| @@ -3,8 +3,141 @@ | ||
| 3 | 3 | jQuery('#mainwp-install-extensions-promo-modal').modal('show'); |
| 4 | 4 | return false; |
| 5 | 5 | }); |
| 6 | 6 | |
| 7 | +jQuery(document).on('click', '#mainwp-extension-update-check-retry', function () { | |
| 8 | + let button = jQuery(this); | |
| 9 | + let status = jQuery('#mainwp-extension-update-check-retry-status'); | |
| 10 | + let failedText = button.data('failed-text'); | |
| 11 | + | |
| 12 | + button.addClass('loading disabled').prop('disabled', true); | |
| 13 | + status.text(''); | |
| 14 | + | |
| 15 | + jQuery.post(ajaxurl, mainwp_secure_data({ | |
| 16 | + action: 'mainwp_extension_update_check_retry' | |
| 17 | + }), function (response) { | |
| 18 | + if (response && response.result === 'SUCCESS') { | |
| 19 | + location.reload(); | |
| 20 | + return; | |
| 21 | + } | |
| 22 | + | |
| 23 | + status.text(response && response.error ? response.error : failedText); | |
| 24 | + button.removeClass('loading disabled').prop('disabled', false); | |
| 25 | + }, 'json').fail(function () { | |
| 26 | + status.text(failedText); | |
| 27 | + button.removeClass('loading disabled').prop('disabled', false); | |
| 28 | + }); | |
| 29 | + | |
| 30 | + return false; | |
| 31 | +}); | |
| 32 | + | |
| 33 | +jQuery(document).on('click', '#mainwp-extensions-show-all', function () { | |
| 34 | + jQuery(this).addClass('green'); | |
| 35 | + jQuery('#mainwp-extensions-show-extensions').removeClass('green'); | |
| 36 | + jQuery('#mainwp-extensions-show-integrations').removeClass('green'); | |
| 37 | + jQuery('#mainwp-extensions-list').find('.card[extension-model="integration"]').fadeIn(200); | |
| 38 | + jQuery('#mainwp-extensions-list').find('.card[extension-model="extension"]').fadeIn(200); | |
| 39 | +}); | |
| 40 | + | |
| 41 | +jQuery(document).on('click', '#mainwp-extensions-show-extensions', function () { | |
| 42 | + jQuery(this).addClass('green'); | |
| 43 | + jQuery('#mainwp-extensions-show-all').removeClass('green'); | |
| 44 | + jQuery('#mainwp-extensions-show-integrations').removeClass('green'); | |
| 45 | + jQuery('#mainwp-extensions-list').find('.card[extension-model="integration"]').fadeOut(200); | |
| 46 | + jQuery('#mainwp-extensions-list').find('.card[extension-model="extension"]').fadeIn(200); | |
| 47 | +}); | |
| 48 | + | |
| 49 | +jQuery(document).on('click', '#mainwp-extensions-show-integrations', function () { | |
| 50 | + jQuery(this).addClass('green'); | |
| 51 | + jQuery('#mainwp-extensions-show-extensions').removeClass('green'); | |
| 52 | + jQuery('#mainwp-extensions-show-all').removeClass('green'); | |
| 53 | + jQuery('#mainwp-extensions-list').find('.card[extension-model="integration"]').fadeIn(200); | |
| 54 | + jQuery('#mainwp-extensions-list').find('.card[extension-model="extension"]').fadeOut(200); | |
| 55 | +}); | |
| 56 | + | |
| 57 | +jQuery(document).on('click', '#mainwp-extensions-manage-toggle-on', function () { | |
| 58 | + jQuery('#mainwp-manage-add-ons-buttons').hide(); | |
| 59 | + jQuery('#mainwp-manage-license-buttons').removeClass('hidden').show(); | |
| 60 | + jQuery('#mainwp_com_api_key').focus(); | |
| 61 | + return false; | |
| 62 | +}); | |
| 63 | + | |
| 64 | +jQuery(document).on('click', '#mainwp-extensions-manage-toggle-off', function () { | |
| 65 | + jQuery('#mainwp-manage-license-buttons').hide(); | |
| 66 | + jQuery('#mainwp-manage-add-ons-buttons').show(); | |
| 67 | + mainwp_extensions_check_activate_button_state(); | |
| 68 | + return false; | |
| 69 | +}); | |
| 70 | + | |
| 71 | +function mainwp_extensions_check_activate_button_state() { | |
| 72 | + let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); | |
| 73 | + if (api_key === '') { | |
| 74 | + jQuery('#mainwp-extensions-grabkeys').addClass('disabled').attr('disabled', true); | |
| 75 | + } else { | |
| 76 | + jQuery('#mainwp-extensions-grabkeys').removeClass('disabled').attr('disabled', false); | |
| 77 | + } | |
| 78 | +} | |
| 79 | + | |
| 80 | +function mainwp_extensions_update_status_header() { | |
| 81 | + let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); | |
| 82 | + let count_enabled = jQuery('#mainwp-extensions-list .card.mainwp-enabled-extension').length; | |
| 83 | + let count_not_activated = jQuery('#mainwp-extensions-list .card.mainwp-enabled-extension[license-status="deactivated"]').length; | |
| 84 | + let count_activated = count_enabled - count_not_activated; | |
| 85 | + let headerHtml = ''; | |
| 86 | + | |
| 87 | + if (api_key === '') { | |
| 88 | + headerHtml = '<h2 class="ui small header">' + | |
| 89 | + '<i class="large yellow warning icon"></i>' + | |
| 90 | + '<div class="content">' + | |
| 91 | + 'License Inactive' + | |
| 92 | + '<div class="sub header">' + | |
| 93 | + count_enabled + ' add-ons enabled • Missing License key • Updates Disabled' + | |
| 94 | + '</div>' + | |
| 95 | + '</div>' + | |
| 96 | + '</h2>'; | |
| 97 | + } else if (count_not_activated > 0) { | |
| 98 | + let title = count_not_activated === 1 ? | |
| 99 | + count_not_activated + ' add-on not activated' : | |
| 100 | + count_not_activated + ' add-ons not activated'; | |
| 101 | + headerHtml = '<h2 class="ui small header">' + | |
| 102 | + '<i class="large yellow warning icon"></i>' + | |
| 103 | + '<div class="content">' + | |
| 104 | + title + | |
| 105 | + '<div class="sub header">' + | |
| 106 | + count_enabled + ' add-ons enabled • ' + count_activated + ' activated • Updates enabled for activated add-ons' + | |
| 107 | + '</div>' + | |
| 108 | + '</div>' + | |
| 109 | + '</h2>'; | |
| 110 | + } else { | |
| 111 | + headerHtml = '<h2 class="ui small header">' + | |
| 112 | + '<i class="large green check icon"></i>' + | |
| 113 | + '<div class="content">' + | |
| 114 | + 'License Active' + | |
| 115 | + '<div class="sub header">' + | |
| 116 | + count_enabled + ' add-ons enabled • All activated • Updates enabled' + | |
| 117 | + '</div>' + | |
| 118 | + '</div>' + | |
| 119 | + '</h2>'; | |
| 120 | + } | |
| 121 | + | |
| 122 | + jQuery('#mainwp-extensions-status-header').html(headerHtml); | |
| 123 | +} | |
| 124 | + | |
| 125 | +// Run a callback after a delay. | |
| 126 | +function run_after_delay(callback, delay = 3000) { | |
| 127 | + if (typeof callback !== 'function') { | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + setTimeout(callback, delay); | |
| 131 | +} | |
| 132 | + | |
| 133 | +jQuery(document).ready(function () { | |
| 134 | + mainwp_extensions_check_activate_button_state(); | |
| 135 | + jQuery('#mainwp_com_api_key').on('input', function () { | |
| 136 | + mainwp_extensions_check_activate_button_state(); | |
| 137 | + }); | |
| 138 | +}); | |
| 139 | + | |
| 7 | 140 | jQuery(document).on('click', '.mainwp-extensions-add-menu', function () { |
| 8 | 141 | let extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug'); |
| 9 | 142 | let data = mainwp_secure_data({ |
| 10 | 143 | action: 'mainwp_extension_add_menu', |
| @@ -36,9 +169,9 @@ | ||
| 36 | 169 | |
| 37 | 170 | return false; |
| 38 | 171 | }); |
| 39 | 172 | |
| 40 | -jQuery(function () { | |
| 173 | +jQuery(function () { // NOSONAR - levels deep ok. | |
| 41 | 174 | jQuery(document).on('click', '.mainwp-manage-extension-license', function () { |
| 42 | 175 | let currentCard = jQuery(this).closest(".card"); |
| 43 | 176 | currentCard.find("#mainwp-extensions-api-form").toggle(); |
| 44 | 177 | if (jQuery(this).attr('api-actived') == '0') { |
| @@ -65,12 +198,12 @@ | ||
| 65 | 198 | allowMultiple: true, |
| 66 | 199 | onShow: function () { |
| 67 | 200 | jQuery('#mainwp-privacy-info-modal').find('.header').html(title + ' Privacy Info'); |
| 68 | 201 | if (0 == privacy) { |
| 69 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('Standalone Extension. This Extension does not use any 3rd party plugins or API\'s to integrate with your Dashboard. This extension falls under the <a href="https://mainwp.com/mainwp-plugin-privacy-policy/" target="_blank">MainWP Plugin Privacy Policy</a>.'); // NOSONAR - noopener - open safe. | |
| 202 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('Standalone Add-on. This Add-on does not use any 3rd party plugins or API\'s to integrate with your Dashboard. This add-on falls under the <a href="https://mainwp.com/mainwp-plugin-privacy-policy/" target="_blank">MainWP Plugin Privacy Policy</a>.'); // NOSONAR - noopener - open safe. | |
| 70 | 203 | } else if (1 == privacy) { |
| 71 | 204 | if (slug == 'advanced-uptime-monitor-extension') { |
| 72 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party API.</strong>'); | |
| 205 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); | |
| 73 | 206 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 74 | 207 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 75 | 208 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 76 | 209 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| @@ -86,9 +219,9 @@ | ||
| 86 | 219 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://www.site24x7.com/" target="_blank">Site24x7 API</a>'); |
| 87 | 220 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 88 | 221 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.zoho.com/privacy.html" target="_blank">Zoho Corporation Pvt. Ltd.</a>'); |
| 89 | 222 | } else if (slug == 'mainwp-vulnerability-checker-extension') { |
| 90 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party API.</strong>'); | |
| 223 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); | |
| 91 | 224 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 92 | 225 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 93 | 226 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 94 | 227 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| @@ -96,9 +229,9 @@ | ||
| 96 | 229 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://nvd.nist.gov/" target="_blank">NVD NIST API</a>'); |
| 97 | 230 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 98 | 231 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.nist.gov/privacy-policy" target="_blank">National Institute of Standards and Technology</a>'); |
| 99 | 232 | } else if (slug == 'mainwp-api-backups-extension') { |
| 100 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party API.</strong>'); | |
| 233 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); | |
| 101 | 234 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 102 | 235 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 103 | 236 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 104 | 237 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| @@ -118,9 +251,9 @@ | ||
| 118 | 251 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://www.vultr.com/" target="_blank">Vultr API</a>'); |
| 119 | 252 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 120 | 253 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.vultr.com/legal/privacy/" target="_blank">Constant Company, LLC.</a>'); |
| 121 | 254 | } else { |
| 122 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party API.</strong>'); | |
| 255 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); | |
| 123 | 256 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 124 | 257 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 125 | 258 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 126 | 259 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| @@ -125,21 +258,21 @@ | ||
| 125 | 258 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 126 | 259 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 127 | 260 | } |
| 128 | 261 | } else if (2 == privacy) { |
| 129 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party Plugin.</strong>'); | |
| 262 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party Plugin.</strong>'); | |
| 130 | 263 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 131 | 264 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 132 | 265 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 133 | 266 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 134 | 267 | } else if (slug == 'mainwp-page-speed-extension') { |
| 135 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party Plugin.</strong>'); | |
| 268 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party Plugin.</strong>'); | |
| 136 | 269 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 137 | 270 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://wordpress.org/plugins/google-pagespeed-insights/" target="_blank">Insights from Google PageSpeed</a>'); |
| 138 | 271 | jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 139 | 272 | jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://mattkeys.me/" target="_blank">Matt Keys</a>'); |
| 140 | 273 | } else { |
| 141 | - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>This extension is not developed by MainWP. Privacy info is not available.</strong>'); | |
| 274 | + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>This add-on is not developed by MainWP. Privacy info is not available.</strong>'); | |
| 142 | 275 | } |
| 143 | 276 | }, |
| 144 | 277 | onHide: function () { |
| 145 | 278 | jQuery('#mainwp-privacy-info-modal').find('.header').html(''); |
| @@ -149,65 +282,90 @@ | ||
| 149 | 282 | |
| 150 | 283 | return false; |
| 151 | 284 | }); |
| 152 | 285 | |
| 153 | - jQuery(document).on('click', '.extension-the-plugin-action', function () { | |
| 286 | + jQuery(document).on('click', '.extension-the-plugin-action', function () { // eslint-disable-line unicorn/no-nested-ternary | |
| 154 | 287 | let parent = jQuery(this).closest(".card"); |
| 155 | 288 | let slug = jQuery(parent).attr('extension-slug'); |
| 156 | 289 | let loadingEl = parent.find(".action-feedback"); |
| 157 | 290 | let whatAct = jQuery(this).attr("plugin-action"); |
| 158 | 291 | |
| 159 | - loadingEl.show(); | |
| 160 | - loadingEl.find('.message').removeClass('red green'); | |
| 292 | + let _callback = function () { | |
| 293 | + let $btn = jQuery(this); // ✅ store correct context | |
| 161 | 294 | |
| 162 | - let msg = __('Deactivating...'); | |
| 163 | - if (whatAct == 'active') { | |
| 164 | - msg = __('Activating...'); | |
| 165 | - } else if (whatAct == 'remove') { | |
| 166 | - msg = __('Removing...'); | |
| 167 | - } | |
| 295 | + loadingEl.show(); | |
| 168 | 296 | |
| 169 | - loadingEl.find('.message').html('<i class="notched circle loading icon"></i> ' + msg); | |
| 297 | + let msg = MainWP.I18n.t('Disabling add-on...'); | |
| 298 | + if (whatAct === 'active') { | |
| 299 | + msg = MainWP.I18n.t('Enabling add-on...'); | |
| 300 | + } else if (whatAct === 'remove') { | |
| 301 | + msg = MainWP.I18n.t('Removing add-on...'); | |
| 302 | + } | |
| 170 | 303 | |
| 171 | - let data = mainwp_secure_data({ | |
| 172 | - action: 'mainwp_extension_plugin_action', | |
| 173 | - slug: slug, | |
| 174 | - what: whatAct, | |
| 175 | - }); | |
| 304 | + loadingEl.find('.ui.text.loader').html(msg); | |
| 176 | 305 | |
| 177 | - jQuery(this).attr('disabled', true); | |
| 178 | - jQuery.post(ajaxurl, data, function (response) { | |
| 179 | - jQuery(this).attr('disabled', false); | |
| 180 | - let success = false; | |
| 181 | - if (response) { | |
| 182 | - if (response.result == 'SUCCESS') { | |
| 183 | - loadingEl.find('.message').addClass('green'); | |
| 184 | - msg = __('Extension deactivated.'); | |
| 185 | - if (whatAct == 'active') { | |
| 186 | - msg = __('Extension activated.'); | |
| 187 | - } else if (whatAct == 'remove') { | |
| 188 | - msg = __('Extension removed.'); | |
| 189 | - } | |
| 190 | - loadingEl.find('.message').html(msg); | |
| 191 | - success = true; | |
| 192 | - } else if (response.error) { | |
| 193 | - loadingEl.find('.message').addClass('red'); | |
| 194 | - loadingEl.find('.message').html(response.error); | |
| 195 | - } else { | |
| 196 | - loadingEl.find('.message').addClass('red'); | |
| 197 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 306 | + let data = mainwp_secure_data({ | |
| 307 | + action: 'mainwp_extension_plugin_action', | |
| 308 | + slug: slug, | |
| 309 | + what: whatAct, | |
| 310 | + }); | |
| 311 | + | |
| 312 | + function handleAddonResponse(response) { | |
| 313 | + $btn.attr('disabled', false); // ✅ correct button | |
| 314 | + | |
| 315 | + if (!response) { | |
| 316 | + showError(MainWP.I18n.t('Undefined error')); | |
| 317 | + return; | |
| 198 | 318 | } |
| 199 | - } else { | |
| 200 | - loadingEl.find('.message').addClass('red'); | |
| 201 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 319 | + | |
| 320 | + if (response.result === 'SUCCESS') { | |
| 321 | + handleSuccess(); | |
| 322 | + return; | |
| 323 | + } | |
| 324 | + | |
| 325 | + if (response.error) { | |
| 326 | + showError(response.error); | |
| 327 | + return; | |
| 328 | + } | |
| 329 | + | |
| 330 | + showError(MainWP.I18n.t('Undefined error')); | |
| 202 | 331 | } |
| 203 | 332 | |
| 204 | - if (success) { | |
| 205 | - setTimeout(function () { | |
| 206 | - location.href = 'admin.php?page=Extensions'; | |
| 333 | + function handleSuccess() { | |
| 334 | + let msg = MainWP.I18n.t('Add-on disabled'); | |
| 335 | + | |
| 336 | + if (whatAct === 'active') { | |
| 337 | + msg = MainWP.I18n.t('Add-on enabled'); | |
| 338 | + } else if (whatAct === 'remove') { | |
| 339 | + msg = MainWP.I18n.t('Add-on removed'); | |
| 340 | + } | |
| 341 | + | |
| 342 | + loadingEl.find('.ui.text.loader').html(msg); | |
| 343 | + | |
| 344 | + run_after_delay(() => { | |
| 345 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 207 | 346 | }, 2000); |
| 208 | 347 | } |
| 209 | - }, 'json'); | |
| 348 | + | |
| 349 | + function showError(message) { | |
| 350 | + loadingEl.find('.ui.text.loader').html(message); | |
| 351 | + | |
| 352 | + run_after_delay(() => { | |
| 353 | + loadingEl.hide(); | |
| 354 | + }); | |
| 355 | + } | |
| 356 | + | |
| 357 | + $btn.attr('disabled', true); | |
| 358 | + | |
| 359 | + jQuery.post(ajaxurl, data, handleAddonResponse, 'json'); | |
| 360 | + }; | |
| 361 | + | |
| 362 | + if ('remove' === whatAct) { | |
| 363 | + let msg = MainWP.I18n.t('Are you sure you want to remove this add-on?'); | |
| 364 | + mainwp_confirm(msg, _callback); | |
| 365 | + } else { | |
| 366 | + _callback(); | |
| 367 | + } | |
| 210 | 368 | return false; |
| 211 | 369 | }); |
| 212 | 370 | }); |
| 213 | 371 | |
| @@ -222,10 +380,8 @@ | ||
| 222 | 380 | |
| 223 | 381 | loadingEl.hide(); |
| 224 | 382 | |
| 225 | 383 | if (jQuery(pObj).attr('license-status') == 'activated') { |
| 226 | - loadingEl.show(); | |
| 227 | - loadingEl.find('.message').html(__('Already activated.')); | |
| 228 | 384 | return; |
| 229 | 385 | } |
| 230 | 386 | |
| 231 | 387 | let data = false; |
| @@ -231,9 +387,9 @@ | ||
| 231 | 387 | let data = false; |
| 232 | 388 | |
| 233 | 389 | if (retring) { |
| 234 | 390 | loadingEl.show(); |
| 235 | - loadingEl.find('.message').html(__('Connection error detected. The Verify Certificate option has been switched to NO. Retrying...')); | |
| 391 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Connection error detected. The Verify Certificate option has been switched to NO. Retrying...')); | |
| 236 | 392 | } else { |
| 237 | 393 | let extensionSlug = jQuery(apiEl).attr('extension-slug'); |
| 238 | 394 | let key = apiEl.find('input[type="text"].extension-api-key').val(); |
| 239 | 395 | let email = apiEl.find('input[type="text"].extension-api-email').val(); |
| @@ -249,10 +405,9 @@ | ||
| 249 | 405 | }); |
| 250 | 406 | } |
| 251 | 407 | |
| 252 | 408 | loadingEl.show(); |
| 253 | - loadingEl.find('.message').removeClass('red green'); | |
| 254 | - loadingEl.find('.message').html('<i class="notched circle loading icon"></i>' + __('Activating...')); | |
| 409 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Activating license...')); | |
| 255 | 410 | |
| 256 | 411 | jQuery.post(ajaxurl, data, function (response) { |
| 257 | 412 | |
| 258 | 413 | let success = false; |
| @@ -258,31 +413,33 @@ | ||
| 258 | 413 | let success = false; |
| 259 | 414 | |
| 260 | 415 | if (response) { |
| 261 | 416 | if (response.result == 'SUCCESS') { |
| 262 | - loadingEl.find('.message').addClass('green'); | |
| 263 | - loadingEl.find('.message').html(__('License activated. ')); | |
| 264 | - statusEl.html('<i class="green check icon"></i> License'); | |
| 417 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('License activated')); | |
| 418 | + statusEl.html('<i class="green key icon"></i> Licensed'); | |
| 265 | 419 | success = true; |
| 266 | 420 | } else if (response.error) { |
| 267 | - loadingEl.find('.message').addClass('red'); | |
| 268 | - loadingEl.find('.message').html(response.error); | |
| 421 | + loadingEl.find('.ui.text.loader').html(response.error); | |
| 269 | 422 | } else if (response.retry_action && response.retry_action == 1) { |
| 270 | 423 | jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 271 | 424 | mainwp_extensions_activate(pObj, true); |
| 272 | 425 | return false; |
| 273 | 426 | } else { |
| 274 | - loadingEl.find('.message').addClass('red'); | |
| 275 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 427 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); | |
| 428 | + setTimeout(function () { | |
| 429 | + loadingEl.hide(); | |
| 430 | + }, 3000); | |
| 276 | 431 | } |
| 277 | 432 | } else { |
| 278 | - loadingEl.find('.message').addClass('red'); | |
| 279 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 433 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); | |
| 434 | + setTimeout(function () { | |
| 435 | + loadingEl.hide(); | |
| 436 | + }, 3000); | |
| 280 | 437 | } |
| 281 | 438 | |
| 282 | 439 | if (success) { |
| 283 | 440 | setTimeout(function () { |
| 284 | - location.href = 'admin.php?page=Extensions'; | |
| 441 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 285 | 442 | }, 2000); |
| 286 | 443 | } |
| 287 | 444 | }, 'json'); |
| 288 | 445 | return false; |
| @@ -287,17 +444,22 @@ | ||
| 287 | 444 | }, 'json'); |
| 288 | 445 | return false; |
| 289 | 446 | } |
| 290 | 447 | |
| 448 | +jQuery(document).on('click', '.mainwp-extension-license-cancel', function () { | |
| 449 | + let currentCard = jQuery(this).closest(".card"); | |
| 450 | + currentCard.find("#mainwp-extensions-api-form").hide(); | |
| 451 | + return false; | |
| 452 | +}); | |
| 453 | + | |
| 291 | 454 | jQuery(document).on('click', '.mainwp-extensions-deactivate', function () { |
| 292 | 455 | let apiEl = jQuery(this).closest(".card"); |
| 293 | 456 | let statusEl = apiEl.find(".activate-api-status"); |
| 294 | 457 | let loadingEl = apiEl.find(".api-feedback"); |
| 458 | + let formEl = apiEl.find("#mainwp-extensions-api-form"); | |
| 295 | 459 | |
| 296 | - if (!apiEl.find('.mainwp-extensions-deactivate-chkbox').is(':checked')) | |
| 297 | - return; | |
| 298 | - | |
| 299 | 460 | loadingEl.hide(); |
| 461 | + formEl.hide(); | |
| 300 | 462 | |
| 301 | 463 | let extensionSlug = jQuery(apiEl).attr('extension-slug'); |
| 302 | 464 | let extensionApiKey = jQuery(apiEl).find('.extension-api-key').val(); |
| 303 | 465 | let data = mainwp_secure_data({ |
| @@ -306,32 +468,37 @@ | ||
| 306 | 468 | api_key: extensionApiKey |
| 307 | 469 | }); |
| 308 | 470 | |
| 309 | 471 | loadingEl.show(); |
| 310 | - loadingEl.find('.message').removeClass('red green'); | |
| 311 | - loadingEl.find('.message').html('<i class="notched circle loading icon"></i>' + __('Deactivating...')); | |
| 472 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Deactivating license...')); | |
| 312 | 473 | |
| 313 | 474 | jQuery.post(ajaxurl, data, function (response) { |
| 314 | 475 | |
| 315 | 476 | if (response) { |
| 316 | 477 | if (response.result == 'SUCCESS') { |
| 317 | - loadingEl.find('.message').addClass('green'); | |
| 318 | - loadingEl.find('.message').html(__('License deactivated.')); | |
| 319 | - statusEl.html('<i class="green check icon"></i> License'); | |
| 478 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('License deactivated')); | |
| 479 | + statusEl.html('<i class="red key icon"></i> ' + MainWP.I18n.t('Activate License')); | |
| 480 | + statusEl.attr('api-actived', '0'); | |
| 320 | 481 | } else if (response.error) { |
| 321 | - loadingEl.find('.message').addClass('red'); | |
| 322 | - loadingEl.find('.message').html(response.error); | |
| 482 | + loadingEl.find('.ui.text.loader').html(response.error); | |
| 483 | + setTimeout(function () { | |
| 484 | + loadingEl.hide(); | |
| 485 | + }, 3000); | |
| 323 | 486 | } else { |
| 324 | - loadingEl.find('.message').addClass('red'); | |
| 325 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 487 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); | |
| 488 | + setTimeout(function () { | |
| 489 | + loadingEl.hide(); | |
| 490 | + }, 3000); | |
| 326 | 491 | } |
| 327 | 492 | } else { |
| 328 | - loadingEl.find('.message').addClass('red'); | |
| 329 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 493 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); | |
| 494 | + setTimeout(function () { | |
| 495 | + loadingEl.hide(); | |
| 496 | + }, 3000); | |
| 330 | 497 | } |
| 331 | 498 | |
| 332 | 499 | setTimeout(function () { |
| 333 | - location.href = 'admin.php?page=Extensions'; | |
| 500 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 334 | 501 | }, 2000); |
| 335 | 502 | }, 'json'); |
| 336 | 503 | }); |
| 337 | 504 | |
| @@ -337,14 +504,14 @@ | ||
| 337 | 504 | |
| 338 | 505 | |
| 339 | 506 | // Verify mainwp.com login credentials |
| 340 | 507 | jQuery(document).on('click', '#mainwp-extensions-savelogin', function () { |
| 341 | - mainwp_extensions_savelogin(this, false); | |
| 508 | + let autoTriggerInstall = jQuery(this).attr('data-context') === 'intro-notice'; | |
| 509 | + mainwp_extensions_savelogin(false, autoTriggerInstall); | |
| 342 | 510 | }); |
| 343 | 511 | |
| 344 | -function mainwp_extensions_savelogin(pObj, retring) { | |
| 345 | - let grabingEl = jQuery("#mainwp-extensions-api-fields"); | |
| 346 | - let api_key = grabingEl.find('#mainwp_com_api_key').val(); | |
| 512 | +function mainwp_extensions_savelogin(retring, autoTriggerInstall) { | |
| 513 | + let api_key = jQuery('#mainwp_com_api_key').val() || ''; | |
| 347 | 514 | let statusEl = jQuery(".mainwp-extensions-api-loading"); |
| 348 | 515 | let data = mainwp_secure_data({ |
| 349 | 516 | action: 'mainwp_extension_saveextensionapilogin', |
| 350 | 517 | api_key: api_key, |
| @@ -351,29 +518,42 @@ | ||
| 351 | 518 | saveLogin: jQuery('#extensions_api_savemylogin_chk').is(':checked') ? 1 : 0 |
| 352 | 519 | }); |
| 353 | 520 | |
| 354 | 521 | if (retring) { |
| 355 | - statusEl.find('.text').html(__("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn(); | |
| 522 | + statusEl.find('.text').html(MainWP.I18n.t("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn(); | |
| 356 | 523 | } else { |
| 357 | 524 | |
| 358 | - statusEl.find('.text').html(__('Validating...')); | |
| 525 | + statusEl.find('.text').html(MainWP.I18n.t('Validating...')); | |
| 359 | 526 | } |
| 360 | 527 | |
| 361 | 528 | statusEl.show(); |
| 362 | 529 | |
| 363 | - jQuery.post(ajaxurl, data, function (response) { | |
| 530 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - Complexity. | |
| 364 | 531 | let undefError = false; |
| 532 | + let isSuccess = false; | |
| 365 | 533 | if (response) { |
| 366 | 534 | if (response.saved) { |
| 367 | - statusEl.find('.text').html('Your API license key has been successfully saved!'); | |
| 535 | + isSuccess = true; | |
| 536 | + if (autoTriggerInstall) { | |
| 537 | + statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...')); | |
| 538 | + mainwp_extension_grab_purchased(false); | |
| 539 | + } else { | |
| 540 | + statusEl.find('.text').html('Your API license key has been successfully saved!'); | |
| 541 | + } | |
| 368 | 542 | } else if (response.result == 'SUCCESS') { |
| 369 | - statusEl.find('.text').html('API license key verification successful!'); | |
| 543 | + isSuccess = true; | |
| 544 | + if (autoTriggerInstall) { | |
| 545 | + statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...')); | |
| 546 | + mainwp_extension_grab_purchased(false); | |
| 547 | + } else { | |
| 548 | + statusEl.find('.text').html('API license key verification successful!'); | |
| 549 | + } | |
| 370 | 550 | } else if (response.error) { |
| 371 | 551 | statusEl.find('.text').html(response.error); |
| 372 | 552 | } else if (response.retry_action && response.retry_action == 1) { |
| 373 | 553 | jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 374 | 554 | statusEl.fadeOut(); |
| 375 | - mainwp_extensions_savelogin(pObj, true); | |
| 555 | + mainwp_extensions_savelogin(true, autoTriggerInstall); | |
| 376 | 556 | return false; |
| 377 | 557 | } else { |
| 378 | 558 | undefError = true; |
| 379 | 559 | } |
| @@ -381,14 +561,23 @@ | ||
| 381 | 561 | undefError = true; |
| 382 | 562 | } |
| 383 | 563 | |
| 384 | 564 | if (undefError) { |
| 385 | - statusEl.find('.text').html(__('Undefined error. Please try again.')); | |
| 565 | + statusEl.find('.text').html(MainWP.I18n.t('Undefined error. Please try again.')); | |
| 386 | 566 | } |
| 387 | - setTimeout(function () { | |
| 388 | - statusEl.fadeOut(); | |
| 389 | - }, 3000); | |
| 390 | 567 | |
| 568 | + if (!autoTriggerInstall || response.error || undefError) { | |
| 569 | + setTimeout(function () { | |
| 570 | + statusEl.fadeOut(); | |
| 571 | + if (isSuccess) { | |
| 572 | + jQuery('#mainwp-manage-license-buttons').hide(); | |
| 573 | + jQuery('#mainwp-manage-add-ons-buttons').show(); | |
| 574 | + mainwp_extensions_check_activate_button_state(); | |
| 575 | + mainwp_extensions_update_status_header(); | |
| 576 | + } | |
| 577 | + }, 3000); | |
| 578 | + } | |
| 579 | + | |
| 391 | 580 | }, 'json'); |
| 392 | 581 | return false; |
| 393 | 582 | } |
| 394 | 583 | |
| @@ -399,76 +588,14 @@ | ||
| 399 | 588 | let countSuccessActivation = 0; |
| 400 | 589 | |
| 401 | 590 | // Bulk grab API keys |
| 402 | 591 | jQuery(document).on('click', '#mainwp-extensions-grabkeys', function () { |
| 403 | - mainwp_extensions_grabkeys(false); | |
| 592 | + totalActivateThreads = jQuery('#mainwp-extensions-list .card[status="queue"]').length; | |
| 593 | + if (totalActivateThreads > 0) { | |
| 594 | + extensions_loop_next(); | |
| 595 | + } | |
| 404 | 596 | }); |
| 405 | 597 | |
| 406 | -function mainwp_extensions_grabkeys(retring) { | |
| 407 | - let grabingEl = jQuery("#mainwp-extensions-api-fields"); | |
| 408 | - let master_api_key = grabingEl.find('#mainwp_com_api_key').val(); | |
| 409 | - let statusEl = jQuery(".mainwp-extensions-api-loading"); | |
| 410 | - let data = mainwp_secure_data({ | |
| 411 | - action: 'mainwp_extension_testextensionapilogin', | |
| 412 | - master_api_key: master_api_key | |
| 413 | - }); | |
| 414 | - | |
| 415 | - if (master_api_key == '') { | |
| 416 | - statusEl.find('.text').html(__("Main API Key is required.")); | |
| 417 | - statusEl.addClass('yellow'); | |
| 418 | - statusEl.fadeOut(); | |
| 419 | - setTimeout(function () { | |
| 420 | - statusEl.fadeOut(); | |
| 421 | - }, 3000); | |
| 422 | - } else { | |
| 423 | - if (retring) { | |
| 424 | - statusEl.find('.text').html(__("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn(); | |
| 425 | - } else { | |
| 426 | - statusEl.removeClass('red'); | |
| 427 | - statusEl.removeClass('yellow'); | |
| 428 | - statusEl.removeClass('green'); | |
| 429 | - statusEl.find('.text').html(__('Validating. Please wait...')).show(); | |
| 430 | - } | |
| 431 | - statusEl.show(); | |
| 432 | - jQuery.post(ajaxurl, data, function (response) { | |
| 433 | - let undefError = false; | |
| 434 | - if (response) { | |
| 435 | - if (response.result == 'SUCCESS') { | |
| 436 | - statusEl.addClass('green'); | |
| 437 | - statusEl.find('.text').html('MainWP Main API Key is valid!').fadeIn(); | |
| 438 | - setTimeout(function () { | |
| 439 | - statusEl.fadeOut(); | |
| 440 | - }, 3000); | |
| 441 | - totalActivateThreads = jQuery('#mainwp-extensions-list .card[status="queue"]').length; | |
| 442 | - console.log(totalActivateThreads); | |
| 443 | - if (totalActivateThreads > 0) | |
| 444 | - extensions_loop_next(); | |
| 445 | - } else if (response.error) { | |
| 446 | - statusEl.addClass('red'); | |
| 447 | - statusEl.find('.text').html(response.error).fadeIn(); | |
| 448 | - } else if (response.retry_action && response.retry_action == 1) { | |
| 449 | - jQuery("#mainwp_api_sslVerifyCertificate").val(0); | |
| 450 | - mainwp_extensions_grabkeys(true); | |
| 451 | - return false; | |
| 452 | - } else { | |
| 453 | - undefError = true; | |
| 454 | - } | |
| 455 | - } else { | |
| 456 | - undefError = true; | |
| 457 | - } | |
| 458 | - if (undefError) { | |
| 459 | - statusEl.addClass('red'); | |
| 460 | - statusEl.find('.text').html(__('Undefined error. Please try again.')).fadeIn(); | |
| 461 | - } | |
| 462 | - | |
| 463 | - setTimeout(function () { | |
| 464 | - statusEl.fadeOut(); | |
| 465 | - }, 3000); | |
| 466 | - }, 'json'); | |
| 467 | - } | |
| 468 | - return false; | |
| 469 | -} | |
| 470 | - | |
| 471 | 598 | let extensions_loop_next = function () { |
| 472 | 599 | let extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first'); |
| 473 | 600 | while (extToActivate.length > 0 && currentActivateThreads < maxActivateThreads) { // NOSONAR - variable modified outside the function. |
| 474 | 601 | extensions_activate_next(extToActivate, true); |
| @@ -473,12 +600,16 @@ | ||
| 473 | 600 | while (extToActivate.length > 0 && currentActivateThreads < maxActivateThreads) { // NOSONAR - variable modified outside the function. |
| 474 | 601 | extensions_activate_next(extToActivate, true); |
| 475 | 602 | extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first'); |
| 476 | 603 | } |
| 477 | - if ((finishedActivateThreads == totalActivateThreads) && (countSuccessActivation == totalActivateThreads)) { | |
| 478 | - setTimeout(function () { | |
| 479 | - location.href = 'admin.php?page=Extensions'; | |
| 480 | - }, 2000); | |
| 604 | + if (finishedActivateThreads == totalActivateThreads) { | |
| 605 | + if (countSuccessActivation == totalActivateThreads) { | |
| 606 | + setTimeout(function () { | |
| 607 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 608 | + }, 2000); | |
| 609 | + } else { | |
| 610 | + mainwp_extensions_update_status_header(); | |
| 611 | + } | |
| 481 | 612 | } |
| 482 | 613 | }; |
| 483 | 614 | |
| 484 | 615 | let extensions_activate_next = function (pObj, bulkAct) { |
| @@ -483,14 +614,13 @@ | ||
| 483 | 614 | |
| 484 | 615 | let extensions_activate_next = function (pObj, bulkAct) { |
| 485 | 616 | pObj.attr("status", "running"); |
| 486 | 617 | |
| 487 | - let grabingEl = jQuery("#mainwp-extensions-api-fields"); | |
| 488 | 618 | let apiEl = pObj; |
| 489 | 619 | let statusEl = apiEl.find(".activate-api-status"); |
| 490 | 620 | let loadingEl = apiEl.find(".api-feedback"); |
| 491 | 621 | |
| 492 | - let master_api_key = grabingEl.find('#mainwp_com_api_key').val(); | |
| 622 | + let master_api_key = jQuery('#mainwp_com_api_key').val() || ''; | |
| 493 | 623 | |
| 494 | 624 | |
| 495 | 625 | let extensionSlug = apiEl.attr('extension-slug'); |
| 496 | 626 | let data = mainwp_secure_data({ |
| @@ -501,16 +631,14 @@ | ||
| 501 | 631 | |
| 502 | 632 | currentActivateThreads++; |
| 503 | 633 | |
| 504 | 634 | loadingEl.show(); |
| 505 | - loadingEl.find('.message').removeClass('red green'); | |
| 506 | - loadingEl.find('.message').html('<i class="notched circle loading icon"></i>' + __('Activating...')); | |
| 635 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Activating license...')); | |
| 507 | 636 | |
| 508 | 637 | if (apiEl.attr('license-status') == 'activated') { |
| 509 | 638 | finishedActivateThreads++; |
| 510 | 639 | currentActivateThreads--; |
| 511 | - loadingEl.find('.message').addClass('green'); | |
| 512 | - loadingEl.find('.message').html(__('Already activated.')); | |
| 640 | + loadingEl.hide(); | |
| 513 | 641 | countSuccessActivation++; |
| 514 | 642 | if (bulkAct) { |
| 515 | 643 | extensions_loop_next(); |
| 516 | 644 | } |
| @@ -523,27 +651,33 @@ | ||
| 523 | 651 | |
| 524 | 652 | if (response) { |
| 525 | 653 | if (response.result == 'SUCCESS') { |
| 526 | 654 | countSuccessActivation++; |
| 527 | - loadingEl.find('.message').addClass('green'); | |
| 528 | - loadingEl.find('.message').html(__('License activated.')); | |
| 529 | - statusEl.html('<i class="green check icon"></i> License'); | |
| 530 | - apiEl.find('.mainwp-extensions-deactivate-chkbox').attr('checked', false); | |
| 655 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('License activated')); | |
| 656 | + statusEl.html('<i class="green key icon"></i> Licensed'); | |
| 657 | + apiEl.attr('license-status', 'activated'); | |
| 658 | + loadingEl.hide(); | |
| 531 | 659 | if (!bulkAct) { |
| 532 | 660 | setTimeout(function () { |
| 533 | - location.href = 'admin.php?page=Extensions'; | |
| 661 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 534 | 662 | }, 2000); |
| 535 | 663 | } |
| 536 | 664 | } else if (response.error) { |
| 537 | - loadingEl.find('.message').addClass('red'); | |
| 538 | - loadingEl.find('.message').html(response.error); | |
| 665 | + loadingEl.find('.ui.text.loader').html(response.error); | |
| 666 | + setTimeout(function () { | |
| 667 | + loadingEl.hide(); | |
| 668 | + }, 3000); | |
| 539 | 669 | } else { |
| 540 | - loadingEl.find('.message').addClass('red'); | |
| 541 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 670 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); | |
| 671 | + setTimeout(function () { | |
| 672 | + loadingEl.hide(); | |
| 673 | + }, 3000); | |
| 542 | 674 | } |
| 543 | 675 | } else { |
| 544 | - loadingEl.find('.message').addClass('red'); | |
| 545 | - loadingEl.find('.message').html(__('Undefined error. ')); | |
| 676 | + loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); | |
| 677 | + setTimeout(function () { | |
| 678 | + loadingEl.hide(); | |
| 679 | + }, 3000); | |
| 546 | 680 | } |
| 547 | 681 | if (bulkAct) { |
| 548 | 682 | extensions_loop_next(); |
| 549 | 683 | } |
| @@ -549,22 +683,20 @@ | ||
| 549 | 683 | } |
| 550 | 684 | }, 'json'); |
| 551 | 685 | }; |
| 552 | 686 | |
| 553 | -jQuery(document).on('click', '#mainwp-extensions-bulkinstall', function () { | |
| 554 | - let grabingEl = jQuery("#mainwp-extensions-api-fields"); | |
| 555 | - let api_key = grabingEl.find('#mainwp_com_api_key').val().trim(); | |
| 687 | +jQuery(document).on('click', '#mainwp-extensions-bulkinstall, #mainwp-extensions-message-bulkinstall', function () { | |
| 688 | + let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); | |
| 556 | 689 | if (api_key == '') { |
| 557 | 690 | mainwp_extension_grab_org_extensions(); |
| 558 | 691 | } else { |
| 559 | - mainwp_extension_grab_purchased(this, false); | |
| 692 | + mainwp_extension_grab_purchased(false); | |
| 560 | 693 | } |
| 561 | 694 | }) |
| 562 | 695 | |
| 563 | -let mainwp_extension_grab_purchased = function (pObj, retring) { | |
| 696 | +let mainwp_extension_grab_purchased = function (retring) { | |
| 564 | 697 | |
| 565 | - let grabingEl = jQuery("#mainwp-extensions-api-fields"); | |
| 566 | - let api_key = grabingEl.find('#mainwp_com_api_key').val().trim(); | |
| 698 | + let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); | |
| 567 | 699 | |
| 568 | 700 | let statusEl = jQuery(".mainwp-extensions-api-loading"); |
| 569 | 701 | let data = mainwp_secure_data({ |
| 570 | 702 | action: 'mainwp_extension_getpurchased', |
| @@ -572,21 +704,21 @@ | ||
| 572 | 704 | }); |
| 573 | 705 | |
| 574 | 706 | |
| 575 | 707 | if (api_key == '') { |
| 576 | - statusEl.find('.text').html(__("Main API Key is required.")); | |
| 708 | + statusEl.find('.text').html(MainWP.I18n.t("Main API Key is required.")); | |
| 577 | 709 | statusEl.show(); |
| 578 | 710 | setTimeout(function () { |
| 579 | 711 | statusEl.fadeOut(); |
| 580 | 712 | }, 3000); |
| 581 | 713 | } else if (retring) { |
| 582 | - statusEl.find('.text').html(__("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")); | |
| 714 | + statusEl.find('.text').html(MainWP.I18n.t("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")); | |
| 583 | 715 | setTimeout(function () { |
| 584 | 716 | statusEl.fadeOut(); |
| 585 | 717 | }, 3000); |
| 586 | 718 | } else { |
| 587 | 719 | statusEl.show(); |
| 588 | - statusEl.find('.text').html(__('Loading extensions info...')); | |
| 720 | + statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...')); | |
| 589 | 721 | jQuery.post(ajaxurl, data, function (response) { |
| 590 | 722 | let undefError = false; |
| 591 | 723 | if (response) { |
| 592 | 724 | if (response.result == 'SUCCESS') { |
| @@ -594,9 +726,9 @@ | ||
| 594 | 726 | jQuery('#mainwp-get-purchased-extensions-modal').modal({ |
| 595 | 727 | allowMultiple: true, |
| 596 | 728 | closable: false, |
| 597 | 729 | onHide: function () { |
| 598 | - location.href = 'admin.php?page=Extensions'; | |
| 730 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 599 | 731 | } |
| 600 | 732 | }).modal('show'); |
| 601 | 733 | jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data); |
| 602 | 734 | if (jQuery('#extension_install_ext_slug').length > 0) { |
| @@ -606,9 +738,9 @@ | ||
| 606 | 738 | statusEl.find('.text').html(response.error); |
| 607 | 739 | } else if (response.retry_action && response.retry_action == 1) { |
| 608 | 740 | jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 609 | 741 | statusEl.fadeOut(); |
| 610 | - mainwp_extension_grab_purchased(pObj, true); | |
| 742 | + mainwp_extension_grab_purchased(true); | |
| 611 | 743 | return false; |
| 612 | 744 | } else { |
| 613 | 745 | undefError = true; |
| 614 | 746 | } |
| @@ -615,9 +747,9 @@ | ||
| 615 | 747 | } else { |
| 616 | 748 | undefError = true; |
| 617 | 749 | } |
| 618 | 750 | if (undefError) { |
| 619 | - statusEl.find('.text').html(__('Undefined error occurred. Please try again.')); | |
| 751 | + statusEl.find('.text').html(MainWP.I18n.t('Undefined error occurred. Please try again.')); | |
| 620 | 752 | } |
| 621 | 753 | setTimeout(function () { |
| 622 | 754 | statusEl.fadeOut(); |
| 623 | 755 | }, 3000); |
| @@ -627,9 +759,8 @@ | ||
| 627 | 759 | } |
| 628 | 760 | |
| 629 | 761 | let mainwp_extension_select_to_install = function () { |
| 630 | 762 | let inst_ext = jQuery('.item.extension[slug="' + jQuery('#extension_install_ext_slug').val() + '"]'); |
| 631 | - console.log(inst_ext); | |
| 632 | 763 | if (jQuery(inst_ext).length > 0) { |
| 633 | 764 | jQuery('mainwp-installing-extensions .ui.tab').removeClass('active'); |
| 634 | 765 | let curtab = jQuery(inst_ext[0]).closest('.ui.tab').attr('data-tab'); |
| 635 | 766 | jQuery('#mainwp-install-extensions-menu .item[data-tab=' + curtab + ']').trigger('click'); |
| @@ -649,9 +780,9 @@ | ||
| 649 | 780 | |
| 650 | 781 | statusEl.removeClass('green'); |
| 651 | 782 | statusEl.removeClass('yellow'); |
| 652 | 783 | statusEl.show(); |
| 653 | - statusEl.find('.text').html(__('Running. Please wait...')); | |
| 784 | + statusEl.find('.text').html(MainWP.I18n.t('Running. Please wait...')); | |
| 654 | 785 | jQuery.post(ajaxurl, data, function (response) { |
| 655 | 786 | let undefError = false; |
| 656 | 787 | if (response) { |
| 657 | 788 | if (response.result == 'SUCCESS') { |
| @@ -658,9 +789,9 @@ | ||
| 658 | 789 | jQuery('#mainwp-get-purchased-extensions-modal').modal({ |
| 659 | 790 | allowMultiple: true, |
| 660 | 791 | closable: false, |
| 661 | 792 | onHide: function () { |
| 662 | - location.href = 'admin.php?page=Extensions'; | |
| 793 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 663 | 794 | } |
| 664 | 795 | }).modal('show'); |
| 665 | 796 | jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data); |
| 666 | 797 | if (jQuery('#extension_install_ext_slug').length > 0) { |
| @@ -678,9 +809,9 @@ | ||
| 678 | 809 | } |
| 679 | 810 | |
| 680 | 811 | if (undefError) { |
| 681 | 812 | statusEl.addClass('red'); |
| 682 | - statusEl.find('.text').html(__('Undefined error. Please try again.')).fadeIn(); | |
| 813 | + statusEl.find('.text').html(MainWP.I18n.t('Undefined error. Please try again.')).fadeIn(); | |
| 683 | 814 | } |
| 684 | 815 | setTimeout(function () { |
| 685 | 816 | statusEl.fadeOut(); |
| 686 | 817 | }, 3000); |
| @@ -704,9 +835,9 @@ | ||
| 704 | 835 | let mainwp_extension_bulk_install = function () { |
| 705 | 836 | if (bulkExtensionsRunning) |
| 706 | 837 | return; |
| 707 | 838 | |
| 708 | - jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:not(:checked)').closest('.extension-to-install').find('.installing-extension[status="queue"]').html('<span data-tooltip="Skipped" data-position="left center" data-inverted=""><i class="stop circle outline grey icon"></i></span>'); | |
| 839 | + jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:not(:checked)').closest('.extension-to-install').find('.installing-extension[status="queue"]').html('<span data-tooltip="Skipped" data-position="left center" data-inverted=""><i class="ban grey icon"></i></span>'); | |
| 709 | 840 | |
| 710 | 841 | bulkExtensionsTotal = jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked').length; |
| 711 | 842 | |
| 712 | 843 | if (bulkExtensionsTotal == 0) |
| @@ -711,9 +842,9 @@ | ||
| 711 | 842 | |
| 712 | 843 | if (bulkExtensionsTotal == 0) |
| 713 | 844 | return false; |
| 714 | 845 | |
| 715 | - jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked').closest('.extension-to-install').find('.installing-extension[status="queue"]').html('<i class="clock outline icon"></i> ' + __('Queued')); | |
| 846 | + jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked').closest('.extension-to-install').find('.installing-extension[status="queue"]').html('<i class="clock outline icon"></i> ' + MainWP.I18n.t('Queued')); | |
| 716 | 847 | |
| 717 | 848 | mainwp_extension_bulk_install_next(); |
| 718 | 849 | } |
| 719 | 850 | |
| @@ -733,9 +864,9 @@ | ||
| 733 | 864 | bulkExtensionsCurrentThreads++; |
| 734 | 865 | |
| 735 | 866 | let statusEl = pExtToInstall.find('.installing-extension'); |
| 736 | 867 | |
| 737 | - statusEl.html('<span data-tooltip="Installing extension. Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); | |
| 868 | + statusEl.html('<span data-tooltip="Installing add-on. Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); | |
| 738 | 869 | |
| 739 | 870 | let data = mainwp_secure_data({ |
| 740 | 871 | action: 'mainwp_extension_downloadandinstall', |
| 741 | 872 | download_link: pExtToInstall.attr('download-link'), |
| @@ -760,19 +891,17 @@ | ||
| 760 | 891 | let response_json = matches[1]; |
| 761 | 892 | response = JSON.parse(response_json); |
| 762 | 893 | } |
| 763 | 894 | |
| 764 | - if (response != '') { | |
| 765 | - if (response.result == 'SUCCESS') { | |
| 766 | - statusEl.html('<span data-tooltip="' + response.output + '" data-inverted="" data-position="left center"><i class="check green icon"></i></span>'); | |
| 767 | - jQuery('.mainwp-installing-extensions').append('<span class="extension-installed-success" slug="' + response.slug + '"></span>') | |
| 768 | - } else if (response.error) { | |
| 769 | - statusEl.html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); | |
| 770 | - } else { | |
| 771 | - statusEl.html('<span data-tooltip="Undefined error occured. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); | |
| 772 | - } | |
| 895 | + if (response == '') { | |
| 896 | + statusEl.html('<span data-tooltip="Undefined error occurred. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); | |
| 897 | + } else if (response.result == 'SUCCESS') { | |
| 898 | + statusEl.html('<span data-tooltip="' + response.output + '" data-inverted="" data-position="left center"><i class="check green icon"></i></span>'); | |
| 899 | + jQuery('.mainwp-installing-extensions').append('<span class="extension-installed-success" slug="' + response.slug + '"></span>') | |
| 900 | + } else if (response.error) { | |
| 901 | + statusEl.html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); | |
| 773 | 902 | } else { |
| 774 | - statusEl.html('<span data-tooltip="Undefined error occured. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); | |
| 903 | + statusEl.html('<span data-tooltip="Undefined error occurred. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); | |
| 775 | 904 | } |
| 776 | 905 | |
| 777 | 906 | mainwp_extension_bulk_install_next(); |
| 778 | 907 | } |
| @@ -800,14 +929,14 @@ | ||
| 800 | 929 | }); |
| 801 | 930 | |
| 802 | 931 | let statusEl = jQuery('#mainwp-bulk-activating-extensions-status'); |
| 803 | 932 | |
| 804 | - statusEl.html('<i class="notched circle loading icon"></i>' + __('Activating extensions. Please wait...')).show(); | |
| 933 | + statusEl.html('<i class="notched circle loading icon"></i>' + MainWP.I18n.t('Activating add-ons. Please wait...')).show(); | |
| 805 | 934 | jQuery.post(ajaxurl, data, function (response) { |
| 806 | 935 | statusEl.html(''); |
| 807 | 936 | if (response == 'SUCCESS') { |
| 808 | 937 | statusEl.addClass('green'); |
| 809 | - statusEl.html(__('Extensions have been activated successfully!')); | |
| 938 | + statusEl.html(MainWP.I18n.t('Add-ons have been activated successfully!')); | |
| 810 | 939 | statusEl.fadeOut(3000); |
| 811 | 940 | } |
| 812 | 941 | mainwp_extension_bulk_install_done(); |
| 813 | 942 | }); |
| @@ -818,12 +947,12 @@ | ||
| 818 | 947 | |
| 819 | 948 | let statusEl = jQuery('#mainwp-bulk-activating-extensions-status'); |
| 820 | 949 | |
| 821 | 950 | statusEl.addClass('green'); |
| 822 | - statusEl.html(__("Installation completed successfully. Page will reload automatically in 3 seconds.")).show(); | |
| 951 | + statusEl.html(MainWP.I18n.t("Installation completed successfully. Page will reload automatically in 3 seconds.")).show(); | |
| 823 | 952 | if (jQuery('.extension-installed-success').length == bulkExtensionsFinished) { |
| 824 | 953 | setTimeout(function () { |
| 825 | - location.href = 'admin.php?page=Extensions'; | |
| 954 | + mainwp_forceReload('admin.php?page=Extensions'); | |
| 826 | 955 | }, 3000); |
| 827 | 956 | } |
| 828 | 957 | } |
| 829 | 958 | |
| @@ -863,9 +992,9 @@ | ||
| 863 | 992 | } |
| 864 | 993 | |
| 865 | 994 | if (undefError) { |
| 866 | 995 | statusEl.css('color', 'red'); |
| 867 | - statusEl.html('<i class="exclamation circle icon"></i> Undefined error!').fadeIn(); | |
| 996 | + statusEl.html('<i class="exclamation circle icon"></i> Undefined error').fadeIn(); | |
| 868 | 997 | } |
| 869 | 998 | }, 'json'); |
| 870 | 999 | return false; |
| 871 | 1000 | }); |