function ml_push_notification_manual_send() { ml_push_notification_manual_send_div(); ?> <?php }
function ml_push_notification_manual_send() { ml_push_notification_manual_send_div(); ?> <script type="text/javascript" > jQuery(document).ready(function($) { $("#ml_push_notification_msg").on("input", function () { limitChars(this, 107, 'ml_notification_chars'); }); jQuery("#ml_push_notification_data_id").change(function() { if($(this).val() === 'custom') { jQuery("#ml_push_notification_post_id_row").show(); } else { jQuery("#ml_push_notification_post_id_row").hide(); } }); jQuery("#ml_push_notification_manual_send_submit").click(function(){ if(validateNotification()) { var checkDuplicate = checkDuplicateNotification(); var cont = true; if(checkDuplicate) { cont = confirm('It seems that you have sent this exact message already, are you sure you wish to send it again?'); } if(cont) { jQuery("#ml_push_notification_manual_send_submit").val("<?php _e('Sending...'); ?> "); jQuery("#ml_push_notification_manual_send_submit").attr("disabled", true); jQuery("#ml_push_notification_manual_send").css("opacity","0.5"); var data = { action: 'ml_push_notification_manual_send', ml_push_notification_msg: jQuery("#ml_push_notification_msg").val(), ml_push_notification_data_id: jQuery("#ml_push_notification_data_id").val(), ml_push_notification_post_id: jQuery("#ml_push_notification_post_id").val(), ml_push_notification_os: jQuery("input[name='ml_push_notification_os']:checked").val() }; $.post(ajaxurl, data, function(response) { //saving the result and reloading the div jQuery("#ml_push_notification_manual_send").html(response).fadeIn(); jQuery("#ml_push_notification_manual_send_submit").val("<?php _e('Send'); ?> "); jQuery("#ml_push_notification_manual_send_submit").attr("disabled", false); jQuery("#ml_push_notification_manual_send").css("opacity","1.0"); loadNotificationHistory(); jQuery("#success-message").show(); setTimeout(function(){ jQuery("#success-message").fadeOut(); }, 2000); }); } return true; } else { return false; } }); }); var limitChars = function(txtMsg, CharLength, indicator){ chars = txtMsg.value.length; document.getElementById(indicator).innerHTML = (CharLength - chars) + " character(s) left."; if (chars > CharLength) { txtMsg.value = txtMsg.value.substring(0, CharLength); //Text in textbox was trimmed, re-set indicator value to 0 document.getElementById(indicator).innerHTML = "0 character(s) left."; } } var checkDuplicateNotification = function() { var data = { action: 'ml_push_notification_check_duplicate', ml_push_notification_msg: jQuery("#ml_push_notification_msg").val(), ml_push_notification_data_id: jQuery("#ml_push_notification_data_id").val(), ml_push_notification_post_id: jQuery("#ml_push_notification_post_id").val(), ml_push_notification_os: jQuery("input[name='ml_push_notification_os']:checked").val() }; var duplicate = false; jQuery.ajax({ url: ajaxurl, data: data, type: 'POST', async: false, success: function(response) { if(jQuery.trim(response).length > 0) { duplicate = true; } } }); return duplicate; }; var validateNotification = function() { var errors = []; var message = jQuery.trim(jQuery("#ml_push_notification_msg").val()); if(message.length === 0) { errors.push('Message cannot be blank'); } var attach = jQuery("#ml_push_notification_data_id").val(); if(attach === 'custom') { var customPostID = jQuery.trim(jQuery("#ml_push_notification_post_id").val()); if(customPostID.length === 0) { errors.push('Custom ID cannot be blank'); } else if(!jQuery.isNumeric(customPostID)) { errors.push('Custom ID must be a number'); } } if(errors.length > 0) { jQuery("#error-message").html(errors.join("<br/>")).show(); return false; } else { jQuery("#error-message").hide(); return true; } }; </script> <?php }