jQuery(document).ready(function($){
     console.log('MsgIncomingMenu.js Ready.....');


     $(document).on('click',".delete",function(){
           var id = this.dataset.id;
           var url = SolicitudesAjax.url;
           var result = confirm("Esta seguro?");
           if(!result) return;

           $.ajax({
               type: "POST",
               url: url,
               data:{
                  action  : "peticionincomingajax",
                  nonce : SolicitudesAjax.seguridad,
                  id : id,
                  option : "delete"
               },
               success:function(){
                   location.reload();
                }
           });
     });
	 
     $(document).on('click',".sendmsg",function(){
           var from = this.dataset.from;
		   $("#phone").val(from);
           $("#ModalSendMsg").modal('show');

     });
	 
	 
     //form modal enviando mensaje
     $("#button-modalsendmsg").click(function(){

            var url = SolicitudesAjax.url;
            $("#button-modalsendmsg").prop("disabled",true);
            var msgphone = $('#phone').val();
            var msgtext = $('#text').val();
                        
            if(msgphone != "" && msgtext != "" ){
				
              $.ajax({
                  type: "POST",
                  url: url,
                  data:{
                    action  : "peticionincomingajax",
                    nonce : SolicitudesAjax.seguridad,
                    msgphone : msgphone,
				    msgtext : msgtext,
                    option : "sendmsg"
                  },
                  success:function(){
                    //location.reload();
				    $("#button-modalsendmsg").prop("disabled",false);
            	    $("#ModalSendMsg").modal("hide");
                  },
				  error:function(){
					$("#ModalSendMsg").modal("hide");
            		alert("Error conexion al servidor...  intente mas tarde.");
            		$("#button-modalsendmsg").prop("disabled",false);
					
				  }
              });
				
            }else{
                $("#ModalSendMsg").modal("hide");
                alert("Error: Hay Datos Obligatorios que faltan llenar.");
        	$("#button-modalsendmsg").prop("disabled",false);
            }
        }); //fine form
	 
	 

	 // Eliminar todos los regitros
	 $("#doaction2").on('click',function(){
           var id = this.dataset.id;
           var url = SolicitudesAjax.url;
		   
		   var selector_bottom = $("#bulk-action-selector-bottom").val();
		   
		   if(selector_bottom === "undefined" || selector_bottom==-1){
			   return;
		   }
		   
           var result = confirm("Esta seguro?");
           if(!result) return;

           $.ajax({
               type: "POST",
               url: url,
               data:{
                  action  : "peticionincomingajax",
                  nonce : SolicitudesAjax.seguridad,
                  id : id,
                  option : "deleteall"
               },
               success:function(){
                   location.reload();
                }
           });
     });


});