bootstrap-switch.min.js
3 years ago
bootstrap.bundle.min.js
3 years ago
bootstrap.bundle.min.js.map
3 years ago
chart.umd.min.js
3 years ago
jquery.fileupload.js
3 years ago
jquery.iframe-transport.js
3 years ago
jquery.rateyo.js
3 years ago
jquery.validate.min.js
3 years ago
jstree.checkbox.js
3 years ago
jstree.min.js
3 years ago
jstree.types.js
3 years ago
jstree.wholerow.js
3 years ago
less.min.js
3 years ago
main.js
3 years ago
popup.js
3 years ago
sgbackup.js
3 years ago
sgcloud.js
3 years ago
sglogin.js
3 years ago
sgrequesthandler.js
3 years ago
sgrequesthandler.wordpress.js
3 years ago
sgschedule.js
3 years ago
sgsettings.js
3 years ago
sgschedule.js
267 lines
| 1 | BG_SCHEDULE_INTERVAL_HOURLY = 0; |
| 2 | BG_SCHEDULE_INTERVAL_DAILY = 1; |
| 3 | BG_SCHEDULE_INTERVAL_WEEKLY = 2; |
| 4 | BG_SCHEDULE_INTERVAL_MONTHLY = 3; |
| 5 | BG_SCHEDULE_INTERVAL_YEARLY = 4; |
| 6 | |
| 7 | jQuery(document).ready( |
| 8 | function () { |
| 9 | sgBackup.initTablePagination('sg-schedule'); |
| 10 | sgBackup.initScheduleCreation(); |
| 11 | } |
| 12 | ); |
| 13 | |
| 14 | sgBackup.initScheduleCreation = function () { |
| 15 | sgBackup.initScheduleSwitchButtons(); |
| 16 | sgBackup.initManulBackupRadioInputs(); |
| 17 | sgBackup.initManualBackupTooltips(); |
| 18 | sgBackup.toggleDaySelection(); |
| 19 | sgBackup.initIntervalSelection(); |
| 20 | } |
| 21 | |
| 22 | sgBackup.removeSchedule = function (id) { |
| 23 | var ajaxHandler = new sgRequestHandler('schedule', {remove: true, id: id, token: BG_BACKUP_STRINGS.nonce}); |
| 24 | |
| 25 | if (!confirm(BG_SCHEDULE_STRINGS.confirm)) { |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | ajaxHandler.callback = function (response) { |
| 30 | jQuery('.alert').remove(); |
| 31 | |
| 32 | if (typeof response.success !== 'undefined') { |
| 33 | location.reload(); |
| 34 | } else { |
| 35 | //if error |
| 36 | var alert = sgBackup.alertGenerator(BG_SCHEDULE_STRINGS.deletionError, 'alert-danger'); |
| 37 | jQuery('.sg-schedule-container legend').after(alert); |
| 38 | } |
| 39 | |
| 40 | sgBackup.scrollToElement('.alert'); |
| 41 | }; |
| 42 | ajaxHandler.run(); |
| 43 | } |
| 44 | |
| 45 | sgBackup.initIntervalSelection = function () { |
| 46 | if (jQuery('#sg-schedule-interval').val() == BG_SCHEDULE_INTERVAL_WEEKLY) { |
| 47 | jQuery('#sg-schedule-day-of-week-select').show(); |
| 48 | } else if (jQuery('#sg-schedule-interval').val() == BG_SCHEDULE_INTERVAL_MONTHLY) { |
| 49 | jQuery('#sg-schedule-day-of-month-select').show(); |
| 50 | } else if (jQuery('#sg-schedule-interval').val() == BG_SCHEDULE_INTERVAL_HOURLY) { |
| 51 | jQuery('#sg-schedule-timezone').hide(); |
| 52 | } |
| 53 | |
| 54 | jQuery('#sg-schedule-interval').on( |
| 55 | 'change', function () { |
| 56 | jQuery('#sg-schedule-timezone').show(); |
| 57 | if (jQuery(this).val() == BG_SCHEDULE_INTERVAL_WEEKLY) { |
| 58 | jQuery('#sg-schedule-month-of-year-select').hide(); |
| 59 | jQuery('#sg-schedule-day-of-month-select').hide(); |
| 60 | jQuery('#sg-schedule-day-of-week-select').show(); |
| 61 | } else if (jQuery(this).val() == BG_SCHEDULE_INTERVAL_MONTHLY) { |
| 62 | jQuery('#sg-schedule-month-of-year-select').hide(); |
| 63 | jQuery('#sg-schedule-day-of-week-select').hide(); |
| 64 | jQuery('#sg-schedule-day-of-month-select').show(); |
| 65 | sgBackup.updateDaysOfMonth(); |
| 66 | } else if (jQuery('#sg-schedule-interval').val() == BG_SCHEDULE_INTERVAL_HOURLY) { |
| 67 | jQuery('#sg-schedule-timezone').hide(); |
| 68 | } else if (jQuery('#sg-schedule-interval').val() == BG_SCHEDULE_INTERVAL_DAILY) { |
| 69 | sgBackup.toggleDaySelection(); |
| 70 | } else { |
| 71 | jQuery('#sg-schedule-month-of-year-select').show(); |
| 72 | jQuery('#sg-schedule-day-of-week-select').hide(); |
| 73 | jQuery('#sg-schedule-day-of-month-select').show(); |
| 74 | sgBackup.updateDaysOfMonth(); |
| 75 | } |
| 76 | } |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | sgBackup.toggleDaySelection = function () { |
| 81 | jQuery('#sg-schedule-day-of-week-select').hide(); |
| 82 | jQuery('#sg-schedule-day-of-month-select').hide(); |
| 83 | jQuery('#sg-schedule-month-of-year-select').hide(); |
| 84 | } |
| 85 | |
| 86 | sgBackup.updateDaysOfMonth = function () { |
| 87 | let year = new Date().getFullYear(); |
| 88 | let interval = jQuery('#sg-schedule-interval').val(); |
| 89 | let month = ''; |
| 90 | |
| 91 | if (interval == BG_SCHEDULE_INTERVAL_MONTHLY) { |
| 92 | month = new Date().getMonth() + 1; |
| 93 | } else { |
| 94 | month = parseInt(jQuery('#sg-schedule-month-of-year').val()); |
| 95 | } |
| 96 | |
| 97 | let days = sgBackup.daysInMonth(year, month); |
| 98 | |
| 99 | jQuery("#sg-schedule-day-of-month option").show(); |
| 100 | |
| 101 | jQuery("#sg-schedule-day-of-month option").each( |
| 102 | function () { |
| 103 | if (jQuery(this).val() > days) { |
| 104 | jQuery(this).hide(); |
| 105 | } |
| 106 | } |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | sgBackup.prependErrorMsg = function (alert) { |
| 111 | if (typeof jQuery('#sg-schedule-id').val() === 'undefined') { |
| 112 | jQuery('.sg-schedule-container legend').after(alert); |
| 113 | } else { |
| 114 | jQuery('#sg-modal .modal-header').prepend(alert); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | //SGSchedule AJAX callback |
| 119 | sgBackup.schedule = function () { |
| 120 | var error = []; |
| 121 | var scheduleForm = jQuery('form[data-type=schedule]'); |
| 122 | |
| 123 | //Validation |
| 124 | jQuery('.alert').remove(); |
| 125 | if (jQuery('input[type=radio][name=backupType]:checked').val() == 2) { |
| 126 | if (jQuery('.sg-custom-option:checked').length <= 0) { |
| 127 | error.push(BG_SCHEDULE_STRINGS.invalidBackupOption); |
| 128 | } |
| 129 | //Check if any file is selected |
| 130 | if (jQuery('input[type=checkbox][name=backupFiles]:checked').length > 0) { |
| 131 | if (jQuery('.sg-custom-backup-files input:checkbox:checked').length <= 0) { |
| 132 | error.push(BG_SCHEDULE_STRINGS.invalidDirectorySelected); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | //Check if any cloud is selected |
| 137 | if (jQuery('input[type=checkbox][name=backupCloud]:checked').length > 0) { |
| 138 | if (jQuery('.sg-custom-backup-cloud input:checkbox:checked').length <= 0) { |
| 139 | error.push(BG_SCHEDULE_STRINGS.invalidCloud); |
| 140 | } |
| 141 | } |
| 142 | //If any error show it and abort ajax |
| 143 | if (error.length) { |
| 144 | var alert = sgBackup.alertGenerator(error, 'alert-danger'); |
| 145 | sgBackup.prependErrorMsg(alert); |
| 146 | sgBackup.scrollToElement('.alert'); |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | //Before sending |
| 151 | jQuery('#sg-save-schedule').attr('disabled', 'disabled'); |
| 152 | jQuery('#sg-save-schedule').html(BG_SCHEDULE_STRINGS.savingInProgress); |
| 153 | |
| 154 | //On Success |
| 155 | var ajaxHandler = new sgRequestHandler('schedule', scheduleForm.serialize() + '&token=' + BG_BACKUP_STRINGS.nonce); |
| 156 | ajaxHandler.dataIsObject = false; |
| 157 | ajaxHandler.callback = function (response) { |
| 158 | jQuery('.alert').remove(); |
| 159 | if (typeof response.success !== 'undefined') { |
| 160 | var alert = sgBackup.alertGenerator(BG_SCHEDULE_STRINGS.successMessage, 'alert-success'); |
| 161 | sgBackup.prependErrorMsg(alert); |
| 162 | location.reload(); |
| 163 | } else { |
| 164 | //if error |
| 165 | var alert = sgBackup.alertGenerator(response, 'alert-danger'); |
| 166 | sgBackup.prependErrorMsg(alert); |
| 167 | } |
| 168 | |
| 169 | //Always |
| 170 | jQuery('#sg-save-schedule').removeAttr('disabled', 'disabled'); |
| 171 | jQuery('#sg-save-schedule').html(BG_SCHEDULE_STRINGS.saveButtonText); |
| 172 | sgBackup.scrollToElement('.alert'); |
| 173 | }; |
| 174 | ajaxHandler.run(); |
| 175 | }; |
| 176 | |
| 177 | sgBackup.initScheduleSwitchButtons = function () { |
| 178 | jQuery('.sg-switch').bootstrapSwitch(); |
| 179 | if (jQuery('#sg-backup-page-content-schedule .sg-switch').is(':checked')) { |
| 180 | jQuery('#sg-backup-page-content-schedule .sg-schedule-settings').show(); |
| 181 | } |
| 182 | jQuery('.sg-switch').on( |
| 183 | 'switchChange.bootstrapSwitch', function (event, state) { |
| 184 | var url = jQuery(this).attr('data-remote'); |
| 185 | if (state) { |
| 186 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: "SCHEDULE"}); |
| 187 | isFeatureAvailable.callback = function (response) { |
| 188 | jQuery('.alert').remove(); |
| 189 | if (typeof response.success !== 'undefined') { |
| 190 | //Show or Hide settings panel |
| 191 | jQuery('.sg-schedule-settings').fadeIn(); |
| 192 | } else { |
| 193 | var alert = sgBackup.alertGenerator(response.error, 'alert-warning'); |
| 194 | jQuery('.sg-schedule-container legend').after(alert); |
| 195 | jQuery('.sg-switch').bootstrapSwitch('state', false); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | isFeatureAvailable.run(); |
| 200 | } else { |
| 201 | var ajaxHandler = new sgRequestHandler('schedule', {remove: true, token: BG_BACKUP_STRINGS.nonce}); |
| 202 | ajaxHandler.run(); |
| 203 | jQuery('.sg-schedule-settings').fadeOut(); |
| 204 | } |
| 205 | } |
| 206 | ); |
| 207 | }; |
| 208 | |
| 209 | sgBackup.initManulBackupRadioInputs = function () { |
| 210 | jQuery('input[type=radio][name=backupType]').off('change').on( |
| 211 | 'change', function () { |
| 212 | jQuery('.sg-custom-backup').fadeToggle(); |
| 213 | jQuery('.sg-custom-backup').children().find('input[class^=sg-custom]').removeAttr('checked'); |
| 214 | jQuery('.sg-custom-backup-files').hide(); |
| 215 | } |
| 216 | ); |
| 217 | jQuery('input[type=checkbox][name=backupFiles], input[type=checkbox][name=backupCloud], input[type=checkbox][name=backupDatabase]').off('change').on( |
| 218 | 'change', function () { |
| 219 | var sgCheckBoxWrapper = jQuery(this).closest('.checkbox').find('.sg-checkbox'); |
| 220 | sgCheckBoxWrapper.fadeToggle(); |
| 221 | if (jQuery(this).attr('name') == 'backupFiles') { |
| 222 | sgCheckBoxWrapper.find('input[type=checkbox]').attr('checked', 'checked'); |
| 223 | } |
| 224 | } |
| 225 | ); |
| 226 | jQuery('input[type=radio][name=backupDBType]').off('change').on( |
| 227 | 'change', function () { |
| 228 | var sgCheckBoxWrapper = jQuery(this).closest('.checkbox').find('.sg-custom-backup-tables'); |
| 229 | if (jQuery('input[type=radio][name=backupDBType]:checked').val() == '2') { |
| 230 | sgCheckBoxWrapper.find('input[type=checkbox]').not("[disabled]").prop('checked', true) |
| 231 | sgCheckBoxWrapper.fadeIn(); |
| 232 | } else { |
| 233 | sgCheckBoxWrapper.fadeOut(); |
| 234 | sgCheckBoxWrapper.find('input[type=checkbox][current="true"]').not("[disabled]").prop('checked', true) |
| 235 | sgCheckBoxWrapper.find('input[type=checkbox][current="false"]').prop('checked', false) |
| 236 | } |
| 237 | } |
| 238 | ) |
| 239 | } |
| 240 | |
| 241 | sgBackup.initManualBackupTooltips = function () { |
| 242 | jQuery('[for=cloud-ftp]').tooltip({ |
| 243 | container: jQuery('[for=cloud-ftp]').parent() |
| 244 | }); |
| 245 | jQuery('[for=cloud-dropbox]').tooltip({ |
| 246 | container: jQuery('[for=cloud-dropbox]').parent() |
| 247 | }); |
| 248 | jQuery('[for=cloud-gdrive]').tooltip({ |
| 249 | container: jQuery('[for=cloud-gdrive]').parent() |
| 250 | }); |
| 251 | jQuery('[for=cloud-one-drive]').tooltip({ |
| 252 | container: jQuery('[for=cloud-one-drive]').parent() |
| 253 | }); |
| 254 | jQuery('[for=cloud-p-cloud]').tooltip({ |
| 255 | container: jQuery('[for=cloud-p-cloud]').parent() |
| 256 | }); |
| 257 | jQuery('[for=cloud-box]').tooltip({ |
| 258 | container: jQuery('[for=cloud-box]').parent() |
| 259 | }); |
| 260 | jQuery('[for=cloud-amazon]').tooltip({ |
| 261 | container: jQuery('[for=cloud-amazon]').parent() |
| 262 | }); |
| 263 | jQuery('[for=cloud-backup-guard]').tooltip({ |
| 264 | container: jQuery('[for=cloud-backup-guard]').parent() |
| 265 | }); |
| 266 | } |
| 267 |