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
main.js
650 lines
| 1 | sgBackup = {}; |
| 2 | sgBackup.isModalOpen = false; |
| 3 | SG_CURRENT_ACTIVE_AJAX = ''; |
| 4 | SG_NOTICE_EXECUTION_TIMEOUT = 'timeout_error'; |
| 5 | SG_NOTICE_EXECUTION_FREE_TIMEOUT = 'timeout_free_error'; |
| 6 | SG_NOTICE_MIGRATION_ERROR = 'migration_error'; |
| 7 | SG_NOTICE_NOT_WRITABLE_ERROR = 'restore_notwritable_error'; |
| 8 | |
| 9 | jQuery(window).on( |
| 10 | 'load', function () { |
| 11 | if (jQuery('.sg-active-action-id').length == 0) { |
| 12 | sgBackup.showReviewModal(); |
| 13 | } |
| 14 | sgBackup.changeMainUrl(); |
| 15 | } |
| 16 | ); |
| 17 | |
| 18 | jQuery(document).ready( |
| 19 | function () { |
| 20 | jQuery('span[data-toggle=tooltip]').tooltip(); |
| 21 | |
| 22 | sgBackup.init(); |
| 23 | |
| 24 | jQuery('.sg-badge-warning').on( |
| 25 | 'click', function () { |
| 26 | var url = jQuery(this).attr('target-url'); |
| 27 | if (url) { |
| 28 | window.open(url, '_blank'); |
| 29 | } |
| 30 | } |
| 31 | ); |
| 32 | |
| 33 | jQuery("#rateYo").rateYo( |
| 34 | { |
| 35 | rating: 5, |
| 36 | fullStar: true, |
| 37 | spacing: "3px", |
| 38 | starWidth: "16px", |
| 39 | starHeight: "16px", |
| 40 | rating: 4.5, |
| 41 | ratedFill: "#ffffff" |
| 42 | } |
| 43 | ); |
| 44 | |
| 45 | if (typeof SG_AJAX_REQUEST_FREQUENCY === 'undefined') { |
| 46 | SG_AJAX_REQUEST_FREQUENCY = 2000; |
| 47 | } |
| 48 | |
| 49 | sgBackup.hideAjaxSpinner(); |
| 50 | var notice = ""; |
| 51 | jQuery('.notice-dismiss').on( |
| 52 | 'click', function () { |
| 53 | if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_EXECUTION_TIMEOUT) { |
| 54 | notice = SG_NOTICE_EXECUTION_TIMEOUT; |
| 55 | } else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_EXECUTION_FREE_TIMEOUT) { |
| 56 | notice = SG_NOTICE_EXECUTION_TIMEOUT; |
| 57 | } else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_MIGRATION_ERROR) { |
| 58 | notice = SG_NOTICE_MIGRATION_ERROR; |
| 59 | } else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_NOT_WRITABLE_ERROR) { |
| 60 | notice = SG_NOTICE_NOT_WRITABLE_ERROR |
| 61 | } |
| 62 | var sgNoticeClosedHandler = new sgRequestHandler( |
| 63 | 'hideNotice', { |
| 64 | notice: notice, |
| 65 | token: BG_BACKUP_STRINGS.nonce |
| 66 | } |
| 67 | ); |
| 68 | sgNoticeClosedHandler.run(); |
| 69 | } |
| 70 | ); |
| 71 | |
| 72 | //send awake requests only if there is an active action |
| 73 | if (jQuery('.sg-active-action-id').length > 0) { |
| 74 | //setInterval(sgBackup.awake, SG_AJAX_REQUEST_FREQUENCY); |
| 75 | } |
| 76 | } |
| 77 | ); |
| 78 | |
| 79 | sgBackup.awake = function () { |
| 80 | var awakeAjaxHandler = new sgRequestHandler('awake', {token: BG_BACKUP_STRINGS.nonce}); |
| 81 | awakeAjaxHandler.run(); |
| 82 | } |
| 83 | |
| 84 | //SG init |
| 85 | sgBackup.init = function () { |
| 86 | sgBackup.initModals(); |
| 87 | sgBackup.downloadButton(); |
| 88 | sgBackup.navMenu(); |
| 89 | sgBackup.sendUsageDataStatus(); |
| 90 | }; |
| 91 | |
| 92 | sgBackup.sendUsageDataStatus = function () { |
| 93 | var checkbox = jQuery('.backup-send-usage-data-status'); |
| 94 | |
| 95 | if (!checkbox.length) { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | checkbox.bind( |
| 100 | 'switchChange.bootstrapSwitch', function () { |
| 101 | var currentStatus = jQuery(this).is(':checked'); |
| 102 | var action = 'send_usage_status'; |
| 103 | jQuery(this).prop('disabled', true); |
| 104 | var ajaxHandler = new sgRequestHandler(action, {currentStatus: currentStatus, token: BG_BACKUP_STRINGS.nonce}); |
| 105 | ajaxHandler.callback = function (data, error) { |
| 106 | jQuery(this).prop('disabled', false); |
| 107 | } |
| 108 | |
| 109 | ajaxHandler.run(); |
| 110 | } |
| 111 | ); |
| 112 | }; |
| 113 | |
| 114 | sgBackup.navMenu = function () { |
| 115 | var navMenu = jQuery('.sg-backup-sidebar-nav a'); |
| 116 | |
| 117 | if (!navMenu.length) { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | navMenu.unbind('click').bind( |
| 122 | 'click', function (event) { |
| 123 | event.preventDefault(); |
| 124 | sgBackup.init(); |
| 125 | |
| 126 | var currentUrl = jQuery(this).attr('href'); |
| 127 | var openContent = jQuery(this).data('open-content'); |
| 128 | |
| 129 | if (typeof openContent != 'undefined' && openContent == 0) { |
| 130 | window.open(currentUrl); |
| 131 | return true; |
| 132 | } |
| 133 | jQuery('.sg-backup-page-content').addClass('sg-visibility-hidden'); |
| 134 | jQuery('.sg-backup-sidebar-nav li').removeClass('active'); |
| 135 | |
| 136 | var currentKey = jQuery(this).data('page-key'); |
| 137 | var currentPageContent = jQuery('#sg-backup-page-content-' + currentKey); |
| 138 | |
| 139 | if (!currentPageContent.length) { |
| 140 | return false; |
| 141 | } |
| 142 | jQuery(this).parent().addClass('active'); |
| 143 | currentPageContent.removeClass('sg-visibility-hidden'); |
| 144 | } |
| 145 | ); |
| 146 | }; |
| 147 | |
| 148 | sgBackup.downloadButton = function () { |
| 149 | var downloadButtons = jQuery('.sg-bg-download-button'); |
| 150 | |
| 151 | if (!downloadButtons.length) { |
| 152 | return false; |
| 153 | } |
| 154 | var isOPen = false; |
| 155 | jQuery(window).bind( |
| 156 | 'click', function () { |
| 157 | if (isOPen) { |
| 158 | jQuery('.sg-backup-table .dropdown-menu').removeClass('sg-bg-show'); |
| 159 | isOPen = false; |
| 160 | } |
| 161 | } |
| 162 | ); |
| 163 | |
| 164 | downloadButtons.bind( |
| 165 | 'click', function () { |
| 166 | var currentButton = jQuery(this); |
| 167 | |
| 168 | if (!currentButton.length) { |
| 169 | return false; |
| 170 | } |
| 171 | setTimeout( |
| 172 | function () { |
| 173 | currentButton.next().addClass('sg-bg-show'); |
| 174 | isOPen = true; |
| 175 | }, 0 |
| 176 | ); |
| 177 | } |
| 178 | ); |
| 179 | }; |
| 180 | |
| 181 | //SG Modal popup logic |
| 182 | sgBackup.initModals = function () { |
| 183 | |
| 184 | jQuery('[data-toggle="modal"][href], [data-toggle="modal"][data-remote]').off('click').on( |
| 185 | 'click', function (e) { |
| 186 | var param = ''; |
| 187 | if (typeof jQuery(this).attr('data-sgbp-params') !== 'undefined') { |
| 188 | param = jQuery(this).attr('data-sgbp-params'); |
| 189 | } |
| 190 | |
| 191 | e.preventDefault(); |
| 192 | var btn = jQuery(this), |
| 193 | url = btn.attr('data-remote'), |
| 194 | modalName = btn.attr('data-modal-name'), |
| 195 | backupType = btn.attr('sg-data-backup-type'), |
| 196 | modal = jQuery('#sg-modal'); |
| 197 | if (modal.length == 0) { |
| 198 | modal = jQuery( |
| 199 | '' + |
| 200 | '<div class="modal fade" id="sg-modal" tabindex="-1" role="dialog" aria-hidden="true"></div>' + |
| 201 | '' |
| 202 | ); |
| 203 | body.append(modal); |
| 204 | } |
| 205 | sgBackup.showAjaxSpinner('#sg-content-wrapper'); |
| 206 | if (typeof sgBackup.disableUi == 'function') { |
| 207 | sgBackup.disableUi(); |
| 208 | } |
| 209 | |
| 210 | var ajaxHandler = new sgRequestHandler( |
| 211 | url, { |
| 212 | param: param, |
| 213 | backupType: backupType, |
| 214 | token: BG_BACKUP_STRINGS.nonce |
| 215 | } |
| 216 | ); |
| 217 | |
| 218 | if (modalName == 'backup-guard-details') { |
| 219 | modal.modal( |
| 220 | { |
| 221 | backdrop: 'static', |
| 222 | keyboard: false |
| 223 | } |
| 224 | ); |
| 225 | } |
| 226 | |
| 227 | ajaxHandler.type = 'GET'; |
| 228 | ajaxHandler.dataType = 'html'; |
| 229 | ajaxHandler.callback = function (data, error) { |
| 230 | sgBackup.hideAjaxSpinner(); |
| 231 | if (typeof sgBackup.enableUi == 'function') { |
| 232 | sgBackup.enableUi(); |
| 233 | } |
| 234 | if (error === false) { |
| 235 | jQuery('#sg-modal').append(data); |
| 236 | } |
| 237 | modal.on( |
| 238 | 'hide.bs.modal', function () { |
| 239 | if (SG_CURRENT_ACTIVE_AJAX != '') { |
| 240 | if (!confirm(BG_MAIN_STRINGS.confirmCancel)) { |
| 241 | return false; |
| 242 | } |
| 243 | SG_CURRENT_ACTIVE_AJAX.abort(); |
| 244 | SG_CURRENT_ACTIVE_AJAX = ''; |
| 245 | } |
| 246 | } |
| 247 | ); |
| 248 | modal.one( |
| 249 | 'hidden.bs.modal', function () { |
| 250 | modal.html(''); |
| 251 | } |
| 252 | ).modal('show'); |
| 253 | sgBackup.didOpenModal(modalName, param); |
| 254 | |
| 255 | jQuery('[data-dismiss="modal"]').click(function() { |
| 256 | modal.modal('hide'); |
| 257 | }); |
| 258 | }; |
| 259 | |
| 260 | if (modalName == 'ftp-settings' || modalName == 'amazon-settings') { |
| 261 | var storage = 'FTP'; |
| 262 | if (modalName == 'amazon-settings') { |
| 263 | storage = 'AMAZON'; |
| 264 | } |
| 265 | error = false; |
| 266 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: storage}); |
| 267 | isFeatureAvailable.callback = function (response) { |
| 268 | if (typeof response.error !== 'undefined') { |
| 269 | var alert = sgBackup.alertGenerator(response.error, 'alert-warning'); |
| 270 | jQuery('.sg-cloud-container legend').after(alert); |
| 271 | that.bootstrapSwitch('state', false); |
| 272 | sgBackup.hideAjaxSpinner(); |
| 273 | } else { |
| 274 | ajaxHandler.run(); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | isFeatureAvailable.run(); |
| 279 | } else { |
| 280 | ajaxHandler.run(); |
| 281 | } |
| 282 | } |
| 283 | ); |
| 284 | }; |
| 285 | |
| 286 | sgBackup.toggleSftpSettings = function () { |
| 287 | jQuery('#ftpPort').val('22'); |
| 288 | jQuery('#sg-sftp-key-file-block').show(); |
| 289 | jQuery('#sg-browse-key-file-block').hide(); |
| 290 | |
| 291 | if (jQuery('#sg-connect-with-key-file').is(':checked') && connectioType == 'sftp') { |
| 292 | jQuery('#sg-browse-key-file-block').show(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | sgBackup.toggleFtpSettings = function () { |
| 297 | jQuery('#ftpPort').val('21'); |
| 298 | jQuery('#sg-sftp-key-file-block').hide(); |
| 299 | } |
| 300 | |
| 301 | // Show/hide some fields that are needed/not needed for ftp/sftp |
| 302 | sgBackup.toggleNeededFtpFields = function (connectioType) { |
| 303 | if (connectioType == 'sftp') { |
| 304 | sgBackup.toggleSftpSettings(); |
| 305 | |
| 306 | } else if (connectioType == 'ftp') { |
| 307 | sgBackup.toggleFtpSettings(); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | sgBackup.didOpenModal = function (modalName, param) { |
| 312 | if (modalName == 'manual-backup' || modalName == 'manual-restore') { |
| 313 | sgBackup.initManulBackupRadioInputs(); |
| 314 | sgBackup.initManualBackupTooltips(); |
| 315 | jQuery('#fileSystemTreeContainer').jstree( |
| 316 | { |
| 317 | 'core': { |
| 318 | |
| 319 | 'data': { |
| 320 | 'url': function (node) { |
| 321 | return getAjaxUrl(); |
| 322 | }, |
| 323 | 'data': function (node) { |
| 324 | var path = node.id; |
| 325 | return { |
| 326 | action: "backup_guard_getBackupContent", |
| 327 | path: path, |
| 328 | backupName: param, |
| 329 | token: BG_BACKUP_STRINGS.nonce |
| 330 | }; |
| 331 | } |
| 332 | } |
| 333 | }, |
| 334 | "plugins": ["wholerow", "checkbox", "types"], |
| 335 | "checkbox": { |
| 336 | "keep_selected_style": false |
| 337 | }, |
| 338 | "types": { |
| 339 | "file": { |
| 340 | "icon": "bg-file-icon" |
| 341 | }, |
| 342 | "folder": { |
| 343 | "icon": "bg-folder-icon" |
| 344 | }, |
| 345 | "default": { |
| 346 | "icon": "bg-no-icon" |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | ); |
| 351 | } else if (modalName == 'import') { |
| 352 | sgBackup.initImportTooltips(); |
| 353 | jQuery('#modal-import-2').hide(); |
| 354 | jQuery('#modal-import-3').hide(); |
| 355 | jQuery('#switch-modal-import-pages-back').hide(); |
| 356 | jQuery('#uploadSgbpFile').hide(); |
| 357 | if (jQuery('#modal-import-1').length == 0) { |
| 358 | sgBackup.toggleDownloadFromPCPage(); |
| 359 | } |
| 360 | sgBackup.initFileUpload(); |
| 361 | } else if (modalName == 'ftp-settings') { |
| 362 | connectioType = jQuery('#sg-connection-method').val(); |
| 363 | sgBackup.toggleNeededFtpFields(connectioType); |
| 364 | |
| 365 | jQuery('#sg-connection-method').on( |
| 366 | 'change', function () { |
| 367 | connectioType = jQuery(this).val(); |
| 368 | sgBackup.toggleNeededFtpFields(connectioType); |
| 369 | } |
| 370 | ); |
| 371 | |
| 372 | jQuery('#sg-connect-with-key-file').on( |
| 373 | 'click', function () { |
| 374 | if (jQuery(this).is(':checked')) { |
| 375 | jQuery('#sg-browse-key-file-block').show(); |
| 376 | } else { |
| 377 | jQuery('#sg-browse-key-file-block').hide(); |
| 378 | } |
| 379 | } |
| 380 | ) |
| 381 | |
| 382 | sgBackup.initSFTPKeyFileSelection(); |
| 383 | |
| 384 | jQuery('#sg-modal').on( |
| 385 | 'hidden.bs.modal', function () { |
| 386 | if (sgBackup.isFtpConnected != true) { |
| 387 | jQuery('input[data-storage=FTP]').bootstrapSwitch('state', false); |
| 388 | } |
| 389 | } |
| 390 | ) |
| 391 | } else if (modalName == 'amazon-settings') { |
| 392 | jQuery('#sg-modal').on( |
| 393 | 'hidden.bs.modal', function () { |
| 394 | if (sgBackup.isAmazonConnected != true) { |
| 395 | jQuery('input[data-storage=AMAZON]').bootstrapSwitch('state', false); |
| 396 | } |
| 397 | } |
| 398 | ); |
| 399 | jQuery("#bucketType").on( |
| 400 | "change", function () { |
| 401 | jQuery("#bucketType option").each( |
| 402 | function () { |
| 403 | var name = jQuery(this).val(); |
| 404 | jQuery(".form-group-" + name).css("display", "none"); |
| 405 | // Add $(this).val() to your list |
| 406 | } |
| 407 | ); |
| 408 | var selected = jQuery("#bucketType").val(); |
| 409 | jQuery(".form-group-" + selected).css("display", "block"); |
| 410 | } |
| 411 | ) |
| 412 | } else if (modalName == 'manual-review') { |
| 413 | var action = 'setReviewPopupState'; |
| 414 | jQuery('#sgLeaveReview').click( |
| 415 | function () { |
| 416 | var reviewUrl = jQuery(this).attr('data-review-url'); |
| 417 | //Never show again |
| 418 | var reviewState = 2; |
| 419 | var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce}); |
| 420 | ajaxHandler.run(); |
| 421 | window.open(reviewUrl); |
| 422 | } |
| 423 | ); |
| 424 | |
| 425 | jQuery('#sgDontAskAgain').click( |
| 426 | function () { |
| 427 | //Never show again |
| 428 | var reviewState = 2; |
| 429 | var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce}); |
| 430 | ajaxHandler.run(); |
| 431 | } |
| 432 | ); |
| 433 | |
| 434 | jQuery('#sgAskLater').click( |
| 435 | function () { |
| 436 | var reviewState = 0; |
| 437 | var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce}); |
| 438 | ajaxHandler.run(); |
| 439 | } |
| 440 | ); |
| 441 | } else if (modalName == 'create-schedule') { |
| 442 | sgBackup.initScheduleCreation(); |
| 443 | } |
| 444 | }; |
| 445 | |
| 446 | sgBackup.isAnyOpenModal = function () { |
| 447 | return jQuery('#sg-modal').length; |
| 448 | }; |
| 449 | |
| 450 | sgBackup.alertGenerator = function (content, alertClass) { |
| 451 | var sgalert = ''; |
| 452 | sgalert += '<div class="alert alert-dismissible ' + alertClass + '">'; |
| 453 | sgalert += '<button type="button" class="close" data-dismiss="alert">×</button>'; |
| 454 | if (jQuery.isArray(content)) { |
| 455 | jQuery.each( |
| 456 | content, function (index, value) { |
| 457 | sgalert += value + '<br/>'; |
| 458 | } |
| 459 | ); |
| 460 | } else if (content != '') { |
| 461 | sgalert += content.replace('[', '').replace(']', '').replace('"', ''); |
| 462 | } |
| 463 | sgalert += '</div>'; |
| 464 | return sgalert; |
| 465 | }; |
| 466 | |
| 467 | sgBackup.scrollToElement = function (id) { |
| 468 | if (jQuery(id).position()) { |
| 469 | if (jQuery(id).position().top < jQuery(window).scrollTop()) { |
| 470 | //scroll up |
| 471 | jQuery('html,body').animate({scrollTop: jQuery(id).position().top}, 1000); |
| 472 | } else if (jQuery(id).position().top + jQuery(id).height() > jQuery(window).scrollTop() + (window.innerHeight || document.documentElement.clientHeight)) { |
| 473 | //scroll down |
| 474 | jQuery('html,body').animate({scrollTop: jQuery(id).position().top - (window.innerHeight || document.documentElement.clientHeight) + jQuery(id).height() + 15}, 1000); |
| 475 | } |
| 476 | } |
| 477 | }; |
| 478 | |
| 479 | sgBackup.showAjaxSpinner = function (appendToElement) { |
| 480 | if (typeof appendToElement == 'undefined') { |
| 481 | appendToElement = '#sg-wrapper'; |
| 482 | } |
| 483 | jQuery('<div class="sg-spinner"></div>').appendTo(appendToElement); |
| 484 | }; |
| 485 | |
| 486 | sgBackup.hideAjaxSpinner = function () { |
| 487 | jQuery('.sg-spinner').remove(); |
| 488 | }; |
| 489 | sgBackup.showReviewModal = function () { |
| 490 | if (typeof sgShowReview != 'undefined') { |
| 491 | jQuery('#sg-review').trigger("click"); |
| 492 | } |
| 493 | }; |
| 494 | |
| 495 | sgBackup.initTablePagination = function (pageName) { |
| 496 | var callBack = pageName + ''; |
| 497 | jQuery.fn.sgTablePagination = function (opts) { |
| 498 | var jQuerythis = this, |
| 499 | defaults = { |
| 500 | perPage: 7, |
| 501 | showPrevNext: false, |
| 502 | hidePageNumbers: false, |
| 503 | pagerSelector: '.' + pageName + ' .pagination' |
| 504 | }, |
| 505 | settings = jQuery.extend(defaults, opts); |
| 506 | |
| 507 | var listElement = jQuerythis.children('tbody'); |
| 508 | var perPage = settings.perPage; |
| 509 | var children = listElement.children(); |
| 510 | var pager = jQuery('.' + pageName + '.pager'); |
| 511 | |
| 512 | if (typeof settings.childSelector != "undefined") { |
| 513 | children = listElement.find(settings.childSelector); |
| 514 | } |
| 515 | |
| 516 | if (typeof settings.pagerSelector != "undefined") { |
| 517 | pager = jQuery(settings.pagerSelector); |
| 518 | } |
| 519 | |
| 520 | var numItems = children.length; |
| 521 | var numPages = Math.ceil(numItems / perPage); |
| 522 | |
| 523 | pager.data("curr", 0); |
| 524 | |
| 525 | if (settings.showPrevNext) { |
| 526 | jQuery('<li><a href="#" class="prev_link">«</a></li>').appendTo(pager); |
| 527 | } |
| 528 | |
| 529 | var curr = 0; |
| 530 | while (numPages > curr && (settings.hidePageNumbers == false)) { |
| 531 | jQuery('<li><a href="#" class="page_link">' + (curr + 1) + '</a></li>').appendTo(pager); |
| 532 | curr++; |
| 533 | } |
| 534 | |
| 535 | if (curr <= 1) { |
| 536 | jQuery(settings.pagerSelector).parent('div').hide(); |
| 537 | jQuery('.' + pageName + '.page_link').hide(); |
| 538 | } |
| 539 | |
| 540 | if (settings.showPrevNext) { |
| 541 | jQuery('<li><a href="#" class="next_link">»</a></li>').appendTo(pager); |
| 542 | } |
| 543 | |
| 544 | pager.find('.page_link:first').addClass('active'); |
| 545 | pager.find('.prev_link').hide(); |
| 546 | if (numPages <= 1) { |
| 547 | pager.find('.next_link').hide(); |
| 548 | } |
| 549 | pager.children().eq(1).addClass("active"); |
| 550 | |
| 551 | children.hide(); |
| 552 | children.slice(0, perPage).show(); |
| 553 | |
| 554 | pager.find('li .page_link').click( |
| 555 | function () { |
| 556 | var clickedPage = jQuery(this).html().valueOf() - 1; |
| 557 | goTo(clickedPage, perPage); |
| 558 | return false; |
| 559 | } |
| 560 | ); |
| 561 | pager.find('li .prev_link').click( |
| 562 | function () { |
| 563 | previous(); |
| 564 | return false; |
| 565 | } |
| 566 | ); |
| 567 | pager.find('li .next_link').click( |
| 568 | function () { |
| 569 | next(); |
| 570 | return false; |
| 571 | } |
| 572 | ); |
| 573 | |
| 574 | function previous() |
| 575 | { |
| 576 | var goToPage = parseInt(pager.data("curr")) - 1; |
| 577 | goTo(goToPage); |
| 578 | } |
| 579 | |
| 580 | function next() |
| 581 | { |
| 582 | goToPage = parseInt(pager.data("curr")) + 1; |
| 583 | goTo(goToPage); |
| 584 | } |
| 585 | |
| 586 | function goTo(page) |
| 587 | { |
| 588 | var startAt = page * perPage, |
| 589 | endOn = startAt + perPage; |
| 590 | |
| 591 | children.css('display', 'none').slice(startAt, endOn).show(); |
| 592 | |
| 593 | if (page >= 1) { |
| 594 | pager.find('.prev_link').show(); |
| 595 | } else { |
| 596 | pager.find('.prev_link').hide(); |
| 597 | } |
| 598 | |
| 599 | if (page < (numPages - 1)) { |
| 600 | pager.find('.next_link').show(); |
| 601 | } else { |
| 602 | pager.find('.next_link').hide(); |
| 603 | } |
| 604 | |
| 605 | pager.data("curr", page); |
| 606 | pager.children().removeClass("active"); |
| 607 | pager.children().eq(page + 1).addClass("active"); |
| 608 | |
| 609 | } |
| 610 | }; |
| 611 | jQuery('table.paginated.' + pageName).sgTablePagination( |
| 612 | { |
| 613 | pagerSelector: '.' + pageName + ' .pagination', |
| 614 | showPrevNext: true, |
| 615 | hidePageNumbers: false, |
| 616 | perPage: 7 |
| 617 | } |
| 618 | ); |
| 619 | }; |
| 620 | |
| 621 | sgBackup.logout = function () { |
| 622 | var ajaxHandler = new sgRequestHandler('logout', {token: BG_BACKUP_STRINGS.nonce}); |
| 623 | ajaxHandler.callback = function (response) { |
| 624 | location.reload(); |
| 625 | }; |
| 626 | ajaxHandler.run(); |
| 627 | }; |
| 628 | |
| 629 | sgBackup.changeMainUrl = function () { |
| 630 | jQuery('nav#sg-main-sidebar li').click( |
| 631 | function () { |
| 632 | |
| 633 | let attr = jQuery(this).children('a').attr('data-page-key'); |
| 634 | |
| 635 | if (typeof attr !== typeof undefined && attr !== false) { |
| 636 | |
| 637 | let queryParams = new URLSearchParams(window.location.search); |
| 638 | |
| 639 | queryParams.set('page', 'backup_guard_' + attr); |
| 640 | |
| 641 | history.replaceState(null, null, "?" + queryParams.toString()); |
| 642 | } |
| 643 | } |
| 644 | ); |
| 645 | }; |
| 646 | |
| 647 | sgBackup.daysInMonth = function (year, month) { |
| 648 | return new Date(year, month, 0).getDate(); |
| 649 | }; |
| 650 |