PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.3
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 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / assets / js / mainwp-setup.js

mainwp-setup.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.3, at assets/js/mainwp-setup.js

223 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( document ).ready( function () {
2
3 jQuery( '#mainwp-qsw-verify-mainwp-child-active' ).change( function () {
4 if ( jQuery( this ).is( ':checked' ) ) {
5 jQuery( '#mainwp-qsw-connect-site-form' ).fadeIn( 500 );
6 } else {
7 jQuery( '#mainwp-qsw-connect-site-form' ).fadeOut( 500 );
8 }
9 } );
10
11 jQuery( '#mainwp-toggle-optional-settings' ).on( 'click', function () {
12 jQuery( '#mainwp-qsw-optional-settings-form' ).toggle( 300 );
13 return false;
14 } );
15
16 jQuery( '.ui.checkbox:not(.not-auto-init)' ).checkbox();
17
18 jQuery( '.mainwp-checkbox-showhide-elements' ).on( 'click', function () {
19 var hiel = jQuery( this ).attr( 'hide-parent' );
20 // if semantic ui checkbox is checked.
21 if ( jQuery( this ).find( 'input' ).is( ':checked' ) ) {
22 jQuery( '[hide-element=' + hiel + ']' ).fadeIn( 500 );
23 } else {
24 jQuery( '[hide-element=' + hiel + ']' ).fadeOut( 500 );
25 }
26 } );
27
28 jQuery( document ).on( 'click', '#mainwp_managesites_add', function ( event ) {
29 mainwp_setup_managesites_add( event );
30 } );
31
32 jQuery( document ).on( 'change', '#mainwp_managesites_add_wpurl', function() {
33 var url = jQuery( '#mainwp_managesites_add_wpurl' ).val();
34 var protocol = jQuery( '#mainwp_managesites_add_wpurl_protocol' ).val();
35
36 if ( url.lastIndexOf( 'http://' ) === 0 ) {
37 protocol = 'http';
38 url = url.substring( 7 );
39 } else if ( url.lastIndexOf( 'https://' ) === 0 ) {
40 protocol = 'https';
41 url = url.substring( 8 );
42 }
43
44 if ( jQuery( '#mainwp_managesites_add_wpname' ).val() == '' ) {
45 jQuery( '#mainwp_managesites_add_wpname' ).val( url );
46 }
47
48 jQuery( '#mainwp_managesites_add_wpurl' ).val( url );
49 jQuery( '#mainwp_managesites_add_wpurl_protocol' ).val( protocol ).trigger( "change" );
50 } );
51
52 } );
53
54 // Connect a new website
55 mainwp_setup_managesites_add = function () {
56
57 jQuery( '#mainwp-message-zone' ).hide();
58
59 var errors = [ ];
60
61 if ( jQuery( '#mainwp_managesites_add_wpname' ).val() == '' ) {
62 errors.push( 'Please enter a title for the website.' );
63 }
64
65 if ( jQuery( '#mainwp_managesites_add_wpurl' ).val() == '' ) {
66 errors.push( 'Please enter a valid URL for the site.' );
67 } else {
68 var url = jQuery( '#mainwp_managesites_add_wpurl' ).val();
69 if ( url.substr( -1 ) != '/' ) {
70 url += '/';
71 }
72
73 jQuery( '#mainwp_managesites_add_wpurl' ).val( url );
74
75 if ( !isUrl( jQuery( '#mainwp_managesites_add_wpurl_protocol' ).val() + '://' + jQuery( '#mainwp_managesites_add_wpurl' ).val() ) ) {
76 errors.push( 'Please enter a valid URL for the site.' );
77 }
78 }
79
80 if ( jQuery( '#mainwp_managesites_add_wpadmin' ).val() == '' ) {
81 errors.push( 'Please enter a username of the website administrator.' );
82 }
83
84 if ( errors.length > 0 ) {
85 jQuery( '#mainwp-message-zone' ).html( errors.join( '<br />' ) ).addClass( 'yellow' ).show();
86 } else {
87 jQuery( '#mainwp-message-zone' ).html( 'Adding the site to your MainWP Dashboard. Please wait...' ).removeClass( 'green red yellow' ).show();
88 jQuery( '#mainwp_managesites_add' ).attr( 'disabled', 'true' ); //disable button to add..
89
90 var url = jQuery( '#mainwp_managesites_add_wpurl_protocol' ).val() + '://' + jQuery( '#mainwp_managesites_add_wpurl' ).val();
91
92 if ( url.substr( -1 ) != '/' ) {
93 url += '/';
94 }
95
96 var name = jQuery( '#mainwp_managesites_add_wpname' ).val();
97 name = name.replace( /"/g, '&quot;' );
98
99 var data = mainwp_setup_secure_data( {
100 action: 'mainwp_checkwp',
101 name: name,
102 url: url,
103 admin: jQuery( '#mainwp_managesites_add_wpadmin' ).val(),
104 } );
105
106 jQuery.post( ajaxurl, data, function ( res_things ) {
107 response = res_things.response;
108 response = jQuery.trim( response );
109
110 var url = jQuery( '#mainwp_managesites_add_wpurl_protocol' ).val() + '://' + jQuery( '#mainwp_managesites_add_wpurl' ).val();
111 if ( url.substr( -1 ) != '/' ) {
112 url += '/';
113 }
114
115 url = url.replace( /"/g, '&quot;' );
116
117 if ( response == 'HTTPERROR' ) {
118 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>.' );
119 } else if ( response == 'NOMAINWP' ) {
120 errors.push( 'MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a> for help.' );
121 } else if ( response.substr( 0, 5 ) == 'ERROR' ) {
122 if ( response.length == 5 ) {
123 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>.' );
124 } else {
125 errors.push( response.substr( 6 ) );
126 }
127 } else if ( response == 'OK' ) {
128 jQuery( '#mainwp_managesites_add' ).attr( 'disabled', 'true' );
129
130 var name = jQuery( '#mainwp_managesites_add_wpname' ).val();
131 name = name.replace( /"/g, '&quot;' );
132 var group_ids = '';
133 var data = mainwp_setup_secure_data( {
134 action: 'mainwp_addwp',
135 managesites_add_wpname: name,
136 managesites_add_wpurl: url,
137 managesites_add_wpadmin: jQuery( '#mainwp_managesites_add_wpadmin' ).val(),
138 managesites_add_uniqueId: jQuery( '#mainwp_managesites_add_uniqueId' ).val(),
139 groupids: group_ids,
140 qsw_page: true,
141 } );
142
143 // to support add client reports tokens values
144 jQuery( "input[name^='creport_token_']" ).each( function(){
145 var tname = jQuery( this ).attr( 'name' );
146 var tvalue = jQuery( this ).val();
147 data[tname] = tvalue;
148 } );
149
150 // support hooks fields
151 jQuery( ".mainwp_addition_fields_addsite input" ).each( function() {
152 var tname = jQuery( this ).attr( 'name' );
153 var tvalue = jQuery( this ).val();
154 data[tname] = tvalue;
155 } );
156
157 jQuery.post( ajaxurl, data, function ( res_things ) {
158
159 if ( res_things.error ) {
160 response = res_things.error;
161 } else {
162 response = res_things.response;
163 }
164
165 response = jQuery.trim( response );
166
167 jQuery( '#mainwp-message-zone' ).hide();
168 jQuery( '#mainwp-info-zone' ).hide();
169
170 if ( response.substr( 0, 5 ) == 'ERROR' ) {
171 jQuery( '#mainwp-message-zone' ).removeClass( 'green yellow green' );
172 jQuery( '#mainwp-message-zone' ).html( response.substr( 6 ) ).addClass( 'red' ).show();
173 } else {
174 //Message the WP was added
175 jQuery( '#mainwp-message-zone' ).removeClass( 'green yellow green' );
176 jQuery( '#mainwp-message-zone' ).html( response ).addClass( 'green' ).show();
177 jQuery( '#mainwp-info-zone' ).html( 'You can also add more sites now or <a href="admin.php?page=mainwp-setup&step=monitoring" class="ui blue mini button">Continue with Quick Setup Wizard</a>' ).show();
178
179 //Reset fields
180 jQuery( '#mainwp_managesites_add_wpname' ).val( '' );
181 jQuery( '#mainwp_managesites_add_wpurl' ).val( '' );
182 jQuery( '#mainwp_managesites_add_wpurl_protocol' ).val( 'https' );
183 jQuery( '#mainwp_managesites_add_wpadmin' ).val( '' );
184 jQuery( '#mainwp_managesites_add_uniqueId' ).val( '' );
185
186 jQuery( "input[name^='creport_token_']" ).each( function() {
187 jQuery( this ).val( '' );
188 } );
189
190 // support hooks fields
191 jQuery( ".mainwp_addition_fields_addsite input" ).each( function() {
192 jQuery( this ).val('');
193 } );
194 }
195
196 jQuery( '#mainwp_managesites_add' ).removeAttr( 'disabled' );
197 }, 'json' );
198 }
199 if ( errors.length > 0 ) {
200 jQuery( '#mainwp-message-zone' ).removeClass( 'green yellow green' );
201 jQuery( '#mainwp-message-zone' ).hide();
202 jQuery( '#mainwp_managesites_add' ).removeAttr( 'disabled' );
203 jQuery( '#mainwp-message-zone' ).html( errors.join( '<br />' ) ).addClass( 'red' ).show();
204 }
205 }, 'json' );
206 }
207 };
208
209 // Check if the URL field is valid value
210 function isUrl( s ) {
211 var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
212 return regexp.test( s );
213 }
214
215 mainwp_setup_secure_data = function ( data ) {
216 if ( data['action'] == undefined )
217 return data;
218
219 data['security'] = jQuery( '#nonce_secure_data' ).attr( data['action'] );
220
221 return data;
222 };
223