Chart.bundle.min.js
5 years ago
bootstrap-switch.min.js
5 years ago
bootstrap.min.js
5 years ago
deactivationSurvey.js
5 years ago
jquery-ui.js
5 years ago
jquery.fileupload.js
5 years ago
jquery.iframe-transport.js
5 years ago
jquery.rateyo.js
5 years ago
jstree.checkbox.js
5 years ago
jstree.min.js
5 years ago
jstree.types.js
5 years ago
jstree.wholerow.js
5 years ago
less.min.js
5 years ago
main.js
5 years ago
popup.js
5 years ago
sgNoticeDismiss.js
5 years ago
sgbackup.js
5 years ago
sgcloud.js
5 years ago
sgdiscount.js
5 years ago
sglicense.js
5 years ago
sglogin.js
5 years ago
sgrequesthandler.js
5 years ago
sgrequesthandler.wordpress.js
5 years ago
sgschedule.js
5 years ago
sgsettings.js
5 years ago
main.js
500 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).load(function() { |
| 10 | if (jQuery('.sg-active-action-id').length == 0) { |
| 11 | sgBackup.showReviewModal(); |
| 12 | } |
| 13 | }); |
| 14 | |
| 15 | jQuery(document).ready( function() { |
| 16 | jQuery('span[data-toggle=tooltip]').tooltip(); |
| 17 | |
| 18 | sgBackup.init(); |
| 19 | |
| 20 | jQuery('.sg-badge-warning').on('click', function () { |
| 21 | var url = jQuery(this).attr('target-url'); |
| 22 | if (url) { |
| 23 | window.open(url, '_blank'); |
| 24 | } |
| 25 | }); |
| 26 | |
| 27 | jQuery("#rateYo").rateYo({ |
| 28 | rating: 5, |
| 29 | fullStar: true, |
| 30 | spacing: "3px", |
| 31 | starWidth: "16px", |
| 32 | starHeight: "16px", |
| 33 | rating: 4.5, |
| 34 | ratedFill: "#ffffff" |
| 35 | }); |
| 36 | |
| 37 | if (typeof SG_AJAX_REQUEST_FREQUENCY === 'undefined'){ |
| 38 | SG_AJAX_REQUEST_FREQUENCY = 2000; |
| 39 | } |
| 40 | |
| 41 | sgBackup.hideAjaxSpinner(); |
| 42 | var notice = ""; |
| 43 | jQuery('.notice-dismiss').on('click', function() { |
| 44 | if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_EXECUTION_TIMEOUT) { |
| 45 | notice = SG_NOTICE_EXECUTION_TIMEOUT; |
| 46 | } |
| 47 | else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_EXECUTION_FREE_TIMEOUT) { |
| 48 | notice = SG_NOTICE_EXECUTION_TIMEOUT; |
| 49 | } |
| 50 | else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_MIGRATION_ERROR) { |
| 51 | notice = SG_NOTICE_MIGRATION_ERROR; |
| 52 | } |
| 53 | else if (jQuery(this).parent().attr('data-notice-id') == SG_NOTICE_NOT_WRITABLE_ERROR) { |
| 54 | notice = SG_NOTICE_NOT_WRITABLE_ERROR |
| 55 | } |
| 56 | var sgNoticeClosedHandler = new sgRequestHandler('hideNotice', {notice: notice, token: BG_BACKUP_STRINGS.nonce}); |
| 57 | sgNoticeClosedHandler.run(); |
| 58 | }); |
| 59 | |
| 60 | //send awake requests only if there is an active action |
| 61 | if (jQuery('.sg-active-action-id').length>0) { |
| 62 | setInterval(sgBackup.awake, SG_AJAX_REQUEST_FREQUENCY); |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | sgBackup.awake = function(){ |
| 67 | var awakeAjaxHandler = new sgRequestHandler('awake', {token: BG_BACKUP_STRINGS.nonce}); |
| 68 | awakeAjaxHandler.run(); |
| 69 | } |
| 70 | |
| 71 | //SG init |
| 72 | sgBackup.init = function(){ |
| 73 | sgBackup.initModals(); |
| 74 | sgBackup.downloadButton(); |
| 75 | }; |
| 76 | |
| 77 | sgBackup.downloadButton = function() |
| 78 | { |
| 79 | var downloadButtons = jQuery('.sg-bg-download-button'); |
| 80 | |
| 81 | if (!downloadButtons.length) { |
| 82 | return false; |
| 83 | } |
| 84 | var isOPen = false; |
| 85 | jQuery(window).bind('click', function () { |
| 86 | if (isOPen) { |
| 87 | jQuery('.sg-backup-table .dropdown-menu').removeClass('sg-bg-show'); |
| 88 | isOPen = false; |
| 89 | } |
| 90 | }); |
| 91 | |
| 92 | downloadButtons.bind('click', function () { |
| 93 | var currentButton = jQuery(this); |
| 94 | |
| 95 | if (!currentButton.length) { |
| 96 | return false; |
| 97 | } |
| 98 | setTimeout(function () { |
| 99 | currentButton.next().addClass('sg-bg-show'); |
| 100 | isOPen = true; |
| 101 | }, 0); |
| 102 | }); |
| 103 | }; |
| 104 | |
| 105 | //SG Modal popup logic |
| 106 | sgBackup.initModals = function(){ |
| 107 | |
| 108 | jQuery('[data-toggle="modal"][href], [data-toggle="modal"][data-remote]').off('click').on('click', function(e) { |
| 109 | var param = ''; |
| 110 | if (typeof jQuery(this).attr('data-sgbp-params') !== 'undefined'){ |
| 111 | param = jQuery(this).attr('data-sgbp-params'); |
| 112 | } |
| 113 | |
| 114 | e.preventDefault(); |
| 115 | var btn = jQuery(this), |
| 116 | url = btn.attr('data-remote'), |
| 117 | modalName = btn.attr('data-modal-name'), |
| 118 | backupType = btn.attr('sg-data-backup-type'), |
| 119 | modal = jQuery('#sg-modal'); |
| 120 | if( modal.length == 0 ) { |
| 121 | modal = jQuery('' + |
| 122 | '<div class="modal fade" id="sg-modal" tabindex="-1" role="dialog" aria-hidden="true"></div>' + |
| 123 | ''); |
| 124 | body.append(modal); |
| 125 | } |
| 126 | sgBackup.showAjaxSpinner('#sg-content-wrapper'); |
| 127 | if (typeof sgBackup.disableUi == 'function') { |
| 128 | sgBackup.disableUi(); |
| 129 | } |
| 130 | |
| 131 | var ajaxHandler = new sgRequestHandler(url, { |
| 132 | param: param, |
| 133 | backupType: backupType, |
| 134 | token: BG_BACKUP_STRINGS.nonce |
| 135 | }); |
| 136 | |
| 137 | ajaxHandler.type = 'GET'; |
| 138 | ajaxHandler.dataType = 'html'; |
| 139 | ajaxHandler.callback = function(data, error) { |
| 140 | sgBackup.hideAjaxSpinner(); |
| 141 | if (typeof sgBackup.enableUi == 'function') { |
| 142 | sgBackup.enableUi(); |
| 143 | } |
| 144 | if (error===false) { |
| 145 | jQuery('#sg-modal').append(data); |
| 146 | } |
| 147 | modal.on('hide.bs.modal', function() { |
| 148 | if(SG_CURRENT_ACTIVE_AJAX != '') { |
| 149 | if (!confirm(BG_MAIN_STRINGS.confirmCancel)) { |
| 150 | return false; |
| 151 | } |
| 152 | SG_CURRENT_ACTIVE_AJAX.abort(); |
| 153 | SG_CURRENT_ACTIVE_AJAX = ''; |
| 154 | } |
| 155 | }); |
| 156 | modal.one('hidden.bs.modal', function() { |
| 157 | modal.html(''); |
| 158 | }).modal('show'); |
| 159 | sgBackup.didOpenModal(modalName, param); |
| 160 | }; |
| 161 | |
| 162 | if (modalName == 'ftp-settings' || modalName == 'amazon-settings') { |
| 163 | var storage = 'FTP'; |
| 164 | if (modalName == 'amazon-settings') { |
| 165 | storage = 'AMAZON'; |
| 166 | } |
| 167 | error = false; |
| 168 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: storage}); |
| 169 | isFeatureAvailable.callback = function(response) { |
| 170 | if (typeof response.error !== 'undefined') { |
| 171 | var alert = sgBackup.alertGenerator(response.error, 'alert-warning'); |
| 172 | jQuery('.sg-cloud-container legend').after(alert); |
| 173 | that.bootstrapSwitch('state', false); |
| 174 | sgBackup.hideAjaxSpinner(); |
| 175 | } |
| 176 | else { |
| 177 | ajaxHandler.run(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | isFeatureAvailable.run(); |
| 182 | } |
| 183 | else { |
| 184 | ajaxHandler.run(); |
| 185 | } |
| 186 | }); |
| 187 | }; |
| 188 | |
| 189 | sgBackup.toggleSftpSettings = function() { |
| 190 | jQuery('#ftpPort').val('22'); |
| 191 | jQuery('#sg-sftp-key-file-block').show(); |
| 192 | jQuery('#sg-browse-key-file-block').hide(); |
| 193 | |
| 194 | if (jQuery('#sg-connect-with-key-file').is(':checked') && connectioType=='sftp') { |
| 195 | jQuery('#sg-browse-key-file-block').show(); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | sgBackup.toggleFtpSettings = function() { |
| 200 | jQuery('#ftpPort').val('21'); |
| 201 | jQuery('#sg-sftp-key-file-block').hide(); |
| 202 | } |
| 203 | |
| 204 | // Show/hide some fields that are needed/not needed for ftp/sftp |
| 205 | sgBackup.toggleNeededFtpFields = function(connectioType) { |
| 206 | if(connectioType == 'sftp') { |
| 207 | sgBackup.toggleSftpSettings(); |
| 208 | |
| 209 | } |
| 210 | else if(connectioType == 'ftp') { |
| 211 | sgBackup.toggleFtpSettings(); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | sgBackup.didOpenModal = function(modalName, param){ |
| 216 | if(modalName == 'manual-backup' || modalName == 'manual-restore'){ |
| 217 | sgBackup.initManulBackupRadioInputs(); |
| 218 | sgBackup.initManualBackupTooltips(); |
| 219 | jQuery('#fileSystemTreeContainer').jstree({ 'core' : { |
| 220 | |
| 221 | 'data' : { |
| 222 | 'url' : function (node) { |
| 223 | return getAjaxUrl(); |
| 224 | }, |
| 225 | 'data' : function (node) { |
| 226 | var path = node.id; |
| 227 | return { action:"backup_guard_getBackupContent", path:path, backupName:param, token: BG_BACKUP_STRINGS.nonce }; |
| 228 | } |
| 229 | } |
| 230 | }, |
| 231 | "plugins" : ["wholerow", "checkbox", "types"], |
| 232 | "checkbox" : { |
| 233 | "keep_selected_style" : false |
| 234 | }, |
| 235 | "types": { |
| 236 | "file": { |
| 237 | "icon": "bg-file-icon" |
| 238 | }, |
| 239 | "folder": { |
| 240 | "icon": "bg-folder-icon" |
| 241 | }, |
| 242 | "default":{ |
| 243 | "icon": "bg-no-icon" |
| 244 | } |
| 245 | } |
| 246 | }); |
| 247 | } |
| 248 | else if(modalName == 'import'){ |
| 249 | sgBackup.initImportTooltips(); |
| 250 | jQuery('#modal-import-2').hide(); |
| 251 | jQuery('#modal-import-3').hide(); |
| 252 | jQuery('#switch-modal-import-pages-back').hide(); |
| 253 | jQuery('#uploadSgbpFile').hide(); |
| 254 | if(jQuery('#modal-import-1').length == 0) { |
| 255 | sgBackup.toggleDownloadFromPCPage(); |
| 256 | } |
| 257 | sgBackup.initFileUpload(); |
| 258 | } |
| 259 | else if(modalName == 'ftp-settings'){ |
| 260 | connectioType = jQuery('#sg-connection-method').val(); |
| 261 | sgBackup.toggleNeededFtpFields(connectioType); |
| 262 | |
| 263 | jQuery('#sg-connection-method').on('change', function(){ |
| 264 | connectioType = jQuery(this).val(); |
| 265 | sgBackup.toggleNeededFtpFields(connectioType); |
| 266 | }); |
| 267 | |
| 268 | jQuery('#sg-connect-with-key-file').on('click', function(){ |
| 269 | if(jQuery(this).is(':checked')) { |
| 270 | jQuery('#sg-browse-key-file-block').show(); |
| 271 | } |
| 272 | else { |
| 273 | jQuery('#sg-browse-key-file-block').hide(); |
| 274 | } |
| 275 | }) |
| 276 | |
| 277 | sgBackup.initSFTPKeyFileSelection(); |
| 278 | |
| 279 | jQuery('#sg-modal').on('hidden.bs.modal', function () { |
| 280 | if(sgBackup.isFtpConnected != true) { |
| 281 | jQuery('input[data-storage=FTP]').bootstrapSwitch('state', false); |
| 282 | } |
| 283 | }) |
| 284 | } |
| 285 | else if(modalName == 'amazon-settings') { |
| 286 | jQuery('#sg-modal').on('hidden.bs.modal', function () { |
| 287 | if(sgBackup.isAmazonConnected != true) { |
| 288 | jQuery('input[data-storage=AMAZON]').bootstrapSwitch('state', false); |
| 289 | } |
| 290 | }); |
| 291 | jQuery("#bucketType").on("change", function(){ |
| 292 | jQuery("#bucketType option").each(function() |
| 293 | { |
| 294 | var name = jQuery(this).val(); |
| 295 | jQuery(".form-group-"+name).css("display","none"); |
| 296 | // Add $(this).val() to your list |
| 297 | }); |
| 298 | var selected = jQuery("#bucketType").val(); |
| 299 | jQuery(".form-group-"+selected).css("display","block"); |
| 300 | }) |
| 301 | } |
| 302 | else if(modalName == 'manual-review'){ |
| 303 | var action = 'setReviewPopupState'; |
| 304 | jQuery('#sgLeaveReview').click(function(){ |
| 305 | var reviewUrl = jQuery(this).attr('data-review-url'); |
| 306 | //Never show again |
| 307 | var reviewState = 2; |
| 308 | var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce}); |
| 309 | ajaxHandler.run(); |
| 310 | window.open(reviewUrl); |
| 311 | }); |
| 312 | |
| 313 | jQuery('#sgDontAskAgain').click(function(){ |
| 314 | //Never show again |
| 315 | var reviewState = 2; |
| 316 | var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce}); |
| 317 | ajaxHandler.run(); |
| 318 | }); |
| 319 | |
| 320 | jQuery('#sgAskLater').click(function(){ |
| 321 | var reviewState = 0; |
| 322 | var ajaxHandler = new sgRequestHandler(action, {reviewState: reviewState, token: BG_BACKUP_STRINGS.nonce}); |
| 323 | ajaxHandler.run(); |
| 324 | }); |
| 325 | } |
| 326 | else if(modalName == 'create-schedule') { |
| 327 | sgBackup.initScheduleCreation(); |
| 328 | } |
| 329 | }; |
| 330 | |
| 331 | sgBackup.isAnyOpenModal = function(){ |
| 332 | return jQuery('#sg-modal').length; |
| 333 | }; |
| 334 | |
| 335 | sgBackup.alertGenerator = function(content, alertClass){ |
| 336 | var sgalert = ''; |
| 337 | sgalert+='<div class="alert alert-dismissible '+alertClass+'">'; |
| 338 | sgalert+='<button type="button" class="close" data-dismiss="alert">×</button>'; |
| 339 | if(jQuery.isArray(content)){ |
| 340 | jQuery.each(content, function(index, value) { |
| 341 | sgalert+=value+'<br/>'; |
| 342 | }); |
| 343 | } |
| 344 | else if(content != ''){ |
| 345 | sgalert+=content.replace('[','').replace(']','').replace('"',''); |
| 346 | } |
| 347 | sgalert+='</div>'; |
| 348 | return sgalert; |
| 349 | }; |
| 350 | |
| 351 | sgBackup.scrollToElement = function(id){ |
| 352 | if(jQuery(id).position()){ |
| 353 | if(jQuery(id).position().top < jQuery(window).scrollTop()){ |
| 354 | //scroll up |
| 355 | jQuery('html,body').animate({scrollTop:jQuery(id).position().top}, 1000); |
| 356 | } |
| 357 | else if(jQuery(id).position().top + jQuery(id).height() > jQuery(window).scrollTop() + (window.innerHeight || document.documentElement.clientHeight)){ |
| 358 | //scroll down |
| 359 | jQuery('html,body').animate({scrollTop:jQuery(id).position().top - (window.innerHeight || document.documentElement.clientHeight) + jQuery(id).height() + 15}, 1000); |
| 360 | } |
| 361 | } |
| 362 | }; |
| 363 | |
| 364 | sgBackup.showAjaxSpinner = function(appendToElement){ |
| 365 | if(typeof appendToElement == 'undefined'){ |
| 366 | appendToElement = '#sg-wrapper'; |
| 367 | } |
| 368 | jQuery('<div class="sg-spinner"></div>').appendTo(appendToElement); |
| 369 | }; |
| 370 | |
| 371 | sgBackup.hideAjaxSpinner = function(){ |
| 372 | jQuery('.sg-spinner').remove(); |
| 373 | }; |
| 374 | |
| 375 | sgBackup.showReviewModal = function(){ |
| 376 | if(typeof sgShowReview != 'undefined') { |
| 377 | jQuery('#sg-review').trigger("click"); |
| 378 | } |
| 379 | }; |
| 380 | |
| 381 | sgBackup.initTablePagination = function(){ |
| 382 | jQuery.fn.sgTablePagination = function(opts){ |
| 383 | var jQuerythis = this, |
| 384 | defaults = { |
| 385 | perPage: 7, |
| 386 | showPrevNext: false, |
| 387 | hidePageNumbers: false, |
| 388 | pagerSelector: 'pagination' |
| 389 | }, |
| 390 | settings = jQuery.extend(defaults, opts); |
| 391 | |
| 392 | var listElement = jQuerythis.children('tbody'); |
| 393 | var perPage = settings.perPage; |
| 394 | var children = listElement.children(); |
| 395 | var pager = jQuery('.pager'); |
| 396 | |
| 397 | if (typeof settings.childSelector!="undefined") { |
| 398 | children = listElement.find(settings.childSelector); |
| 399 | } |
| 400 | |
| 401 | if (typeof settings.pagerSelector!="undefined") { |
| 402 | pager = jQuery(settings.pagerSelector); |
| 403 | } |
| 404 | |
| 405 | var numItems = children.size(); |
| 406 | var numPages = Math.ceil(numItems/perPage); |
| 407 | |
| 408 | pager.data("curr",0); |
| 409 | |
| 410 | if (settings.showPrevNext){ |
| 411 | jQuery('<li><a href="#" class="prev_link">«</a></li>').appendTo(pager); |
| 412 | } |
| 413 | |
| 414 | var curr = 0; |
| 415 | while(numPages > curr && (settings.hidePageNumbers==false)){ |
| 416 | jQuery('<li><a href="#" class="page_link">'+(curr+1)+'</a></li>').appendTo(pager); |
| 417 | curr++; |
| 418 | } |
| 419 | |
| 420 | if(curr<=1){ |
| 421 | jQuery(settings.pagerSelector).parent('div').hide(); |
| 422 | jQuery('.page_link').hide(); |
| 423 | } |
| 424 | |
| 425 | if (settings.showPrevNext){ |
| 426 | jQuery('<li><a href="#" class="next_link">»</a></li>').appendTo(pager); |
| 427 | } |
| 428 | |
| 429 | pager.find('.page_link:first').addClass('active'); |
| 430 | pager.find('.prev_link').hide(); |
| 431 | if (numPages<=1) { |
| 432 | pager.find('.next_link').hide(); |
| 433 | } |
| 434 | pager.children().eq(1).addClass("active"); |
| 435 | |
| 436 | children.hide(); |
| 437 | children.slice(0, perPage).show(); |
| 438 | |
| 439 | pager.find('li .page_link').click(function(){ |
| 440 | var clickedPage = jQuery(this).html().valueOf()-1; |
| 441 | goTo(clickedPage,perPage); |
| 442 | return false; |
| 443 | }); |
| 444 | pager.find('li .prev_link').click(function(){ |
| 445 | previous(); |
| 446 | return false; |
| 447 | }); |
| 448 | pager.find('li .next_link').click(function(){ |
| 449 | next(); |
| 450 | return false; |
| 451 | }); |
| 452 | |
| 453 | function previous(){ |
| 454 | var goToPage = parseInt(pager.data("curr")) - 1; |
| 455 | goTo(goToPage); |
| 456 | } |
| 457 | |
| 458 | function next(){ |
| 459 | goToPage = parseInt(pager.data("curr")) + 1; |
| 460 | goTo(goToPage); |
| 461 | } |
| 462 | |
| 463 | function goTo(page){ |
| 464 | var startAt = page * perPage, |
| 465 | endOn = startAt + perPage; |
| 466 | |
| 467 | children.css('display','none').slice(startAt, endOn).show(); |
| 468 | |
| 469 | if (page>=1) { |
| 470 | pager.find('.prev_link').show(); |
| 471 | } |
| 472 | else { |
| 473 | pager.find('.prev_link').hide(); |
| 474 | } |
| 475 | |
| 476 | if (page<(numPages-1)) { |
| 477 | pager.find('.next_link').show(); |
| 478 | } |
| 479 | else { |
| 480 | pager.find('.next_link').hide(); |
| 481 | } |
| 482 | |
| 483 | pager.data("curr",page); |
| 484 | pager.children().removeClass("active"); |
| 485 | pager.children().eq(page+1).addClass("active"); |
| 486 | |
| 487 | } |
| 488 | }; |
| 489 | jQuery('table.paginated').sgTablePagination({pagerSelector:'.pagination',showPrevNext:true,hidePageNumbers:false,perPage:7}); |
| 490 | }; |
| 491 | |
| 492 | sgBackup.logout = function() |
| 493 | { |
| 494 | var ajaxHandler = new sgRequestHandler('logout', {token: BG_BACKUP_STRINGS.nonce}); |
| 495 | ajaxHandler.callback = function(response){ |
| 496 | location.reload(); |
| 497 | }; |
| 498 | ajaxHandler.run(); |
| 499 | } |
| 500 |