| 1 |
/* logs module js */ |
| 2 |
jQuery(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 |
mainwp_init_ui_calendar('.mainwp-module-logs-content-wrap .ui.calendar'); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
$('#logs_delete_records_button').on('click', function () { |
| 13 |
mainwp_set_message_zone('#mainwp-message-zone'); |
| 14 |
|
| 15 |
let str_startdate = jQuery('#log_delete_records_startdate').val(); |
| 16 |
let str_enddate = jQuery('#log_delete_records_enddate').val(); |
| 17 |
let errors = []; |
| 18 |
if (str_startdate == '' || str_enddate == '') { |
| 19 |
errors.push(__('Please select Start Date and End Date.')); |
| 20 |
} |
| 21 |
if (errors.length > 0) { |
| 22 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + errors, 'red'); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
let msg = __('Are you sure you want to delete logs for selected date?'); |
| 27 |
|
| 28 |
mainwp_confirm(msg, function () { |
| 29 |
let data = mainwp_secure_data({ |
| 30 |
action: 'mainwp_module_log_delete_records', |
| 31 |
startdate: jQuery('#log_delete_records_startdate').val(), |
| 32 |
enddate: jQuery('#log_delete_records_enddate').val(), |
| 33 |
}); |
| 34 |
mainwp_set_message_zone('#mainwp-message-zone', __('Running ...'), 'green'); |
| 35 |
jQuery.post(ajaxurl, data, function (response) { |
| 36 |
mainwp_set_message_zone('#mainwp-message-zone'); |
| 37 |
if (response.error) { |
| 38 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + response.error, 'red'); |
| 39 |
} else if (response.result) { |
| 40 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + __('Logs records has been deleted successfully.'), 'green'); |
| 41 |
} else { |
| 42 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + __('Undefined error. Please try again.'), 'red'); |
| 43 |
} |
| 44 |
}, 'json'); |
| 45 |
}); |
| 46 |
|
| 47 |
return false; |
| 48 |
}); |
| 49 |
|
| 50 |
jQuery('#logs_compact_records_button').on('click', function () { |
| 51 |
let year = jQuery('#mainwp_module_log_compact_year').dropdown('get value'); |
| 52 |
mainwp_set_message_zone('#mainwp-message-zone'); |
| 53 |
if (0 == year) { |
| 54 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + __('Please select year.'), 'red'); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
let msg = __('Are you sure you want to compact logs for selected year?'); |
| 59 |
|
| 60 |
mainwp_confirm(msg, function () { |
| 61 |
let data = mainwp_secure_data({ |
| 62 |
action: 'mainwp_module_log_compact_records', |
| 63 |
year: year, |
| 64 |
}); |
| 65 |
mainwp_set_message_zone('#mainwp-message-zone', __('Running ...'), 'green'); |
| 66 |
jQuery.post(ajaxurl, data, function (response) { |
| 67 |
mainwp_set_message_zone('#mainwp-message-zone'); |
| 68 |
if (response.error) { |
| 69 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + response.error, 'red'); |
| 70 |
} else if (response.result) { |
| 71 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + __('Logs records has been compact successfully.'), 'green'); |
| 72 |
} else { |
| 73 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + __('Undefined error. Please try again.'), 'red'); |
| 74 |
} |
| 75 |
}, 'json'); |
| 76 |
}); |
| 77 |
return false; |
| 78 |
}); |
| 79 |
|
| 80 |
}); |
| 81 |
|