Chart.bundle.min.js
6 years ago
bootstrap-switch.min.js
6 years ago
bootstrap.min.js
6 years ago
deactivationSurvey.js
6 years ago
jquery-ui.js
6 years ago
jquery.fileupload.js
6 years ago
jquery.iframe-transport.js
6 years ago
jquery.rateyo.js
6 years ago
jstree.checkbox.js
6 years ago
jstree.min.js
6 years ago
jstree.types.js
6 years ago
jstree.wholerow.js
6 years ago
less.min.js
6 years ago
main.js
6 years ago
popup.js
6 years ago
sgNoticeDismiss.js
6 years ago
sgbackup.js
6 years ago
sgcloud.js
6 years ago
sgdiscount.js
6 years ago
sglicense.js
6 years ago
sglogin.js
6 years ago
sgrequesthandler.js
6 years ago
sgrequesthandler.wordpress.js
6 years ago
sgschedule.js
6 years ago
sgsettings.js
6 years ago
sgsettings.js
185 lines
| 1 | isDirty = false; |
| 2 | |
| 3 | jQuery(document).ready( function() { |
| 4 | sgBackup.initGeneralSettingsSwitchButtons(); |
| 5 | AMOUNT_OF_BACKUPS_TO_KEEP = jQuery("#amount-of-backups-to-keep").val(); |
| 6 | sgBackup.saveInitialState(); |
| 7 | }); |
| 8 | |
| 9 | window.onbeforeunload = function(){ |
| 10 | var msg = 'You haven\'t saved your changes.'; |
| 11 | isDirty = false; |
| 12 | |
| 13 | jQuery(':input').each(function () { |
| 14 | |
| 15 | if (jQuery(this).attr('type') == 'checkbox') { |
| 16 | value = jQuery(this).prop('checked'); |
| 17 | } |
| 18 | else { |
| 19 | value = jQuery(this).val(); |
| 20 | } |
| 21 | |
| 22 | if(jQuery(this).data('initialValue') != value){ |
| 23 | isDirty = true; |
| 24 | } |
| 25 | }); |
| 26 | |
| 27 | if(isDirty == true){ |
| 28 | return msg; |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | sgBackup.saveInitialState = function() { |
| 33 | jQuery(':input').each(function() { |
| 34 | if (jQuery(this).attr('type') == 'checkbox') { |
| 35 | value = jQuery(this).prop('checked'); |
| 36 | } |
| 37 | else { |
| 38 | value = jQuery(this).val(); |
| 39 | } |
| 40 | |
| 41 | jQuery(this).data('initialValue', value); |
| 42 | }); |
| 43 | }; |
| 44 | |
| 45 | sgBackup.initGeneralSettingsSwitchButtons = function() { |
| 46 | jQuery('.sg-switch').bootstrapSwitch(); |
| 47 | |
| 48 | jQuery('.sg-email-switch').on('switchChange.bootstrapSwitch', function (event, state) { |
| 49 | var url = jQuery(this).attr('data-remote'); |
| 50 | if (state) { |
| 51 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: 'NOTIFICATIONS'}); |
| 52 | isFeatureAvailable.callback = function(response) { |
| 53 | if (typeof response.success !== 'undefined') { |
| 54 | //If switch is on |
| 55 | jQuery('.sg-general-settings').fadeToggle(); |
| 56 | } |
| 57 | else { |
| 58 | jQuery('.alert').remove(); |
| 59 | var alert = sgBackup.alertGenerator(response.error, 'alert-warning'); |
| 60 | jQuery('.sg-settings-container legend').after(alert); |
| 61 | jQuery('.sg-email-switch').bootstrapSwitch('state', false); |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | isFeatureAvailable.run(); |
| 67 | } |
| 68 | else { |
| 69 | var ajaxHandler = new sgRequestHandler(url, {cancel: true}); |
| 70 | ajaxHandler.callback = function(response){ |
| 71 | jQuery('.sg-user-email').remove(); |
| 72 | jQuery('.sg-general-settings').hide(); |
| 73 | }; |
| 74 | ajaxHandler.run(); |
| 75 | jQuery('#sg-user-email').remove(); |
| 76 | jQuery('#sg-email').val(''); |
| 77 | } |
| 78 | }); |
| 79 | |
| 80 | jQuery('.sg-switch').on('switchChange.bootstrapSwitch', function (event, state) { |
| 81 | that = this; |
| 82 | var feature = jQuery(this).attr('sgFeatureName'); |
| 83 | if (feature && feature != 'NOTIFICATIONS') { |
| 84 | var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: feature}); |
| 85 | isFeatureAvailable.callback = function(response) { |
| 86 | if (state) { |
| 87 | if (typeof response.error !== 'undefined') { |
| 88 | jQuery('.alert').remove(); |
| 89 | var alert = sgBackup.alertGenerator(response.error, 'alert-warning'); |
| 90 | jQuery('.sg-settings-container legend').after(alert); |
| 91 | jQuery(that).bootstrapSwitch('state', false); |
| 92 | return false; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | isFeatureAvailable.run(); |
| 98 | } |
| 99 | }); |
| 100 | }; |
| 101 | |
| 102 | sgBackup.sgsettings = function(){ |
| 103 | var settingsForm = jQuery('form[data-type=sgsettings]'); |
| 104 | var error = []; |
| 105 | //Validation |
| 106 | jQuery('.alert').remove(); |
| 107 | |
| 108 | if(jQuery('.sg-email-switch').is(":checked")){ |
| 109 | var emails = jQuery('#sg-email').val().split(","); |
| 110 | |
| 111 | jQuery.each(emails, function( index, value ) { |
| 112 | value = jQuery.trim(value); |
| 113 | if(!sgBackup.isValidEmailAddress(value)){ |
| 114 | error.push(BG_SETTINGS_STRINGS.invalidEmailAddress); |
| 115 | } |
| 116 | }); |
| 117 | } |
| 118 | |
| 119 | var backupFileName = jQuery('#backup-file-name').val(); |
| 120 | |
| 121 | if (typeof amountOfBackups !== 'undefined' && !backupFileName) { |
| 122 | error.push(BG_SETTINGS_STRINGS.invalidFileName); |
| 123 | } |
| 124 | |
| 125 | var amountOfBackups = jQuery('#amount-of-backups-to-keep').val(); |
| 126 | if (typeof amountOfBackups !== 'undefined' && (!jQuery.isNumeric(amountOfBackups) || amountOfBackups <= 0)) { |
| 127 | error.push(BG_SETTINGS_STRINGS.invalidRetentionNumber); |
| 128 | } |
| 129 | else if (AMOUNT_OF_BACKUPS_TO_KEEP != amountOfBackups) { |
| 130 | if (!confirm(BG_SETTINGS_STRINGS.retentionConfirmationFirstPart+' '+amountOfBackups+' '+BG_SETTINGS_STRINGS.retentionConfirmationSecondPart)) { |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | //If any error show it and abort ajax |
| 136 | if(error.length){ |
| 137 | var alert = sgBackup.alertGenerator(error, 'alert-danger'); |
| 138 | jQuery('.sg-settings-container legend').after(alert); |
| 139 | sgBackup.scrollToElement('.alert'); |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | //Before sending |
| 144 | var userEmail = jQuery('#sg-email').val(); |
| 145 | jQuery('#sg-save-settings').attr('disabled','disabled'); |
| 146 | jQuery('#sg-save-settings').html(BG_SETTINGS_STRINGS.savingInProgress); |
| 147 | |
| 148 | //On Success |
| 149 | var ajaxHandler = new sgRequestHandler('settings', settingsForm.serialize()); |
| 150 | ajaxHandler.dataIsObject = false; |
| 151 | ajaxHandler.callback = function(response){ |
| 152 | jQuery('.alert').remove(); |
| 153 | if(typeof response.success !== 'undefined'){ |
| 154 | var alert = sgBackup.alertGenerator(BG_SETTINGS_STRINGS.successMessage, 'alert-success'); |
| 155 | jQuery('.sg-settings-container legend').after(alert); |
| 156 | sgBackup.addUserInfo(userEmail); |
| 157 | //jQuery('.sg-switch').bootstrapSwitch('state', true, true); |
| 158 | jQuery('.sg-general-settings').fadeOut(); |
| 159 | sgBackup.saveInitialState(); |
| 160 | } |
| 161 | else{ |
| 162 | //if error |
| 163 | var alert = sgBackup.alertGenerator(response, 'alert-danger'); |
| 164 | jQuery('.sg-settings-container legend').after(alert); |
| 165 | } |
| 166 | |
| 167 | //Always |
| 168 | jQuery('#sg-save-settings').removeAttr('disabled','disabled'); |
| 169 | jQuery('#sg-save-settings').html(BG_SETTINGS_STRINGS.saveButtonText); |
| 170 | sgBackup.scrollToElement('.alert'); |
| 171 | }; |
| 172 | ajaxHandler.run(); |
| 173 | }; |
| 174 | |
| 175 | sgBackup.addUserInfo = function(info){ |
| 176 | jQuery('.sg-user-info .sg-helper-block').remove(); |
| 177 | jQuery('.sg-user-info br').remove(); |
| 178 | jQuery('.sg-user-info').append('<br/><span class="text-muted sg-user-email sg-helper-block">'+info+'</span>'); |
| 179 | }; |
| 180 | |
| 181 | sgBackup.isValidEmailAddress = function(emailAddress) { |
| 182 | var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,10}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i); |
| 183 | return pattern.test(emailAddress); |
| 184 | } |
| 185 |