| @@ -1,17 +1,39 @@ | ||
| 1 | 1 | jQuery(function () { |
| 2 | - jQuery('#mainwp-qsw-verify-mainwp-child-active').on('change', function () { | |
| 3 | - if (jQuery(this).is(':checked')) { | |
| 2 | + jQuery('.mainwp-field-tab-connect input[name=tab_connect]').change(function () { | |
| 3 | + const tab_active = this.value; | |
| 4 | + if (tab_active !== '') { | |
| 4 | 5 | jQuery('#mainwp-qsw-connect-site-form').fadeIn(500); |
| 5 | 6 | jQuery('#mainwp_managesites_add').show(); |
| 7 | + jQuery('#mainwp-qsw-toggle-verify-mainwp-child-active').show(); | |
| 6 | 8 | jQuery('#mainwp_addsite_continue_button').hide(); |
| 9 | + jQuery('.menu-connect-first-site .item').tab('change tab', tab_active); | |
| 10 | + } | |
| 11 | + }); | |
| 12 | + | |
| 13 | + jQuery('#mainwp-qsw-verify-mainwp-child-active').on('change', function () { | |
| 14 | + if (jQuery(this).is(':checked')) { | |
| 15 | + jQuery('#mainwp_managesites_add').removeClass('disabled'); | |
| 16 | + jQuery('#mainwp_managesites_add_import').removeClass('disabled'); | |
| 7 | 17 | } else { |
| 8 | - jQuery('#mainwp-qsw-connect-site-form').fadeOut(500); | |
| 9 | - jQuery('#mainwp_managesites_add').hide(); | |
| 10 | - jQuery('#mainwp_addsite_continue_button').show(); | |
| 18 | + jQuery('#mainwp_managesites_add').addClass('disabled'); | |
| 19 | + jQuery('#mainwp_managesites_add_import').addClass('disabled'); | |
| 11 | 20 | } |
| 12 | 21 | }); |
| 13 | 22 | |
| 23 | + // Handle submit import file CVS. | |
| 24 | + jQuery(document).on('click', '#mainwp_managesites_add_import', function () { | |
| 25 | + let error_messages = mainwp_managesites_import_handle_form_before_submit(); | |
| 26 | + // If there is an error, prevent submission and display the error | |
| 27 | + if (error_messages.length > 0) { | |
| 28 | + feedback('mainwp-message-zone', error_messages.join("<br/>"), "red"); | |
| 29 | + } else { | |
| 30 | + jQuery('#mainwp_connect_first_site_form').trigger('submit'); | |
| 31 | + } | |
| 32 | + | |
| 33 | + return false; | |
| 34 | + }); | |
| 35 | + | |
| 14 | 36 | jQuery('#mainwp_qsw_client_name_field').on('keyup', function () { |
| 15 | 37 | if (jQuery(this).val()) { |
| 16 | 38 | jQuery('#bulk_add_createclient').show(); |
| 17 | 39 | jQuery('#mainwp_qsw_add_client_continue_button').hide(); |
| @@ -29,14 +51,21 @@ | ||
| 29 | 51 | jQuery('.ui.checkbox:not(.not-auto-init)').checkbox(); |
| 30 | 52 | jQuery('.ui.dropdown:not(.not-auto-init)').dropdown(); |
| 31 | 53 | |
| 32 | 54 | jQuery('.mainwp-checkbox-showhide-elements').on('click', function () { |
| 33 | - let hiel = jQuery(this).attr('hide-parent'); | |
| 34 | - // if semantic ui checkbox is checked. | |
| 35 | - if (jQuery(this).find('input').is(':checked')) { | |
| 36 | - jQuery('[hide-element=' + hiel + ']').fadeIn(500); | |
| 37 | - } else { | |
| 38 | - jQuery('[hide-element=' + hiel + ']').fadeOut(500); | |
| 55 | + let $el = jQuery(this); | |
| 56 | + let hiels = $el.attr('hide-parent'); | |
| 57 | + if (hiels !== undefined && hiels !== '') { | |
| 58 | + let isChecked = $el.find('input').is(':checked'); | |
| 59 | + let items = hiels.split(';'); | |
| 60 | + items.forEach(function(hiel) { | |
| 61 | + // if semantic ui checkbox is checked. | |
| 62 | + if (isChecked) { | |
| 63 | + jQuery('[hide-element=' + hiel + ']').fadeIn(500); | |
| 64 | + } else { | |
| 65 | + jQuery('[hide-element=' + hiel + ']').fadeOut(500); | |
| 66 | + } | |
| 67 | + }); | |
| 39 | 68 | } |
| 40 | 69 | }); |
| 41 | 70 | |
| 42 | 71 | jQuery(document).on('click', '#mainwp_managesites_add', function () { |
| @@ -64,8 +93,20 @@ | ||
| 64 | 93 | }); |
| 65 | 94 | |
| 66 | 95 | }); |
| 67 | 96 | |
| 97 | +// Handle tab onvisible. | |
| 98 | +const mainwp_menu_connect_first_site_onvisible_callback = function (objItem) { | |
| 99 | + const tab = jQuery(objItem).attr("data-tab"); | |
| 100 | + jQuery('.mainwp-field-tab-connect input[name=tab_connect]').filter(`[value="${tab}"]`).parent().trigger('click'); // set checked class ui checkbox | |
| 101 | + if (tab === 'multiple-site') { | |
| 102 | + jQuery('#mainwp_managesites_add_import').show(); | |
| 103 | + jQuery('#mainwp_managesites_add').hide(); | |
| 104 | + } else if (tab === 'single-site') { | |
| 105 | + jQuery('#mainwp_managesites_add').show(); | |
| 106 | + jQuery('#mainwp_managesites_add_import').hide(); | |
| 107 | + } | |
| 108 | +} | |
| 68 | 109 | // Connect a new website |
| 69 | 110 | let mainwp_setup_managesites_add = function () { |
| 70 | 111 | mainwp_set_message_zone('#mainwp-message-zone'); |
| 71 | 112 | let errors = []; |
| @@ -95,9 +136,9 @@ | ||
| 95 | 136 | |
| 96 | 137 | if (errors.length > 0) { |
| 97 | 138 | mainwp_set_message_zone('#mainwp-message-zone', errors.join('<br />'), 'yellow'); |
| 98 | 139 | } else { |
| 99 | - mainwp_set_message_zone('#mainwp-message-zone', 'Adding the site to your MainWP Dashboard. Please wait...', ''); | |
| 140 | + mainwp_set_message_zone('#mainwp-message-zone', '<i class="notched circle loading icon"></i> Adding the site to your MainWP Dashboard. Please wait...', ''); | |
| 100 | 141 | jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //disable button to add.. |
| 101 | 142 | |
| 102 | 143 | let url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); |
| 103 | 144 | |
| @@ -126,14 +167,14 @@ | ||
| 126 | 167 | |
| 127 | 168 | url = url.replace(/"/g, '"'); |
| 128 | 169 | |
| 129 | 170 | if (response == 'HTTPERROR') { |
| 130 | - errors.push('This site can not be reached! Please use the Test Connection feature and see if the positive response will be returned. For additional help, please review <a href="https://kb.mainwp.com/">MainWP Knowledgebase</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.'); // NOSONAR - noopener - open safe. | |
| 171 | + errors.push('This site can not be reached! Please use the Test Connection feature and see if the positive response will be returned. For additional help, please review <a href="https://docs.mainwp.com/">MainWP Knowledgebase</a>, and if you still have issues, please let us know in the <a href="https://community.mainwp.com/c/community-support/5">MainWP Community</a>.'); // NOSONAR - noopener - open safe. | |
| 131 | 172 | } else if (response == 'NOMAINWP') { |
| 132 | 173 | errors.push(mainwp_js_get_error_not_detected_connect()); |
| 133 | 174 | } else if (response.substring(0, 5) == 'ERROR') { |
| 134 | 175 | if (response.length == 5) { |
| 135 | - errors.push('Undefined error occurred. Please try again. If the issue does not resolve, please review <a href="https://kb.mainwp.com/">MainWP Knowledgebase</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.'); // NOSONAR - noopener - open safe. | |
| 176 | + errors.push('Undefined error occurred. Please try again. If the issue does not resolve, please review <a href="https://docs.mainwp.com/">MainWP Knowledgebase</a>, and if you still have issues, please let us know in the <a href="https://community.mainwp.com/c/community-support/5">MainWP Community</a>.'); // NOSONAR - noopener - open safe. | |
| 136 | 177 | } else { |
| 137 | 178 | let error = response.substring(6); |
| 138 | 179 | let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', false, true); // return text error. |
| 139 | 180 | if (false === err) { |
| @@ -152,8 +193,9 @@ | ||
| 152 | 193 | action: 'mainwp_addwp', |
| 153 | 194 | managesites_add_wpname: name, |
| 154 | 195 | managesites_add_wpurl: url, |
| 155 | 196 | managesites_add_wpadmin: jQuery('#mainwp_managesites_add_wpadmin').val(), |
| 197 | + managesites_add_adminpwd: encodeURIComponent(jQuery('#mainwp_managesites_add_admin_pwd').val()), | |
| 156 | 198 | managesites_add_uniqueId: jQuery('#mainwp_managesites_add_uniqueId').val(), |
| 157 | 199 | groupids: group_ids, |
| 158 | 200 | qsw_page: true, |
| 159 | 201 | }); |
| @@ -195,8 +237,9 @@ | ||
| 195 | 237 | jQuery('#mainwp_managesites_add_wpname').val(''); |
| 196 | 238 | jQuery('#mainwp_managesites_add_wpurl').val(''); |
| 197 | 239 | jQuery('#mainwp_managesites_add_wpurl_protocol').val('https'); |
| 198 | 240 | jQuery('#mainwp_managesites_add_wpadmin').val(''); |
| 241 | + jQuery('#mainwp_managesites_add_admin_pwd').val(''); | |
| 199 | 242 | jQuery('#mainwp_managesites_add_uniqueId').val(''); |
| 200 | 243 | |
| 201 | 244 | jQuery("input[name^='creport_token_']").each(function () { |
| 202 | 245 | jQuery(this).val(''); |
| @@ -207,10 +250,10 @@ | ||
| 207 | 250 | jQuery(this).val(''); |
| 208 | 251 | }); |
| 209 | 252 | |
| 210 | 253 | setTimeout(function () { |
| 211 | - window.location.href = 'admin.php?page=mainwp-setup&step=connect_first_site'; | |
| 212 | - }, 1000); | |
| 254 | + mainwp_forceReload('admin.php?page=mainwp-setup&step=add_client'); | |
| 255 | + }, 3000); | |
| 213 | 256 | } |
| 214 | 257 | |
| 215 | 258 | jQuery('#mainwp_managesites_add').prop("disabled", false); |
| 216 | 259 | }, 'json'); |
| @@ -228,16 +271,15 @@ | ||
| 228 | 271 | try { |
| 229 | 272 | new URL(url); |
| 230 | 273 | return true; |
| 231 | 274 | } catch (e) { |
| 232 | - return false; | |
| 275 | + console.log(e); | |
| 233 | 276 | } |
| 277 | + return false; | |
| 234 | 278 | } |
| 235 | 279 | |
| 236 | 280 | let mainwp_setup_secure_data = function (data) { |
| 237 | 281 | if (data['action'] == undefined) |
| 238 | 282 | return data; |
| 239 | - | |
| 240 | - data['security'] = jQuery('#nonce_secure_data').attr(data['action']); | |
| 241 | - | |
| 283 | + data.security = jQuery('input[name="qsw_nonce[' + data.action + ']"]').val() || ''; | |
| 242 | 284 | return data; |
| 243 | 285 | }; |