| @@ -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,24 +51,31 @@ | ||
| 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 | - var 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 | - jQuery(document).on('click', '#mainwp_managesites_add', function (event) { | |
| 43 | - mainwp_setup_managesites_add(event); | |
| 71 | + jQuery(document).on('click', '#mainwp_managesites_add', function () { | |
| 72 | + mainwp_setup_managesites_add(); | |
| 44 | 73 | }); |
| 45 | 74 | |
| 46 | 75 | jQuery(document).on('change', '#mainwp_managesites_add_wpurl', function () { |
| 47 | - var url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 48 | - var protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); | |
| 76 | + let url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 77 | + let protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); | |
| 49 | 78 | |
| 50 | 79 | if (url.lastIndexOf('http://') === 0) { |
| 51 | 80 | protocol = 'http'; |
| 52 | 81 | url = url.substring(7); |
| @@ -64,15 +93,25 @@ | ||
| 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 | -mainwp_setup_managesites_add = function () { | |
| 110 | +let mainwp_setup_managesites_add = function () { | |
| 111 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 112 | + let errors = []; | |
| 70 | 113 | |
| 71 | - jQuery('#mainwp-message-zone').hide(); | |
| 72 | - | |
| 73 | - var errors = []; | |
| 74 | - | |
| 75 | 114 | if (jQuery('#mainwp_managesites_add_wpname').val().trim() == '') { |
| 76 | 115 | errors.push('Please enter a title for the website.'); |
| 77 | 116 | } |
| 78 | 117 | |
| @@ -78,10 +117,10 @@ | ||
| 78 | 117 | |
| 79 | 118 | if (jQuery('#mainwp_managesites_add_wpurl').val().trim() == '') { |
| 80 | 119 | errors.push('Please enter a valid URL for the site.'); |
| 81 | 120 | } else { |
| 82 | - var url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 83 | - if (url.substr(-1) != '/') { | |
| 121 | + let url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 122 | + if (!url.endsWith('/')) { | |
| 84 | 123 | url += '/'; |
| 85 | 124 | } |
| 86 | 125 | |
| 87 | 126 | jQuery('#mainwp_managesites_add_wpurl').val(url); |
| @@ -95,23 +134,23 @@ | ||
| 95 | 134 | errors.push('Please enter a username of the website administrator.'); |
| 96 | 135 | } |
| 97 | 136 | |
| 98 | 137 | if (errors.length > 0) { |
| 99 | - jQuery('#mainwp-message-zone').html(errors.join('<br />')).addClass('yellow').show(); | |
| 138 | + mainwp_set_message_zone('#mainwp-message-zone', errors.join('<br />'), 'yellow'); | |
| 100 | 139 | } else { |
| 101 | - jQuery('#mainwp-message-zone').html('Adding the site to your MainWP Dashboard. Please wait...').removeClass('green red yellow').show(); | |
| 140 | + mainwp_set_message_zone('#mainwp-message-zone', '<i class="notched circle loading icon"></i> Adding the site to your MainWP Dashboard. Please wait...', ''); | |
| 102 | 141 | jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //disable button to add.. |
| 103 | 142 | |
| 104 | - var url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 143 | + let url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 105 | 144 | |
| 106 | - if (url.substr(-1) != '/') { | |
| 145 | + if (!url.endsWith('/')) { | |
| 107 | 146 | url += '/'; |
| 108 | 147 | } |
| 109 | 148 | |
| 110 | - var name = jQuery('#mainwp_managesites_add_wpname').val().trim(); | |
| 149 | + let name = jQuery('#mainwp_managesites_add_wpname').val().trim(); | |
| 111 | 150 | name = name.replace(/"/g, '"'); |
| 112 | 151 | |
| 113 | - var data = mainwp_setup_secure_data({ | |
| 152 | + let data = mainwp_setup_secure_data({ | |
| 114 | 153 | action: 'mainwp_checkwp', |
| 115 | 154 | name: name, |
| 116 | 155 | url: url, |
| 117 | 156 | admin: jQuery('#mainwp_managesites_add_wpadmin').val().trim(), |
| @@ -117,13 +156,13 @@ | ||
| 117 | 156 | admin: jQuery('#mainwp_managesites_add_wpadmin').val().trim(), |
| 118 | 157 | }); |
| 119 | 158 | |
| 120 | 159 | jQuery.post(ajaxurl, data, function (res_things) { |
| 121 | - response = res_things.response; | |
| 160 | + let response = res_things.response; | |
| 122 | 161 | response = response.trim(); |
| 123 | 162 | |
| 124 | - var url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 125 | - if (url.substr(-1) != '/') { | |
| 163 | + let url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 164 | + if (!url.endsWith('/')) { | |
| 126 | 165 | url += '/'; |
| 127 | 166 | } |
| 128 | 167 | |
| 129 | 168 | url = url.replace(/"/g, '"'); |
| @@ -128,17 +167,17 @@ | ||
| 128 | 167 | |
| 129 | 168 | url = url.replace(/"/g, '"'); |
| 130 | 169 | |
| 131 | 170 | if (response == 'HTTPERROR') { |
| 132 | - 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>.'); | |
| 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. | |
| 133 | 172 | } else if (response == 'NOMAINWP') { |
| 134 | 173 | errors.push(mainwp_js_get_error_not_detected_connect()); |
| 135 | - } else if (response.substr(0, 5) == 'ERROR') { | |
| 174 | + } else if (response.substring(0, 5) == 'ERROR') { | |
| 136 | 175 | if (response.length == 5) { |
| 137 | - 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>.'); | |
| 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. | |
| 138 | 177 | } else { |
| 139 | - var error = response.substr(6); | |
| 140 | - var err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', false, true); // return text error. | |
| 178 | + let error = response.substring(6); | |
| 179 | + let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', false, true); // return text error. | |
| 141 | 180 | if (false === err) { |
| 142 | 181 | errors.push(error); // it is not json string error. |
| 143 | 182 | } else if (true !== err && '' != err) { |
| 144 | 183 | errors.push(err); // decoded error. |
| @@ -146,16 +185,17 @@ | ||
| 146 | 185 | } |
| 147 | 186 | } else if (response == 'OK') { |
| 148 | 187 | jQuery('#mainwp_managesites_add').attr('disabled', 'true'); |
| 149 | 188 | |
| 150 | - var name = jQuery('#mainwp_managesites_add_wpname').val(); | |
| 189 | + let name = jQuery('#mainwp_managesites_add_wpname').val(); | |
| 151 | 190 | name = name.replace(/"/g, '"'); |
| 152 | - var group_ids = ''; | |
| 153 | - var data = mainwp_setup_secure_data({ | |
| 191 | + let group_ids = ''; | |
| 192 | + let data = mainwp_setup_secure_data({ | |
| 154 | 193 | action: 'mainwp_addwp', |
| 155 | 194 | managesites_add_wpname: name, |
| 156 | 195 | managesites_add_wpurl: url, |
| 157 | 196 | managesites_add_wpadmin: jQuery('#mainwp_managesites_add_wpadmin').val(), |
| 197 | + managesites_add_adminpwd: encodeURIComponent(jQuery('#mainwp_managesites_add_admin_pwd').val()), | |
| 158 | 198 | managesites_add_uniqueId: jQuery('#mainwp_managesites_add_uniqueId').val(), |
| 159 | 199 | groupids: group_ids, |
| 160 | 200 | qsw_page: true, |
| 161 | 201 | }); |
| @@ -161,17 +201,17 @@ | ||
| 161 | 201 | }); |
| 162 | 202 | |
| 163 | 203 | // to support add client reports tokens values |
| 164 | 204 | jQuery("input[name^='creport_token_']").each(function () { |
| 165 | - var tname = jQuery(this).attr('name'); | |
| 166 | - var tvalue = jQuery(this).val(); | |
| 205 | + let tname = jQuery(this).attr('name'); | |
| 206 | + let tvalue = jQuery(this).val(); | |
| 167 | 207 | data[tname] = tvalue; |
| 168 | 208 | }); |
| 169 | 209 | |
| 170 | 210 | // support hooks fields |
| 171 | 211 | jQuery(".mainwp_addition_fields_addsite input").each(function () { |
| 172 | - var tname = jQuery(this).attr('name'); | |
| 173 | - var tvalue = jQuery(this).val(); | |
| 212 | + let tname = jQuery(this).attr('name'); | |
| 213 | + let tvalue = jQuery(this).val(); | |
| 174 | 214 | data[tname] = tvalue; |
| 175 | 215 | }); |
| 176 | 216 | |
| 177 | 217 | jQuery.post(ajaxurl, data, function (res_things) { |
| @@ -183,18 +223,16 @@ | ||
| 183 | 223 | } |
| 184 | 224 | |
| 185 | 225 | response = response.trim(); |
| 186 | 226 | |
| 187 | - jQuery('#mainwp-message-zone').hide(); | |
| 227 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 188 | 228 | jQuery('#mainwp-info-zone').hide(); |
| 189 | 229 | |
| 190 | - if (response.substr(0, 5) == 'ERROR') { | |
| 191 | - jQuery('#mainwp-message-zone').removeClass('green yellow green'); | |
| 192 | - jQuery('#mainwp-message-zone').html(response.substr(6)).addClass('red').show(); | |
| 230 | + if (response.substring(0, 5) == 'ERROR') { | |
| 231 | + mainwp_set_message_zone('#mainwp-message-zone', response.substring(6), 'red'); | |
| 193 | 232 | } else { |
| 194 | 233 | //Message the WP was added |
| 195 | - jQuery('#mainwp-message-zone').removeClass('green yellow green'); | |
| 196 | - jQuery('#mainwp-message-zone').html(response).addClass('green').show(); | |
| 234 | + mainwp_set_message_zone('#mainwp-message-zone', response, 'green'); | |
| 197 | 235 | |
| 198 | 236 | //Reset fields |
| 199 | 237 | jQuery('#mainwp_managesites_add_wpname').val(''); |
| 200 | 238 | jQuery('#mainwp_managesites_add_wpurl').val(''); |
| @@ -199,8 +237,9 @@ | ||
| 199 | 237 | jQuery('#mainwp_managesites_add_wpname').val(''); |
| 200 | 238 | jQuery('#mainwp_managesites_add_wpurl').val(''); |
| 201 | 239 | jQuery('#mainwp_managesites_add_wpurl_protocol').val('https'); |
| 202 | 240 | jQuery('#mainwp_managesites_add_wpadmin').val(''); |
| 241 | + jQuery('#mainwp_managesites_add_admin_pwd').val(''); | |
| 203 | 242 | jQuery('#mainwp_managesites_add_uniqueId').val(''); |
| 204 | 243 | |
| 205 | 244 | jQuery("input[name^='creport_token_']").each(function () { |
| 206 | 245 | jQuery(this).val(''); |
| @@ -211,10 +250,10 @@ | ||
| 211 | 250 | jQuery(this).val(''); |
| 212 | 251 | }); |
| 213 | 252 | |
| 214 | 253 | setTimeout(function () { |
| 215 | - window.location.href = 'admin.php?page=mainwp-setup&step=connect_first_site'; | |
| 216 | - }, 1000); | |
| 254 | + mainwp_forceReload('admin.php?page=mainwp-setup&step=add_client'); | |
| 255 | + }, 3000); | |
| 217 | 256 | } |
| 218 | 257 | |
| 219 | 258 | jQuery('#mainwp_managesites_add').prop("disabled", false); |
| 220 | 259 | }, 'json'); |
| @@ -219,12 +258,10 @@ | ||
| 219 | 258 | jQuery('#mainwp_managesites_add').prop("disabled", false); |
| 220 | 259 | }, 'json'); |
| 221 | 260 | } |
| 222 | 261 | if (errors.length > 0) { |
| 223 | - jQuery('#mainwp-message-zone').removeClass('green yellow green'); | |
| 224 | - jQuery('#mainwp-message-zone').hide(); | |
| 262 | + mainwp_set_message_zone('#mainwp-message-zone', errors.join('<br />'), 'red'); | |
| 225 | 263 | jQuery('#mainwp_managesites_add').prop("disabled", false); |
| 226 | - jQuery('#mainwp-message-zone').html(errors.join('<br />')).addClass('red').show(); | |
| 227 | 264 | } |
| 228 | 265 | }, 'json'); |
| 229 | 266 | } |
| 230 | 267 | }; |
| @@ -229,17 +266,20 @@ | ||
| 229 | 266 | } |
| 230 | 267 | }; |
| 231 | 268 | |
| 232 | 269 | // Check if the URL field is valid value |
| 233 | -function isUrl(s) { | |
| 234 | - var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/; | |
| 235 | - return regexp.test(s); | |
| 270 | +function isUrl(url) { | |
| 271 | + try { | |
| 272 | + new URL(url); | |
| 273 | + return true; | |
| 274 | + } catch (e) { | |
| 275 | + console.log(e); | |
| 276 | + } | |
| 277 | + return false; | |
| 236 | 278 | } |
| 237 | 279 | |
| 238 | -mainwp_setup_secure_data = function (data) { | |
| 280 | +let mainwp_setup_secure_data = function (data) { | |
| 239 | 281 | if (data['action'] == undefined) |
| 240 | 282 | return data; |
| 241 | - | |
| 242 | - data['security'] = jQuery('#nonce_secure_data').attr(data['action']); | |
| 243 | - | |
| 283 | + data.security = jQuery('input[name="qsw_nonce[' + data.action + ']"]').val() || ''; | |
| 244 | 284 | return data; |
| 245 | 285 | }; |