| 1 |
/* logs module js */ |
| 2 |
jQuery(document).ready(function ($) { |
| 3 |
|
| 4 |
if (jQuery('.mainwp-module-logs-content-wrap .ui.calendar').length > 0) { |
| 5 |
if (mainwpParams.use_wp_datepicker == 1) { |
| 6 |
jQuery('.mainwp-module-logs-content-wrap .ui.calendar input[type=text]').datepicker({ dateFormat: "yy-mm-dd" }); |
| 7 |
} else { |
| 8 |
jQuery('.mainwp-module-logs-content-wrap .ui.calendar').calendar({ |
| 9 |
type: 'date', |
| 10 |
monthFirst: false, |
| 11 |
today: true, |
| 12 |
touchReadonly: false, |
| 13 |
formatter: { |
| 14 |
date: function (date) { |
| 15 |
if (!date) return ''; |
| 16 |
var day = date.getDate(); |
| 17 |
var month = date.getMonth() + 1; |
| 18 |
var year = date.getFullYear(); |
| 19 |
|
| 20 |
if (month < 10) { |
| 21 |
month = '0' + month; |
| 22 |
} |
| 23 |
if (day < 10) { |
| 24 |
day = '0' + day; |
| 25 |
} |
| 26 |
return year + '-' + month + '-' + day; |
| 27 |
} |
| 28 |
} |
| 29 |
}); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
$('#logs_delete_records_button').on('click', function () { |
| 34 |
jQuery('#mainwp-message-zone').html("").hide(); |
| 35 |
jQuery('#mainwp-message-zone').removeClass('red yellow green'); |
| 36 |
|
| 37 |
var str_startdate = jQuery('#log_delete_records_startdate').val(); |
| 38 |
var str_enddate = jQuery('#log_delete_records_enddate').val(); |
| 39 |
var errors = []; |
| 40 |
if (str_startdate == '' || str_enddate == '') { |
| 41 |
errors.push(__('Please select Start Date and End Date.')); |
| 42 |
} |
| 43 |
if (errors.length > 0) { |
| 44 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + errors).addClass('red').show(); |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
var msg = __('Are you sure you want to delete logs for selected date?'); |
| 49 |
|
| 50 |
mainwp_confirm(msg, function () { |
| 51 |
var data = mainwp_secure_data({ |
| 52 |
action: 'mainwp_module_log_delete_records', |
| 53 |
startdate: jQuery('#log_delete_records_startdate').val(), |
| 54 |
enddate: jQuery('#log_delete_records_enddate').val(), |
| 55 |
}); |
| 56 |
jQuery('#mainwp-message-zone').html(__('Running ...')).addClass('green').show(); |
| 57 |
jQuery.post(ajaxurl, data, function (response) { |
| 58 |
jQuery('#mainwp-message-zone').removeClass('red yellow green'); |
| 59 |
if (response.error) { |
| 60 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + response.error).addClass('red'); |
| 61 |
} else if (response.result) { |
| 62 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + __('Logs records has been deleted successfully.')).addClass('green'); |
| 63 |
} else { |
| 64 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + __('Undefined error. Please try again.')).addClass('red'); |
| 65 |
} |
| 66 |
}, 'json'); |
| 67 |
}); |
| 68 |
|
| 69 |
return false; |
| 70 |
}); |
| 71 |
|
| 72 |
jQuery('#logs_compact_records_button').on('click', function () { |
| 73 |
var year = jQuery('#mainwp_module_log_compact_year').dropdown('get value'); |
| 74 |
jQuery('#mainwp-message-zone').html("").hide(); |
| 75 |
jQuery('#mainwp-message-zone').removeClass('red yellow green'); |
| 76 |
|
| 77 |
if (0 == year) { |
| 78 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + __('Please select year.')).addClass('red').show(); |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
var msg = __('Are you sure you want to compact logs for selected year?'); |
| 83 |
|
| 84 |
mainwp_confirm(msg, function () { |
| 85 |
var data = mainwp_secure_data({ |
| 86 |
action: 'mainwp_module_log_compact_records', |
| 87 |
year: year, |
| 88 |
}); |
| 89 |
|
| 90 |
jQuery('#mainwp-message-zone').html(__('Running ...')).addClass('green').show(); |
| 91 |
jQuery.post(ajaxurl, data, function (response) { |
| 92 |
jQuery('#mainwp-message-zone').removeClass('red yellow green'); |
| 93 |
if (response.error) { |
| 94 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + response.error).addClass('red'); |
| 95 |
} else if (response.result) { |
| 96 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + __('Logs records has been compact successfully.')).addClass('green'); |
| 97 |
} else { |
| 98 |
jQuery('#mainwp-message-zone').html('<i class="close icon"></i>' + __('Undefined error. Please try again.')).addClass('red'); |
| 99 |
} |
| 100 |
}, 'json'); |
| 101 |
}); |
| 102 |
return false; |
| 103 |
}); |
| 104 |
|
| 105 |
}); |
| 106 |
|