PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.3 6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 All 157 releases
← All changes | assets/js/mainwp-extensions.js +485 -359 5.0 → 6.2.1 View file →
@@ -1,13 +1,146 @@
1 1 /* eslint complexity: ["error", 100] */
2 2 jQuery(document).on('click', '.item.extension-inactive', function () {
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 - var extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug');
9 - var data = mainwp_secure_data({
141 + let extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug');
142 + let data = mainwp_secure_data({
10 143 action: 'mainwp_extension_add_menu',
11 144 slug: extensionSlug
12 145 });
13 146
@@ -22,10 +155,10 @@
22 155 return false;
23 156 });
24 157
25 158 jQuery(document).on('click', '.mainwp-extensions-remove-menu', function () {
26 - var extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug');
27 - var data = mainwp_secure_data({
159 + let extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug');
160 + let data = mainwp_secure_data({
28 161 action: 'mainwp_extension_remove_menu',
29 162 slug: extensionSlug
30 163 });
31 164
@@ -36,11 +169,11 @@
36 169
37 170 return false;
38 171 });
39 172
40 -jQuery(document).ready(function () {
173 +jQuery(function () { // NOSONAR - levels deep ok.
41 174 jQuery(document).on('click', '.mainwp-manage-extension-license', function () {
42 - var currentCard = jQuery(this).closest(".card");
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') {
45 178 extensions_activate_next(currentCard, false);
46 179 }
@@ -47,20 +180,20 @@
47 180 return false;
48 181 });
49 182
50 183 jQuery(document).on('click', '.extension-privacy-info-link', function () {
51 - var slug = jQuery(this).attr('base-slug');
52 - var title = '';
184 + let slug = jQuery(this).attr('base-slug');
185 + let title = '';
53 186 if (jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").length > 0) {
54 187 title = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('extension_title');
55 188 } else {
56 189 title = jQuery(this).closest('.ui.card').attr('extension-title');
57 190 }
58 - var privacy = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('privacy');
59 - var integration = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration');
60 - var integration_url = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_url');
61 - var integration_owner = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_owner');
62 - var integration_owner_pp = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_owner_pp');
191 + let privacy = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('privacy');
192 + let integration = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration');
193 + let integration_url = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_url');
194 + let integration_owner = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_owner');
195 + let integration_owner_pp = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_owner_pp');
63 196
64 197 jQuery('#mainwp-privacy-info-modal').modal({
65 198 allowMultiple: true,
66 199 onShow: function () {
@@ -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>.');
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,23 +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>');
267 + } else if (slug == 'mainwp-page-speed-extension') {
268 + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party Plugin.</strong>');
269 + jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>');
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>');
271 + jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>');
272 + jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://mattkeys.me/" target="_blank">Matt Keys</a>');
134 273 } else {
135 - if (slug == 'mainwp-page-speed-extension') {
136 - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Extension integrates with a 3rd party Plugin.</strong>');
137 - jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>');
138 - 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>');
139 - jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>');
140 - jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://mattkeys.me/" target="_blank">Matt Keys</a>');
141 - } else {
142 - jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>This extension is not developed by MainWP. Privacy info is not available.</strong>');
143 - }
274 + jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>This add-on is not developed by MainWP. Privacy info is not available.</strong>');
144 275 }
145 276 },
146 277 onHide: function () {
147 278 jQuery('#mainwp-privacy-info-modal').find('.header').html('');
@@ -151,65 +282,90 @@
151 282
152 283 return false;
153 284 });
154 285
155 - jQuery(document).on('click', '.extension-the-plugin-action', function () {
156 - var parent = jQuery(this).closest(".card");
157 - var slug = jQuery(parent).attr('extension-slug');
158 - var loadingEl = parent.find(".action-feedback");
159 - var whatAct = jQuery(this).attr("plugin-action");
286 + jQuery(document).on('click', '.extension-the-plugin-action', function () { // eslint-disable-line unicorn/no-nested-ternary
287 + let parent = jQuery(this).closest(".card");
288 + let slug = jQuery(parent).attr('extension-slug');
289 + let loadingEl = parent.find(".action-feedback");
290 + let whatAct = jQuery(this).attr("plugin-action");
160 291
161 - loadingEl.show();
162 - loadingEl.find('.message').removeClass('red green');
292 + let _callback = function () {
293 + let $btn = jQuery(this); // ✅ store correct context
163 294
164 - var msg = __('Deactivating...');
165 - if (whatAct == 'active') {
166 - msg = __('Activating...');
167 - } else if (whatAct == 'remove') {
168 - msg = __('Removing...');
169 - }
295 + loadingEl.show();
170 296
171 - 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 + }
172 303
173 - var data = mainwp_secure_data({
174 - action: 'mainwp_extension_plugin_action',
175 - slug: slug,
176 - what: whatAct,
177 - });
304 + loadingEl.find('.ui.text.loader').html(msg);
178 305
179 - jQuery(this).attr('disabled', true);
180 - jQuery.post(ajaxurl, data, function (response) {
181 - jQuery(this).attr('disabled', false);
182 - var success = false;
183 - if (response) {
184 - if (response.result == 'SUCCESS') {
185 - loadingEl.find('.message').addClass('green');
186 - msg = __('Extension deactivated.');
187 - if (whatAct == 'active') {
188 - msg = __('Extension activated.');
189 - } else if (whatAct == 'remove') {
190 - msg = __('Extension removed.');
191 - }
192 - loadingEl.find('.message').html(msg);
193 - success = true;
194 - } else if (response.error) {
195 - loadingEl.find('.message').addClass('red');
196 - loadingEl.find('.message').html(response.error);
197 - } else {
198 - loadingEl.find('.message').addClass('red');
199 - 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;
200 318 }
201 - } else {
202 - loadingEl.find('.message').addClass('red');
203 - 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'));
204 331 }
205 332
206 - if (success) {
207 - setTimeout(function () {
208 - 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');
209 346 }, 2000);
210 347 }
211 - }, '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 + }
212 368 return false;
213 369 });
214 370 });
215 371
@@ -217,32 +373,32 @@
217 373 mainwp_extensions_activate(this, false);
218 374 });
219 375
220 376 function mainwp_extensions_activate(pObj, retring) {
221 - var apiEl = jQuery(pObj).closest(".card");
222 - var statusEl = apiEl.find(".activate-api-status");
223 - var loadingEl = apiEl.find(".api-feedback");
377 + let apiEl = jQuery(pObj).closest(".card");
378 + let statusEl = apiEl.find(".activate-api-status");
379 + let loadingEl = apiEl.find(".api-feedback");
224 380
225 381 loadingEl.hide();
226 382
227 383 if (jQuery(pObj).attr('license-status') == 'activated') {
228 - loadingEl.show();
229 - loadingEl.find('.message').html(__('Already activated.'));
230 384 return;
231 385 }
232 386
233 - if (retring == true) {
387 + let data = false;
388 +
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 - var extensionSlug = jQuery(apiEl).attr('extension-slug');
238 - var key = apiEl.find('input[type="text"].extension-api-key').val();
239 - var email = apiEl.find('input[type="text"].extension-api-email').val();
393 + let extensionSlug = jQuery(apiEl).attr('extension-slug');
394 + let key = apiEl.find('input[type="text"].extension-api-key').val();
395 + let email = apiEl.find('input[type="text"].extension-api-email').val();
240 396
241 397 if (key == '')
242 398 return;
243 399
244 - var data = mainwp_secure_data({
400 + data = mainwp_secure_data({
245 401 action: 'mainwp_extension_api_activate',
246 402 slug: extensionSlug,
247 403 key: key,
248 404 email: email
@@ -249,40 +405,41 @@
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 - var success = false;
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,21 +444,26 @@
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 - var apiEl = jQuery(this).closest(".card");
293 - var statusEl = apiEl.find(".activate-api-status");
294 - var loadingEl = apiEl.find(".api-feedback");
455 + let apiEl = jQuery(this).closest(".card");
456 + let statusEl = apiEl.find(".activate-api-status");
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 false;
298 -
299 460 loadingEl.hide();
461 + formEl.hide();
300 462
301 - var extensionSlug = jQuery(apiEl).attr('extension-slug');
302 - var extensionApiKey = jQuery(apiEl).find('.extension-api-key').val();
303 - var data = mainwp_secure_data({
463 + let extensionSlug = jQuery(apiEl).attr('extension-slug');
464 + let extensionApiKey = jQuery(apiEl).find('.extension-api-key').val();
465 + let data = mainwp_secure_data({
304 466 action: 'mainwp_extension_deactivate',
305 467 slug: extensionSlug,
306 468 api_key: extensionApiKey
307 469 });
@@ -306,76 +468,92 @@
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');
320 - success = true;
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');
321 481 } else if (response.error) {
322 - loadingEl.find('.message').addClass('red');
323 - loadingEl.find('.message').html(response.error);
482 + loadingEl.find('.ui.text.loader').html(response.error);
483 + setTimeout(function () {
484 + loadingEl.hide();
485 + }, 3000);
324 486 } else {
325 - loadingEl.find('.message').addClass('red');
326 - 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);
327 491 }
328 492 } else {
329 - loadingEl.find('.message').addClass('red');
330 - 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);
331 497 }
332 498
333 499 setTimeout(function () {
334 - location.href = 'admin.php?page=Extensions';
500 + mainwp_forceReload('admin.php?page=Extensions');
335 501 }, 2000);
336 502 }, 'json');
337 - return false;
338 503 });
339 504
340 505
341 506 // Verify mainwp.com login credentials
342 507 jQuery(document).on('click', '#mainwp-extensions-savelogin', function () {
343 - mainwp_extensions_savelogin(this, false);
508 + let autoTriggerInstall = jQuery(this).attr('data-context') === 'intro-notice';
509 + mainwp_extensions_savelogin(false, autoTriggerInstall);
344 510 });
345 511
346 -function mainwp_extensions_savelogin(pObj, retring) {
347 - var grabingEl = jQuery("#mainwp-extensions-api-fields");
348 - var api_key = grabingEl.find('#mainwp_com_api_key').val();
349 - var statusEl = jQuery(".mainwp-extensions-api-loading");
350 - var data = mainwp_secure_data({
512 +function mainwp_extensions_savelogin(retring, autoTriggerInstall) {
513 + let api_key = jQuery('#mainwp_com_api_key').val() || '';
514 + let statusEl = jQuery(".mainwp-extensions-api-loading");
515 + let data = mainwp_secure_data({
351 516 action: 'mainwp_extension_saveextensionapilogin',
352 517 api_key: api_key,
353 518 saveLogin: jQuery('#extensions_api_savemylogin_chk').is(':checked') ? 1 : 0
354 519 });
355 520
356 - if ( retring == true ) {
357 - statusEl.find( '.text' ).html(__("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn();
521 + if (retring) {
522 + statusEl.find('.text').html(MainWP.I18n.t("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn();
358 523 } else {
359 -
360 - statusEl.find( '.text' ).html( __( 'Validating...' ) );
524 +
525 + statusEl.find('.text').html(MainWP.I18n.t('Validating...'));
361 526 }
362 527
363 528 statusEl.show();
364 529
365 - jQuery.post(ajaxurl, data, function (response) {
366 - var undefError = false;
530 + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - Complexity.
531 + let undefError = false;
532 + let isSuccess = false;
367 533 if (response) {
368 534 if (response.saved) {
369 - 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 + }
370 542 } else if (response.result == 'SUCCESS') {
371 - statusEl.find( '.text' ).html('API license key verification successful!');
372 - } else if ( response.error ) {
373 - statusEl.find( '.text' ).html(response.error);
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 + }
550 + } else if (response.error) {
551 + statusEl.find('.text').html(response.error);
374 552 } else if (response.retry_action && response.retry_action == 1) {
375 553 jQuery("#mainwp_api_sslVerifyCertificate").val(0);
376 554 statusEl.fadeOut();
377 - mainwp_extensions_savelogin(pObj, true);
555 + mainwp_extensions_savelogin(true, autoTriggerInstall);
378 556 return false;
379 557 } else {
380 558 undefError = true;
381 559 }
@@ -383,118 +561,70 @@
383 561 undefError = true;
384 562 }
385 563
386 564 if (undefError) {
387 - statusEl.find( '.text' ).html( __( 'Undefined error. Please try again.' ) );
565 + statusEl.find('.text').html(MainWP.I18n.t('Undefined error. Please try again.'));
388 566 }
389 - setTimeout( function () {
390 - statusEl.fadeOut();
391 - }, 3000 );
392 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 +
393 580 }, 'json');
394 581 return false;
395 582 }
396 583
397 -var maxActivateThreads = 8;
398 -var totalActivateThreads = 0;
399 -var currentActivateThreads = 0;
400 -var finishedActivateThreads = 0;
401 -var countSuccessActivation = 0;
584 +let maxActivateThreads = 8;
585 +let totalActivateThreads = 0;
586 +let currentActivateThreads = 0;
587 +let finishedActivateThreads = 0;
588 +let countSuccessActivation = 0;
402 589
403 590 // Bulk grab API keys
404 591 jQuery(document).on('click', '#mainwp-extensions-grabkeys', function () {
405 - mainwp_extensions_grabkeys(false);
592 + totalActivateThreads = jQuery('#mainwp-extensions-list .card[status="queue"]').length;
593 + if (totalActivateThreads > 0) {
594 + extensions_loop_next();
595 + }
406 596 });
407 597
408 -function mainwp_extensions_grabkeys(retring) {
409 - var grabingEl = jQuery("#mainwp-extensions-api-fields");
410 - var master_api_key = grabingEl.find('#mainwp_com_api_key').val();
411 - var statusEl = jQuery(".mainwp-extensions-api-loading");
412 - var data = mainwp_secure_data({
413 - action: 'mainwp_extension_testextensionapilogin',
414 - master_api_key: master_api_key
415 - });
416 -
417 - if (master_api_key == '') {
418 - statusEl.find('.text').html(__("Main API Key is required."));
419 - statusEl.addClass('yellow');
420 - statusEl.fadeOut();
421 - setTimeout(function () {
422 - statusEl.fadeOut();
423 - }, 3000);
424 - } else {
425 - if (retring == true) {
426 - statusEl.find('.text').html(__("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn();
598 +let extensions_loop_next = function () {
599 + let extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first');
600 + while (extToActivate.length > 0 && currentActivateThreads < maxActivateThreads) { // NOSONAR - variable modified outside the function.
601 + extensions_activate_next(extToActivate, true);
602 + extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first');
603 + }
604 + if (finishedActivateThreads == totalActivateThreads) {
605 + if (countSuccessActivation == totalActivateThreads) {
606 + setTimeout(function () {
607 + mainwp_forceReload('admin.php?page=Extensions');
608 + }, 2000);
427 609 } else {
428 - statusEl.removeClass('red');
429 - statusEl.removeClass('yellow');
430 - statusEl.removeClass('green');
431 - statusEl.find('.text').html( __('Validating. Please wait...')).show();
610 + mainwp_extensions_update_status_header();
432 611 }
433 - statusEl.show();
434 - jQuery.post(ajaxurl, data, function (response) {
435 - var undefError = false;
436 - if (response) {
437 - if (response.result == 'SUCCESS') {
438 - statusEl.addClass('green');
439 - statusEl.find('.text').html('MainWP Main API Key is valid!').fadeIn();
440 - setTimeout(function () {
441 - statusEl.fadeOut();
442 - }, 3000);
443 - totalActivateThreads = jQuery('#mainwp-extensions-list .card[status="queue"]').length;
444 - console.log(totalActivateThreads);
445 - if (totalActivateThreads > 0)
446 - extensions_loop_next();
447 - } else if (response.error) {
448 - statusEl.addClass('red');
449 - statusEl.find('.text').html(response.error).fadeIn();
450 - } else if (response.retry_action && response.retry_action == 1) {
451 - jQuery("#mainwp_api_sslVerifyCertificate").val(0);
452 - mainwp_extensions_grabkeys(true);
453 - return false;
454 - } else {
455 - undefError = true;
456 - }
457 - } else {
458 - undefError = true;
459 - }
460 - if (undefError) {
461 - statusEl.addClass('red');
462 - statusEl.find('.text').html(__('Undefined error. Please try again.')).fadeIn();
463 - }
464 -
465 - setTimeout(function () {
466 - statusEl.fadeOut();
467 - }, 3000);
468 - }, 'json');
469 - }
470 - return false;
471 -}
472 -
473 -extensions_loop_next = function () {
474 - while ((extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first')) && (extToActivate.length > 0) && (currentActivateThreads < maxActivateThreads)) {
475 - extensions_activate_next(extToActivate, true);
476 612 }
477 - if ((finishedActivateThreads == totalActivateThreads) && (countSuccessActivation == totalActivateThreads)) {
478 - setTimeout(function () {
479 - location.href = 'admin.php?page=Extensions';
480 - }, 2000);
481 - }
482 613 };
483 614
484 -extensions_activate_next = function (pObj, bulkAct) {
615 +let extensions_activate_next = function (pObj, bulkAct) {
616 + pObj.attr("status", "running");
485 617
486 - var grabingEl = jQuery("#mainwp-extensions-api-fields");
487 - var apiEl = pObj;
488 - var statusEl = apiEl.find(".activate-api-status");
489 - var loadingEl = apiEl.find(".api-feedback");
618 + let apiEl = pObj;
619 + let statusEl = apiEl.find(".activate-api-status");
620 + let loadingEl = apiEl.find(".api-feedback");
490 621
491 - var master_api_key = grabingEl.find('#mainwp_com_api_key').val();
622 + let master_api_key = jQuery('#mainwp_com_api_key').val() || '';
492 623
493 - apiEl.attr("status", "running");
494 624
495 - var extensionSlug = apiEl.attr('extension-slug');
496 - var data = mainwp_secure_data({
625 + let extensionSlug = apiEl.attr('extension-slug');
626 + let data = mainwp_secure_data({
497 627 action: 'mainwp_extension_grabapikey',
498 628 master_api_key: master_api_key,
499 629 slug: extensionSlug
500 630 });
@@ -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,94 +683,89 @@
549 683 }
550 684 }, 'json');
551 685 };
552 686
553 -jQuery(document).on('click', '#mainwp-extensions-bulkinstall', function () {
554 - var grabingEl = jQuery("#mainwp-extensions-api-fields");
555 - var 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 - mainwp_extension_grab_org_extensions(this);
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 -mainwp_extension_grab_purchased = function (pObj, retring) {
696 +let mainwp_extension_grab_purchased = function (retring) {
564 697
565 - var grabingEl = jQuery("#mainwp-extensions-api-fields");
566 - var api_key = grabingEl.find('#mainwp_com_api_key').val().trim();
698 + let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim();
567 699
568 - var statusEl = jQuery(".mainwp-extensions-api-loading");
569 - var data = mainwp_secure_data({
700 + let statusEl = jQuery(".mainwp-extensions-api-loading");
701 + let data = mainwp_secure_data({
570 702 action: 'mainwp_extension_getpurchased',
571 703 api_key: api_key
572 704 });
573 705
574 -
575 - if ( api_key == '' ) {
576 - statusEl.find('.text').html( __( "Main API Key is required." ) );
706 +
707 + if (api_key == '') {
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);
713 + } else if (retring) {
714 + statusEl.find('.text').html(MainWP.I18n.t("Connection error detected. The Verify Certificate option has been switched to NO. Retrying..."));
715 + setTimeout(function () {
716 + statusEl.fadeOut();
717 + }, 3000);
581 718 } else {
582 - if ( retring == true ) {
583 - statusEl.find('.text').html( __( "Connection error detected. The Verify Certificate option has been switched to NO. Retrying..." ) );
584 - setTimeout(function () {
585 - statusEl.fadeOut();
586 - }, 3000);
587 - } else {
588 - statusEl.show();
589 - statusEl.find( '.text' ).html( __( 'Loading extensions info...' ) );
590 - jQuery.post(ajaxurl, data, function (response) {
591 - var undefError = false;
592 - if (response) {
593 - if (response.result == 'SUCCESS') {
594 - statusEl.hide();
595 - jQuery('#mainwp-get-purchased-extensions-modal').modal({
596 - allowMultiple: true,
597 - closable: false,
598 - onHide: function () {
599 - location.href = 'admin.php?page=Extensions';
600 - }
601 - }).modal('show');
602 - jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data);
603 - if (jQuery('#extension_install_ext_slug').length > 0) {
604 - mainwp_extension_select_to_install();
719 + statusEl.show();
720 + statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...'));
721 + jQuery.post(ajaxurl, data, function (response) {
722 + let undefError = false;
723 + if (response) {
724 + if (response.result == 'SUCCESS') {
725 + statusEl.hide();
726 + jQuery('#mainwp-get-purchased-extensions-modal').modal({
727 + allowMultiple: true,
728 + closable: false,
729 + onHide: function () {
730 + mainwp_forceReload('admin.php?page=Extensions');
605 731 }
606 - } else if (response.error) {
607 - statusEl.find( '.text' ).html(response.error);
608 - } else if (response.retry_action && response.retry_action == 1) {
609 - jQuery("#mainwp_api_sslVerifyCertificate").val(0);
610 - statusEl.fadeOut();
611 - mainwp_extension_grab_purchased(pObj, true);
612 - return false;
613 - } else {
614 - undefError = true;
732 + }).modal('show');
733 + jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data);
734 + if (jQuery('#extension_install_ext_slug').length > 0) {
735 + mainwp_extension_select_to_install();
615 736 }
737 + } else if (response.error) {
738 + statusEl.find('.text').html(response.error);
739 + } else if (response.retry_action && response.retry_action == 1) {
740 + jQuery("#mainwp_api_sslVerifyCertificate").val(0);
741 + statusEl.fadeOut();
742 + mainwp_extension_grab_purchased(true);
743 + return false;
616 744 } else {
617 745 undefError = true;
618 746 }
619 - if ( undefError ) {
620 - statusEl.find( '.text' ).html( __( 'Undefined error occurred. Please try again.' ) );
621 - }
622 - setTimeout(function () {
623 - statusEl.fadeOut();
624 - }, 3000);
625 - }, 'json');
626 - }
747 + } else {
748 + undefError = true;
749 + }
750 + if (undefError) {
751 + statusEl.find('.text').html(MainWP.I18n.t('Undefined error occurred. Please try again.'));
752 + }
753 + setTimeout(function () {
754 + statusEl.fadeOut();
755 + }, 3000);
756 + }, 'json');
627 757 }
628 758 return false;
629 759 }
630 760
631 -mainwp_extension_select_to_install = function () {
632 - var inst_ext = jQuery('.item.extension[slug="' + jQuery('#extension_install_ext_slug').val() + '"]');
633 - console.log(inst_ext);
761 +let mainwp_extension_select_to_install = function () {
762 + let inst_ext = jQuery('.item.extension[slug="' + jQuery('#extension_install_ext_slug').val() + '"]');
634 763 if (jQuery(inst_ext).length > 0) {
635 764 jQuery('mainwp-installing-extensions .ui.tab').removeClass('active');
636 - var curtab = jQuery(inst_ext[0]).closest('.ui.tab').attr('data-tab');
765 + let curtab = jQuery(inst_ext[0]).closest('.ui.tab').attr('data-tab');
637 766 jQuery('#mainwp-install-extensions-menu .item[data-tab=' + curtab + ']').trigger('click');
638 - var install_chk = jQuery(inst_ext).find('input[type=checkbox]');
767 + let install_chk = jQuery(inst_ext).find('input[type=checkbox]');
639 768 if (install_chk.length > 0) {
640 769 jQuery(install_chk[0]).trigger('click');
641 770 }
642 771 }
@@ -641,12 +770,12 @@
641 770 }
642 771 }
643 772 }
644 773
645 -mainwp_extension_grab_org_extensions = function () {
774 +let mainwp_extension_grab_org_extensions = function () {
646 775
647 - var statusEl = jQuery(".mainwp-extensions-api-loading");
648 - var data = mainwp_secure_data({
776 + let statusEl = jQuery(".mainwp-extensions-api-loading");
777 + let data = mainwp_secure_data({
649 778 action: 'mainwp_extension_getpurchased',
650 779 });
651 780
652 781 statusEl.removeClass('green');
@@ -651,11 +780,11 @@
651 780
652 781 statusEl.removeClass('green');
653 782 statusEl.removeClass('yellow');
654 783 statusEl.show();
655 - statusEl.find('.text').html( __('Running. Please wait...'));
784 + statusEl.find('.text').html(MainWP.I18n.t('Running. Please wait...'));
656 785 jQuery.post(ajaxurl, data, function (response) {
657 - var undefError = false;
786 + let undefError = false;
658 787 if (response) {
659 788 if (response.result == 'SUCCESS') {
660 789 jQuery('#mainwp-get-purchased-extensions-modal').modal({
661 790 allowMultiple: true,
@@ -660,9 +789,9 @@
660 789 jQuery('#mainwp-get-purchased-extensions-modal').modal({
661 790 allowMultiple: true,
662 791 closable: false,
663 792 onHide: function () {
664 - location.href = 'admin.php?page=Extensions';
793 + mainwp_forceReload('admin.php?page=Extensions');
665 794 }
666 795 }).modal('show');
667 796 jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data);
668 797 if (jQuery('#extension_install_ext_slug').length > 0) {
@@ -680,9 +809,9 @@
680 809 }
681 810
682 811 if (undefError) {
683 812 statusEl.addClass('red');
684 - statusEl.find('.text').html(__('Undefined error. Please try again.')).fadeIn();
813 + statusEl.find('.text').html(MainWP.I18n.t('Undefined error. Please try again.')).fadeIn();
685 814 }
686 815 setTimeout(function () {
687 816 statusEl.fadeOut();
688 817 }, 3000);
@@ -696,19 +825,19 @@
696 825 mainwp_extension_bulk_install();
697 826 return false;
698 827 })
699 828
700 -bulkExtensionsMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests'];
701 -bulkExtensionsCurrentThreads = 0;
702 -bulkExtensionsTotal = 0;
703 -bulkExtensionsFinished = 0;
704 -bulkExtensionsRunning = false;
829 +let bulkExtensionsMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests'];
830 +let bulkExtensionsCurrentThreads = 0;
831 +let bulkExtensionsTotal = 0;
832 +let bulkExtensionsFinished = 0;
833 +let bulkExtensionsRunning = false;
705 834
706 -mainwp_extension_bulk_install = function () {
835 +let mainwp_extension_bulk_install = function () {
707 836 if (bulkExtensionsRunning)
708 837 return;
709 838
710 - 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>');
711 840
712 841 bulkExtensionsTotal = jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked').length;
713 842
714 843 if (bulkExtensionsTotal == 0)
@@ -713,33 +842,33 @@
713 842
714 843 if (bulkExtensionsTotal == 0)
715 844 return false;
716 845
717 - 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'));
718 847
719 848 mainwp_extension_bulk_install_next();
720 849 }
721 850
722 -mainwp_extension_bulk_install_next = function () {
723 - while ((extToInstall = jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked:first').closest('.extension-to-install')) && (extToInstall.length > 0) && (bulkExtensionsCurrentThreads < bulkExtensionsMaxThreads)) {
851 +let mainwp_extension_bulk_install_next = function () {
852 + while ((extToInstall = jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked:first').closest('.extension-to-install')) && (extToInstall.length > 0) && (bulkExtensionsCurrentThreads < bulkExtensionsMaxThreads)) { // NOSONAR -- modified out side the function.
724 853 mainwp_extension_bulk_install_specific(extToInstall);
725 854 }
726 855
727 - if ((bulkExtensionsTotal > 0) && (bulkExtensionsFinished == bulkExtensionsTotal)) {
856 + if ((bulkExtensionsTotal > 0) && (bulkExtensionsFinished == bulkExtensionsTotal)) { // NOSONAR -- modified out side the function.
728 857 mainwp_extension_bulk_activate();
729 858 }
730 859 }
731 860
732 -mainwp_extension_bulk_install_specific = function (pExtToInstall) {
861 +let mainwp_extension_bulk_install_specific = function (pExtToInstall) {
733 862 bulkExtensionsRunning = true;
734 863 pExtToInstall.find('input[type="checkbox"]').attr('status', 'running');
735 864 bulkExtensionsCurrentThreads++;
736 865
737 - var statusEl = pExtToInstall.find('.installing-extension');
866 + let statusEl = pExtToInstall.find('.installing-extension');
738 867
739 - 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>');
740 869
741 - var data = mainwp_secure_data({
870 + let data = mainwp_secure_data({
742 871 action: 'mainwp_extension_downloadandinstall',
743 872 download_link: pExtToInstall.attr('download-link'),
744 873 plugin_slug: pExtToInstall.attr('plugin-slug')
745 874 });
@@ -754,28 +883,25 @@
754 883 bulkExtensionsFinished++;
755 884
756 885 statusEl.html('');
757 886
758 - var reg = new RegExp('<mainwp>(.*)</mainwp>');
759 - var matches = reg.exec(res_data);
760 - var response = '';
887 + let matches = res_data.match('<mainwp>(.*)</mainwp>');
888 + let response = '';
761 889
762 890 if (matches) {
763 - response_json = matches[1];
891 + let response_json = matches[1];
764 892 response = JSON.parse(response_json);
765 893 }
766 894
767 - if (response != '') {
768 - if (response.result == 'SUCCESS') {
769 - statusEl.html('<span data-tooltip="' + response.output + '" data-inverted="" data-position="left center"><i class="check green icon"></i></span>');
770 - jQuery('.mainwp-installing-extensions').append('<span class="extension-installed-success" slug="' + response.slug + '"></span>')
771 - } else if (response.error) {
772 - statusEl.html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>');
773 - } 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>');
775 - }
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>');
776 902 } else {
777 - 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>');
778 904 }
779 905
780 906 mainwp_extension_bulk_install_next();
781 907 }
@@ -784,10 +910,10 @@
784 910
785 911 return false;
786 912 }
787 913
788 -mainwp_extension_bulk_activate = function () {
789 - var plugins = [];
914 +let mainwp_extension_bulk_activate = function () {
915 + let plugins = [];
790 916
791 917 jQuery('.extension-installed-success').each(function () {
792 918 plugins.push(jQuery(this).attr('slug'));
793 919 });
@@ -796,21 +922,21 @@
796 922 mainwp_extension_bulk_install_done();
797 923 return;
798 924 }
799 925
800 - var data = mainwp_secure_data({
926 + let data = mainwp_secure_data({
801 927 action: 'mainwp_extension_bulk_activate',
802 928 plugins: plugins
803 929 });
804 930
805 - var statusEl = jQuery('#mainwp-bulk-activating-extensions-status');
931 + let statusEl = jQuery('#mainwp-bulk-activating-extensions-status');
806 932
807 - 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();
808 934 jQuery.post(ajaxurl, data, function (response) {
809 935 statusEl.html('');
810 936 if (response == 'SUCCESS') {
811 937 statusEl.addClass('green');
812 - statusEl.html(__('Extensions have been activated successfully!'));
938 + statusEl.html(MainWP.I18n.t('Add-ons have been activated successfully!'));
813 939 statusEl.fadeOut(3000);
814 940 }
815 941 mainwp_extension_bulk_install_done();
816 942 });
@@ -815,18 +941,18 @@
815 941 mainwp_extension_bulk_install_done();
816 942 });
817 943 }
818 944
819 -mainwp_extension_bulk_install_done = function () {
945 +let mainwp_extension_bulk_install_done = function () {
820 946 bulkExtensionsRunning = false;
821 947
822 - var statusEl = jQuery('#mainwp-bulk-activating-extensions-status');
948 + let statusEl = jQuery('#mainwp-bulk-activating-extensions-status');
823 949
824 950 statusEl.addClass('green');
825 - 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();
826 952 if (jQuery('.extension-installed-success').length == bulkExtensionsFinished) {
827 953 setTimeout(function () {
828 - location.href = 'admin.php?page=Extensions';
954 + mainwp_forceReload('admin.php?page=Extensions');
829 955 }, 3000);
830 956 }
831 957 }
832 958
@@ -833,13 +959,13 @@
833 959
834 960 // Is this function still in use???
835 961 jQuery(document).on('click', '#mainwp-extensions-api-sslverify-certificate', function () {
836 962
837 - var parent = jQuery(this).closest(".extension_api_sslverify_loading");
838 - var statusEl = parent.find('span.status');
839 - var loadingEl = parent.find("i");
963 + let parent = jQuery(this).closest(".extension_api_sslverify_loading");
964 + let statusEl = parent.find('span.status');
965 + let loadingEl = parent.find("i");
840 966
841 - var data = mainwp_secure_data({
967 + let data = mainwp_secure_data({
842 968 action: 'mainwp_extension_apisslverifycertificate',
843 969 api_sslverify: jQuery("#mainwp_api_sslVerifyCertificate").val()
844 970 });
845 971
@@ -846,9 +972,9 @@
846 972 statusEl.hide();
847 973 loadingEl.show();
848 974 jQuery.post(ajaxurl, data, function (response) {
849 975 loadingEl.hide();
850 - var undefError = false;
976 + let undefError = false;
851 977 if (response) {
852 978 if (response.saved) {
853 979 statusEl.css('color', '#0074a2');
854 980 statusEl.html('MainWP Main API Key saved!').fadeIn();
@@ -866,15 +992,15 @@
866 992 }
867 993
868 994 if (undefError) {
869 995 statusEl.css('color', 'red');
870 - statusEl.html('<i class="exclamation circle icon"></i> Undefined error!').fadeIn();
996 + statusEl.html('<i class="exclamation circle icon"></i> Undefined error').fadeIn();
871 997 }
872 998 }, 'json');
873 999 return false;
874 1000 });
875 1001
876 -jQuery(document).ready(function ($) {
1002 +jQuery(function ($) {
877 1003 jQuery(document).on('click', '#mainwp-check-all-sync-ext', function () {
878 1004 $('.sync-ext-row').find("input:checkbox").each(function () {
879 1005 $(this).attr('checked', true);
880 1006 });
@@ -888,11 +1014,11 @@
888 1014 jQuery(document).on('click', '.mainwp-show-extensions', function () {
889 1015 $('a.mainwp-show-extensions').removeClass('mainwp_action_down');
890 1016 $(this).addClass('mainwp_action_down');
891 1017
892 - var gr = $(this).attr('group');
893 - var selectedEl = $('#mainwp-available-extensions-list .mainwp-availbale-extension-holder.group-' + gr);
894 - var installedGroup = $('.installed-group-exts');
1018 + let gr = $(this).attr('group');
1019 + let selectedEl = $('#mainwp-available-extensions-list .mainwp-availbale-extension-holder.group-' + gr);
1020 + let installedGroup = $('.installed-group-exts');
895 1021 installedGroup.hide();
896 1022
897 1023 if (gr == 'all') {
898 1024 $('#mainwp-available-extensions-list .mainwp-availbale-extension-holder').fadeIn(500);