| 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(MainWP.I18n.t('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 = MainWP.I18n.t('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', MainWP.I18n.t('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>' + MainWP.I18n.t('Logs records has been deleted successfully.'), 'green'); |
| 41 |
} else { |
| 42 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + MainWP.I18n.t('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>' + MainWP.I18n.t('Please select year.'), 'red'); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
let msg = MainWP.I18n.t('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', MainWP.I18n.t('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>' + MainWP.I18n.t('Logs records has been compact successfully.'), 'green'); |
| 72 |
} else { |
| 73 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + MainWP.I18n.t('Undefined error. Please try again.'), 'red'); |
| 74 |
} |
| 75 |
}, 'json'); |
| 76 |
}); |
| 77 |
return false; |
| 78 |
}); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
jQuery('.mainwp-acts-logs-big-child-db-cleanup-btn').on('click', function () { |
| 83 |
let msg = MainWP.I18n.t('Are you sure you want to clean up activity logs for the selected site?'); |
| 84 |
mainwp_confirm(msg, () => { |
| 85 |
let data = mainwp_secure_data({ |
| 86 |
action: 'mainwp_module_log_clean_up_child_logs', |
| 87 |
siteid: jQuery(this).data('siteid'), |
| 88 |
}); |
| 89 |
|
| 90 |
$(this).attr('disabled', 'disabled'); |
| 91 |
|
| 92 |
let btn = $(this); |
| 93 |
|
| 94 |
mainwp_set_message_zone('#mainwp-message-zone', MainWP.I18n.t('Running ...'), 'green'); |
| 95 |
jQuery.post(ajaxurl, data, function (response) { |
| 96 |
mainwp_set_message_zone('#mainwp-message-zone'); |
| 97 |
if (response?.error) { |
| 98 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + response.error, 'red'); |
| 99 |
} else if (response?.success) { |
| 100 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + MainWP.I18n.t('Log records were cleaned up successfully.'), 'green'); |
| 101 |
$(btn).closest('.item').fadeOut(3000); |
| 102 |
return; |
| 103 |
} else { |
| 104 |
mainwp_set_message_zone('#mainwp-message-zone', '<i class="close icon"></i>' + MainWP.I18n.t('Undefined error. Please try again.'), 'red'); |
| 105 |
} |
| 106 |
$(btn).attr('disabled', false); |
| 107 |
}, 'json'); |
| 108 |
}); |
| 109 |
return false; |
| 110 |
}); |
| 111 |
|
| 112 |
}); |
| 113 |
|