| @@ -1,516 +1,574 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * MainWP_User.page |
| 3 | 3 | */ |
| 4 | -var userCountSent = 0; | |
| 5 | -var userCountReceived = 0; | |
| 6 | -jQuery( document ).ready( function () { | |
| 4 | +let userCountSent = 0; | |
| 5 | +let userCountReceived = 0; | |
| 7 | 6 | |
| 8 | - // Fetch users | |
| 9 | - jQuery( document ).on( 'click', '#mainwp_show_users', function () { | |
| 7 | +let updateUsersBulkActionsState = function () { | |
| 8 | + let checkedCount = jQuery('#mainwp-users-table input[name="user[]"]:checked').length; | |
| 9 | + let dropdown = jQuery('#mainwp-manage-users #mainwp-bulk-actions'); | |
| 10 | + let applyButton = jQuery('#mainwp-do-users-bulk-actions'); | |
| 11 | + | |
| 12 | + if (checkedCount > 0) { | |
| 13 | + dropdown.removeClass('disabled'); | |
| 14 | + dropdown.parent('.ui.dropdown').removeClass('disabled'); | |
| 15 | + applyButton.removeClass('disabled'); | |
| 16 | + } else { | |
| 17 | + dropdown.addClass('disabled'); | |
| 18 | + dropdown.parent('.ui.dropdown').addClass('disabled'); | |
| 19 | + dropdown.dropdown('set selected', 'none'); | |
| 20 | + applyButton.addClass('disabled'); | |
| 21 | + } | |
| 22 | +}; | |
| 23 | + | |
| 24 | +let import_user_stop_by_user = false; | |
| 25 | +let import_user_current_line_number = 0; | |
| 26 | +let import_user_total_import = 0; | |
| 27 | +let import_user_count_created_users = 0; | |
| 28 | +let import_user_count_create_fails = 0; | |
| 29 | + | |
| 30 | +jQuery(function () { | |
| 31 | + | |
| 32 | + updateUsersBulkActionsState(); | |
| 33 | + | |
| 34 | + jQuery(document).on('change', '#mainwp-users-table .check-column INPUT:checkbox', function () { | |
| 35 | + updateUsersBulkActionsState(); | |
| 36 | + }); | |
| 37 | + | |
| 38 | + // Fetch users | |
| 39 | + jQuery(document).on('click', '#mainwp_show_users', function () { | |
| 10 | 40 | mainwp_fetch_users(); |
| 11 | - } ); | |
| 41 | + }); | |
| 12 | 42 | |
| 13 | - // Delete single user | |
| 14 | - jQuery( document ).on( 'click', '.user_submitdelete', function () { | |
| 15 | - var confirmation = confirm( 'Are you sure you want to proceed?' ); | |
| 43 | + // Delete single user | |
| 44 | + jQuery(document).on('click', '.user_submitdelete', function () { | |
| 45 | + let confirmation = confirm('Are you sure you want to proceed?'); | |
| 16 | 46 | |
| 17 | - if ( confirmation == true ) { | |
| 18 | - mainwpuser_postAction( jQuery( this ), 'delete' ); | |
| 19 | - return; | |
| 20 | - } | |
| 47 | + if (confirmation) { | |
| 48 | + mainwpuser_postAction(jQuery(this), 'delete'); | |
| 49 | + return; | |
| 50 | + } | |
| 21 | 51 | |
| 22 | 52 | return false; |
| 23 | - } ); | |
| 53 | + }); | |
| 24 | 54 | |
| 25 | - // Edit single user | |
| 26 | - jQuery( document ).on( 'click', '.user_getedit', function () { | |
| 27 | - jQuery( 'td.check-column input[type="checkbox"]' ).each( function () { | |
| 55 | + // Edit single user | |
| 56 | + jQuery(document).on('click', '.user_getedit', function () { | |
| 57 | + jQuery('td.check-column input[type="checkbox"]').each(function () { | |
| 28 | 58 | this.checked = false; |
| 29 | - } ); | |
| 59 | + }); | |
| 30 | 60 | mainwp_edit_users_box_init(); |
| 31 | - jQuery( '#mainwp-edit-users-modal' ).modal( 'setting', 'closable', false ).modal('show'); | |
| 32 | - mainwpuser_postAction( jQuery( this ), 'edit' ); | |
| 61 | + jQuery('#mainwp-edit-users-modal').modal('setting', 'closable', false).modal('show'); | |
| 62 | + mainwpuser_postAction(jQuery(this), 'edit'); | |
| 33 | 63 | return false; |
| 34 | - } ); | |
| 64 | + }); | |
| 35 | 65 | |
| 36 | - // Trigger Manage Users bulk actions | |
| 37 | - jQuery( document ).on( 'click', '#mainwp-do-users-bulk-actions', function () { | |
| 38 | - var action = jQuery( '#mainwp-bulk-actions' ).val(); | |
| 39 | - if ( action == 'none' ) | |
| 40 | - return false; | |
| 66 | + // Trigger Manage Users bulk actions | |
| 67 | + jQuery(document).on('click', '#mainwp-do-users-bulk-actions', function () { | |
| 68 | + let action = jQuery('#mainwp-bulk-actions').val(); | |
| 69 | + if (action == 'none') | |
| 70 | + return; | |
| 41 | 71 | |
| 42 | - var tmp = jQuery( "input[name='user[]']:checked" ); | |
| 72 | + let tmp = jQuery("input[name='user[]']:checked"); | |
| 43 | 73 | userCountSent = tmp.length; |
| 44 | 74 | |
| 45 | - if ( userCountSent == 0 ) | |
| 46 | - return false; | |
| 75 | + if (userCountSent == 0) | |
| 76 | + return; | |
| 47 | 77 | |
| 48 | - var _callback = function() { | |
| 78 | + let _callback = function () { | |
| 49 | 79 | |
| 50 | - if ( action == 'edit' ) { | |
| 51 | - jQuery( '#mainwp-edit-users-modal' ).modal( 'setting', 'closable', false ).modal('show'); | |
| 80 | + if (action == 'edit') { | |
| 81 | + jQuery('#mainwp-edit-users-modal').modal('setting', 'closable', false).modal('show'); | |
| 52 | 82 | mainwp_edit_users_box_init(); |
| 53 | 83 | return; |
| 54 | 84 | } |
| 55 | 85 | |
| 56 | - jQuery( '#mainwp-do-users-bulk-actions' ).attr( 'disabled', 'true' ); | |
| 86 | + jQuery('#mainwp-do-users-bulk-actions').attr('disabled', 'true'); | |
| 57 | 87 | tmp.each( |
| 58 | - function ( index, elem ) { | |
| 59 | - mainwpuser_postAction( elem, action ); | |
| 88 | + function (index, elem) { | |
| 89 | + mainwpuser_postAction(elem, action); | |
| 60 | 90 | } |
| 61 | 91 | ); |
| 62 | 92 | }; |
| 63 | 93 | |
| 64 | - if ( action == 'delete' ) { | |
| 65 | - var msg = __( 'You are about to delete %1 user(s). Are you sure you want to proceed?', userCountSent ); | |
| 66 | - mainwp_confirm( msg, _callback ); | |
| 67 | - return false; | |
| 94 | + if (action == 'delete') { | |
| 95 | + let msg = MainWP.I18n.t('You are about to delete %1 user(s). Are you sure you want to proceed?', userCountSent); | |
| 96 | + mainwp_confirm(msg, _callback); | |
| 97 | + return; | |
| 68 | 98 | } |
| 69 | 99 | |
| 70 | 100 | _callback(); |
| 101 | + }); | |
| 71 | 102 | |
| 72 | - return false; | |
| 73 | - } ); | |
| 74 | 103 | |
| 75 | - | |
| 76 | - jQuery( document ).on( 'click', '#mainwp_btn_update_user', function () { | |
| 77 | - var errors = [ ]; | |
| 78 | - var tmp = jQuery( "input[name='user[]']:checked" ); | |
| 104 | + jQuery(document).on('click', '#mainwp_btn_update_user', function () { | |
| 105 | + let errors = []; | |
| 106 | + let tmp = jQuery("input[name='user[]']:checked"); | |
| 79 | 107 | userCountSent = tmp.length; |
| 80 | 108 | |
| 81 | - if ( userCountSent == 0 ) { | |
| 82 | - errors.push( __( 'Please search and select users.' ) ); | |
| 109 | + if (userCountSent == 0) { | |
| 110 | + errors.push(MainWP.I18n.t('Please search and select users.')); | |
| 83 | 111 | } |
| 84 | 112 | |
| 85 | - if ( errors.length > 0 ) { | |
| 86 | - jQuery( '#mainwp_update_password_error' ).html( errors.join( '<br />' ) ); | |
| 87 | - jQuery( '#mainwp_update_password_error' ).show(); | |
| 88 | - return false; | |
| 113 | + if (errors.length > 0) { | |
| 114 | + jQuery('#mainwp_update_password_error').html(errors.join('<br />')); | |
| 115 | + jQuery('#mainwp_update_password_error').show(); | |
| 116 | + return; | |
| 89 | 117 | } |
| 90 | 118 | |
| 91 | - jQuery( '#mainwp_update_password_error' ).hide(); | |
| 92 | - jQuery( '#mainwp_users_updating' ).show(); | |
| 119 | + jQuery('#mainwp_update_password_error').hide(); | |
| 120 | + jQuery('#mainwp_users_updating').show(); | |
| 93 | 121 | |
| 94 | - jQuery( '#mainwp-do-users-bulk-actions' ).attr( 'disabled', 'true' ); | |
| 95 | - jQuery( '#mainwp_btn_update_user' ).attr( 'disabled', 'true' ); | |
| 122 | + jQuery('#mainwp-do-users-bulk-actions').attr('disabled', 'true'); | |
| 123 | + jQuery('#mainwp_btn_update_user').attr('disabled', 'true'); | |
| 96 | 124 | |
| 97 | 125 | tmp.each( |
| 98 | - function ( index, elem ) { | |
| 99 | - mainwpuser_postAction( elem, 'update_user' ); | |
| 126 | + function (index, elem) { | |
| 127 | + mainwpuser_postAction(elem, 'update_user'); | |
| 100 | 128 | } |
| 101 | 129 | ); |
| 130 | + }); | |
| 102 | 131 | |
| 132 | + jQuery(document).on('click', '#bulk_updateadminpassword', function () { | |
| 133 | + mainwp_confirm( | |
| 134 | + 'You are about to update administrator passwords on selected sites. This will overwrite the current password for the admin account used for connection.', | |
| 135 | + function () { | |
| 136 | + jQuery('#mainwp-update-admin-password-form').submit() | |
| 137 | + } | |
| 138 | + ); | |
| 103 | 139 | return false; |
| 104 | - } ); | |
| 105 | -} ); | |
| 140 | + }); | |
| 141 | +}); | |
| 106 | 142 | |
| 107 | -mainwp_edit_users_box_init = function () { | |
| 143 | +let mainwp_edit_users_box_init = function () { | |
| 108 | 144 | |
| 109 | - jQuery( 'form#update_user_profile select#role option[value="donotupdate"]' ).prop( 'selected', true ); | |
| 110 | - jQuery( 'form#update_user_profile select#role' ).prop("disabled", false); | |
| 111 | - jQuery( 'form#update_user_profile input#first_name' ).val( '' ); | |
| 112 | - jQuery( 'form#update_user_profile input#last_name' ).val( '' ); | |
| 113 | - jQuery( 'form#update_user_profile input#nickname' ).val( '' ); | |
| 114 | - jQuery( 'form#update_user_profile input#email' ).val( '' ); | |
| 115 | - jQuery( 'form#update_user_profile input#url' ).val( '' ); | |
| 116 | - jQuery( 'form#update_user_profile select#display_name' ).empty().attr( 'disabled', 'disabled' ); | |
| 117 | - jQuery( 'form#update_user_profile #description' ).val( '' ); | |
| 118 | - jQuery( 'form#update_user_profile input#password' ).val( '' ); | |
| 145 | + jQuery('form#update_user_profile select#role option[value="donotupdate"]').prop('selected', true); | |
| 146 | + jQuery('form#update_user_profile select#role').prop("disabled", false); | |
| 147 | + jQuery('form#update_user_profile input#first_name').val(''); | |
| 148 | + jQuery('form#update_user_profile input#last_name').val(''); | |
| 149 | + jQuery('form#update_user_profile input#nickname').val(''); | |
| 150 | + jQuery('form#update_user_profile input#email').val(''); | |
| 151 | + jQuery('form#update_user_profile input#url').val(''); | |
| 152 | + jQuery('form#update_user_profile select#display_name').empty().attr('disabled', 'disabled'); | |
| 153 | + jQuery('form#update_user_profile #description').val(''); | |
| 154 | + jQuery('form#update_user_profile input#password').val(''); | |
| 119 | 155 | }; |
| 120 | 156 | |
| 121 | -mainwpuser_postAction = function ( elem, what ) { | |
| 122 | - var rowElement = jQuery( elem ).parents( 'tr' ); | |
| 123 | - var userId = rowElement.find( '.userId' ).val(); | |
| 124 | - var userName = rowElement.find( '.userName' ).val(); | |
| 125 | - var websiteId = rowElement.find( '.websiteId' ).val(); | |
| 157 | +let mainwpuser_postAction = function (elem, what) { | |
| 158 | + let rowElement = jQuery(elem).parents('tr'); | |
| 159 | + let userId = rowElement.find('.userId').val(); | |
| 160 | + let userName = rowElement.find('.userName').val(); | |
| 161 | + let websiteId = rowElement.find('.websiteId').val(); | |
| 126 | 162 | |
| 127 | - var data = mainwp_secure_data( { | |
| 163 | + let data = mainwp_secure_data({ | |
| 128 | 164 | action: 'mainwp_user_' + what, |
| 129 | 165 | userId: userId, |
| 130 | 166 | userName: userName, |
| 131 | 167 | websiteId: websiteId, |
| 132 | - update_password: encodeURIComponent( jQuery('#password').val() ) // to fix | |
| 133 | - } ); | |
| 168 | + update_password: encodeURIComponent(jQuery('#password').val()) // to fix | |
| 169 | + }); | |
| 134 | 170 | |
| 135 | - if ( what == 'update_user' ) { | |
| 136 | - data['user_data'] = jQuery( 'form#update_user_profile' ).serialize(); | |
| 171 | + if (what == 'update_user') { | |
| 172 | + data['user_data'] = jQuery('form#update_user_profile').serialize(); | |
| 137 | 173 | } |
| 138 | 174 | |
| 139 | - rowElement.find( '.row-actions' ).hide(); | |
| 140 | - rowElement.find( '.row-actions-working' ).show(); | |
| 141 | - jQuery.post( ajaxurl, data, function ( response ) { | |
| 142 | - if ( what == 'edit' && response && response.user_data ) { | |
| 143 | - var roles_filter = [ 'administrator', 'subscriber', 'contributor', 'author', 'editor' ]; | |
| 144 | - var disabled_change_role = false; | |
| 145 | - if ( response.user_data.role == '' || jQuery.inArray( response.user_data.role, roles_filter ) === -1 ) { | |
| 146 | - jQuery( 'form#update_user_profile select#role option[value="donotupdate"]' ).prop( 'selected', true ); | |
| 175 | + rowElement.find('.row-actions').hide(); | |
| 176 | + if (what === 'delete') { | |
| 177 | + rowElement.html('<td colspan="8"><i class="ui active inline loader tiny"></i> Please wait</td>'); | |
| 178 | + } | |
| 179 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. | |
| 180 | + if (what == 'edit' && response?.user_data) { | |
| 181 | + let roles_filter = ['administrator', 'subscriber', 'contributor', 'author', 'editor']; | |
| 182 | + let disabled_change_role = false; | |
| 183 | + if (response.user_data.role == '' || jQuery.inArray(response.user_data.role, roles_filter) === -1) { | |
| 184 | + jQuery('form#update_user_profile select#role option[value="donotupdate"]').prop('selected', true); | |
| 147 | 185 | disabled_change_role = true; |
| 148 | 186 | } else { |
| 149 | - jQuery( 'form#update_user_profile select#role option[value="' + response.user_data.role + '"]' ).prop( 'selected', true ); | |
| 150 | - if ( response.is_secure_admin ) { | |
| 187 | + jQuery('form#update_user_profile select#role option[value="' + response.user_data.role + '"]').prop('selected', true); | |
| 188 | + if (response.is_secure_admin) { | |
| 151 | 189 | disabled_change_role = true; |
| 152 | 190 | } |
| 153 | 191 | } |
| 154 | 192 | |
| 155 | - if ( disabled_change_role ) { | |
| 156 | - jQuery( 'form#update_user_profile select#role' ).attr( 'disabled', 'disabled' ); | |
| 193 | + if (disabled_change_role) { | |
| 194 | + jQuery('form#update_user_profile select#role').attr('disabled', 'disabled'); | |
| 157 | 195 | } else { |
| 158 | - jQuery( 'form#update_user_profile select#role' ).prop("disabled", false); | |
| 196 | + jQuery('form#update_user_profile select#role').prop("disabled", false); | |
| 159 | 197 | } |
| 160 | 198 | |
| 161 | - jQuery( 'form#update_user_profile input#first_name' ).val( response.user_data.first_name ); | |
| 162 | - jQuery( 'form#update_user_profile input#last_name' ).val( response.user_data.last_name ); | |
| 163 | - jQuery( 'form#update_user_profile input#nickname' ).val( response.user_data.nickname ); | |
| 164 | - jQuery( 'form#update_user_profile input#email' ).val( response.user_data.user_email ); | |
| 165 | - jQuery( 'form#update_user_profile input#url' ).val( response.user_data.user_url ); | |
| 166 | - jQuery( 'form#update_user_profile select#display_name' ).empty(); | |
| 167 | - jQuery( 'form#update_user_profile select#display_name' ).prop("disabled", false); | |
| 168 | - if ( response.user_data.public_display ) { | |
| 169 | - jQuery.each( response.user_data.public_display, function ( index, value ) { | |
| 170 | - var o = new Option( value ); | |
| 171 | - if ( value == response.user_data.display_name ) { | |
| 199 | + jQuery('form#update_user_profile input#first_name').val(response.user_data.first_name); | |
| 200 | + jQuery('form#update_user_profile input#last_name').val(response.user_data.last_name); | |
| 201 | + jQuery('form#update_user_profile input#nickname').val(response.user_data.nickname); | |
| 202 | + jQuery('form#update_user_profile input#email').val(response.user_data.user_email); | |
| 203 | + jQuery('form#update_user_profile input#url').val(response.user_data.user_url); | |
| 204 | + jQuery('form#update_user_profile select#display_name').empty(); | |
| 205 | + jQuery('form#update_user_profile select#display_name').prop("disabled", false); | |
| 206 | + if (response.user_data.public_display) { | |
| 207 | + jQuery.each(response.user_data.public_display, function (index, value) { | |
| 208 | + let o = new Option(value); | |
| 209 | + if (value == response.user_data.display_name) { | |
| 172 | 210 | o.selected = true; |
| 173 | 211 | } |
| 174 | - jQuery( 'form#update_user_profile select#display_name' ).append( o ); | |
| 175 | - } ); | |
| 176 | - jQuery( 'form#update_user_profile select#display_name option[value="' + response.user_data.display_name + '"]' ).prop( 'selected', true ); | |
| 212 | + jQuery('form#update_user_profile select#display_name').append(o); | |
| 213 | + }); | |
| 214 | + jQuery('form#update_user_profile select#display_name option[value="' + response.user_data.display_name + '"]').prop('selected', true); | |
| 177 | 215 | } |
| 178 | 216 | |
| 179 | - jQuery( 'form#update_user_profile #description' ).val( response.user_data.description ); | |
| 180 | - rowElement.find( 'td.check-column input[type="checkbox"]' )[0].checked = true; | |
| 181 | - rowElement.find( '.row-actions-working' ).hide(); | |
| 217 | + jQuery('form#update_user_profile #description').val(response.user_data.description); | |
| 218 | + rowElement.find('td.check-column input[type="checkbox"]')[0].checked = true; | |
| 182 | 219 | return; |
| 183 | 220 | } |
| 184 | 221 | |
| 185 | - if ( response.result ) { | |
| 186 | - rowElement.html( '<td colspan="8"><i class="check circle icon"></i> ' + response.result + '</td>' ); | |
| 222 | + if (response.result) { | |
| 223 | + rowElement.html('<td colspan="8"><i class="green check icon"></i> ' + response.result + '</td>'); | |
| 187 | 224 | } else { |
| 188 | - rowElement.find( '.row-actions-working' ).hide(); | |
| 225 | + rowElement.html('<td colspan="8"><i class="times red icon"></i> Undefined error. Please try again.</td>'); | |
| 189 | 226 | } |
| 227 | + | |
| 190 | 228 | userCountReceived++; |
| 191 | - if ( userCountReceived == userCountSent ) { | |
| 229 | + if (userCountReceived == userCountSent) { | |
| 192 | 230 | userCountReceived = 0; |
| 193 | 231 | userCountSent = 0; |
| 194 | - jQuery( '#mainwp-do-users-bulk-actions' ).prop("disabled", false); | |
| 232 | + jQuery('#mainwp-do-users-bulk-actions').prop("disabled", false); | |
| 195 | 233 | |
| 196 | - jQuery( '#mainwp_btn_update_user' ).prop("disabled", false); | |
| 197 | - jQuery( '#mainwp_users_updating' ).hide(); | |
| 234 | + jQuery('#mainwp_btn_update_user').prop("disabled", false); | |
| 235 | + jQuery('#mainwp_users_updating').hide(); | |
| 198 | 236 | |
| 199 | 237 | |
| 200 | - if ( what == 'update_user' || what == 'delete' ) { | |
| 201 | - jQuery( '#mainwp_users_loading_info' ).show(); | |
| 202 | - //jQuery( '#mainwp-update-users-box' ).hide(); | |
| 203 | - jQuery( '#mainwp-edit-users-modal' ).modal('hide'); | |
| 238 | + if (what == 'update_user' || what == 'delete') { | |
| 239 | + jQuery('#mainwp_users_loading_info').show(); | |
| 240 | + jQuery('#mainwp-edit-users-modal').modal('hide'); | |
| 204 | 241 | mainwp_fetch_users(); |
| 205 | 242 | } |
| 206 | 243 | } |
| 207 | - }, 'json' ); | |
| 244 | + }, 'json'); | |
| 208 | 245 | |
| 209 | 246 | return false; |
| 210 | 247 | }; |
| 211 | 248 | |
| 212 | 249 | // Fetch users from child sites |
| 213 | -mainwp_fetch_users = function () { | |
| 214 | - var errors = [ ]; | |
| 215 | - var selected_sites = [ ]; | |
| 216 | - var selected_groups = [ ]; | |
| 217 | - var selected_clients = []; | |
| 250 | +let mainwp_fetch_users = function () { | |
| 251 | + let errors = []; | |
| 252 | + let selected_sites = []; | |
| 253 | + let selected_groups = []; | |
| 254 | + let selected_clients = []; | |
| 218 | 255 | |
| 219 | - if ( jQuery( '#select_by' ).val() == 'site' ) { | |
| 220 | - jQuery( "input[name='selected_sites[]']:checked" ).each( function () { | |
| 221 | - selected_sites.push( jQuery( this ).val() ); | |
| 222 | - } ); | |
| 223 | - if ( selected_sites.length == 0 ) { | |
| 224 | - errors.push( __( 'Please select at least one website or group or clients.' ) ); | |
| 256 | + if (jQuery('input[name="select_by"]').val() == 'site') { | |
| 257 | + jQuery("input[name='selected_sites[]']:checked").each(function () { | |
| 258 | + selected_sites.push(jQuery(this).val()); | |
| 259 | + }); | |
| 260 | + if (selected_sites.length == 0) { | |
| 261 | + errors.push(MainWP.I18n.t('Please select at least one website or group or clients.')); | |
| 262 | + } | |
| 263 | + } else if (jQuery('input[name="select_by"]').val() == 'client') { | |
| 264 | + jQuery("input[name='selected_clients[]']:checked").each(function () { | |
| 265 | + selected_clients.push(jQuery(this).val()); | |
| 266 | + }); | |
| 267 | + if (selected_clients.length == 0) { | |
| 268 | + errors.push(MainWP.I18n.t('Please select at least one website or group or clients.')); | |
| 269 | + } | |
| 270 | + } else { | |
| 271 | + jQuery("input[name='selected_groups[]']:checked").each(function () { | |
| 272 | + selected_groups.push(jQuery(this).val()); | |
| 273 | + }); | |
| 274 | + if (selected_groups.length == 0) { | |
| 275 | + errors.push(MainWP.I18n.t('Please select at least one website or group or clients.')); | |
| 276 | + } | |
| 225 | 277 | } |
| 226 | - } else if ( jQuery( '#select_by' ).val() == 'client' ) { | |
| 227 | - jQuery( "input[name='selected_clients[]']:checked" ).each( function () { | |
| 228 | - selected_clients.push( jQuery( this ).val() ); | |
| 229 | - } ); | |
| 230 | - if ( selected_clients.length == 0 ) { | |
| 231 | - errors.push( __( 'Please select at least one website or group or clients.' ) ); | |
| 278 | + | |
| 279 | + let role = ""; | |
| 280 | + let roles = jQuery("#mainwp_user_roles").dropdown("get value"); | |
| 281 | + if (roles !== null) { | |
| 282 | + role = roles.join(','); | |
| 232 | 283 | } |
| 233 | - } else{ | |
| 234 | - jQuery( "input[name='selected_groups[]']:checked" ).each( function () { | |
| 235 | - selected_groups.push( jQuery( this ).val() ); | |
| 236 | - } ); | |
| 237 | - if ( selected_groups.length == 0 ) { | |
| 238 | - errors.push( __( 'Please select at least one website or group or clients.' ) ); | |
| 284 | + | |
| 285 | + if (errors.length > 0) { | |
| 286 | + mainwp_set_message_zone('#mainwp-message-zone', errors.join('<br />'), 'yellow'); | |
| 287 | + jQuery('#mainwp_users_loading_info').hide(); | |
| 288 | + return; | |
| 289 | + } else { | |
| 290 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 239 | 291 | } |
| 240 | - } | |
| 241 | 292 | |
| 242 | - var role = ""; | |
| 243 | - var roles = jQuery("#mainwp_user_roles").dropdown("get value"); | |
| 244 | - if (roles !== null) { | |
| 245 | - role = roles.join(','); | |
| 246 | - } | |
| 293 | + let name = jQuery('#mainwp_search_users').val(); | |
| 247 | 294 | |
| 248 | - if ( errors.length > 0 ) { | |
| 249 | - jQuery( '#mainwp-message-zone' ).html( errors.join( '<br />' ) ); | |
| 250 | - jQuery( '#mainwp-message-zone' ).show(); | |
| 251 | - jQuery( '#mainwp-message-zone' ).addClass( 'yellow '); | |
| 252 | - jQuery( '#mainwp_users_loading_info' ).hide(); | |
| 253 | - return; | |
| 254 | - } else { | |
| 255 | - jQuery( '#mainwp-message-zone' ).html( "" ); | |
| 256 | - jQuery( '#mainwp-message-zone' ).removeClass( 'yellow '); | |
| 257 | - jQuery( '#mainwp-message-zone' ).hide(); | |
| 258 | - } | |
| 295 | + let data = mainwp_secure_data({ | |
| 296 | + action: 'mainwp_users_search', | |
| 297 | + urole: role, | |
| 298 | + search: name, | |
| 299 | + 'groups[]': selected_groups, | |
| 300 | + 'sites[]': selected_sites, | |
| 301 | + 'clients[]': selected_clients | |
| 302 | + }); | |
| 259 | 303 | |
| 260 | - var name = jQuery( '#mainwp_search_users' ).val(); | |
| 304 | + jQuery('#mainwp-loading-users-row').show(); | |
| 261 | 305 | |
| 262 | - var data = mainwp_secure_data( { | |
| 263 | - action: 'mainwp_users_search', | |
| 264 | - role: role, | |
| 265 | - search: name, | |
| 266 | - 'groups[]': selected_groups, | |
| 267 | - 'sites[]': selected_sites, | |
| 268 | - 'clients[]': selected_clients | |
| 269 | - } ); | |
| 270 | - | |
| 271 | - jQuery( '#mainwp-loading-users-row' ).show(); | |
| 272 | - | |
| 273 | - jQuery.post( ajaxurl, data, function ( response ) { | |
| 274 | - response = response.trim(); | |
| 275 | - jQuery( '#mainwp-loading-users-row' ).hide(); | |
| 276 | - jQuery( '#mainwp_users_loading_info' ).hide(); | |
| 277 | - jQuery( '#mainwp_users_main' ).show(); | |
| 278 | - // var matches = ( response == null ? null : response.match( /user\[\]/g ) ); | |
| 279 | - // jQuery( '#mainwp_users_total' ).html( matches == null ? 0 : matches.length ); | |
| 280 | - jQuery( '#mainwp_users_wrap_table' ).html( response ); | |
| 281 | - // re-initialize datatable | |
| 282 | - jQuery("#mainwp-users-table").DataTable().destroy(); | |
| 283 | - jQuery('#mainwp-users-table').DataTable( { | |
| 284 | - "responsive" : true, | |
| 285 | - "colReorder": { | |
| 286 | - fixedColumnsLeft: 1, | |
| 287 | - fixedColumnsRight: 1 | |
| 288 | - }, | |
| 289 | - "stateSave": true, | |
| 290 | - "pagingType": "full_numbers", | |
| 291 | - "order": [], | |
| 292 | - "scrollX" : true, | |
| 293 | - "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ], | |
| 294 | - "columnDefs": [ { | |
| 295 | - "targets": 'no-sort', | |
| 296 | - "orderable": false | |
| 297 | - } ], | |
| 298 | - "preDrawCallback": function() { | |
| 299 | - jQuery( '#mainwp_users_wrap_table table .ui.dropdown' ).dropdown(); | |
| 300 | - jQuery( '#mainwp_users_wrap_table table .ui.checkbox' ).checkbox(); | |
| 301 | - mainwp_datatable_fix_menu_overflow(); | |
| 302 | - mainwp_table_check_columns_init(); // ajax: to fix checkbox all. | |
| 303 | - } | |
| 304 | - } ); | |
| 305 | - } ); | |
| 306 | + jQuery.post(ajaxurl, data, function (response) { | |
| 307 | + response = response.trim(); | |
| 308 | + jQuery('#mainwp-loading-users-row').hide(); | |
| 309 | + jQuery('#mainwp_users_loading_info').hide(); | |
| 310 | + jQuery('#mainwp_users_main').show(); | |
| 311 | + jQuery('#mainwp_users_wrap_table').html(response); | |
| 312 | + // re-initialize datatable | |
| 313 | + jQuery("#mainwp-users-table").DataTable().destroy(); | |
| 314 | + jQuery('#mainwp-users-table').DataTable({ | |
| 315 | + "responsive": true, | |
| 316 | + "colReorder": { columns: ":not(.check-column):not(#mainwp-users-actions)" }, | |
| 317 | + "stateSave": true, | |
| 318 | + "pagingType": "full_numbers", | |
| 319 | + "order": [], | |
| 320 | + "scrollX": true, | |
| 321 | + "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], | |
| 322 | + "columnDefs": [{ | |
| 323 | + "targets": 'no-sort', | |
| 324 | + "orderable": false | |
| 325 | + }], | |
| 326 | + "drawCallback": function () { | |
| 327 | + setTimeout(() => { | |
| 328 | + jQuery('#mainwp-users-table .ui.dropdown').dropdown(); | |
| 329 | + jQuery('#mainwp-users-table .ui.checkbox').checkbox(); | |
| 330 | + mainwp_datatable_fix_menu_overflow('#mainwp-users-table'); | |
| 331 | + mainwp_table_check_columns_init(); // ajax: to fix checkbox all. | |
| 332 | + updateUsersBulkActionsState(); | |
| 333 | + }, 1000); | |
| 334 | + }, | |
| 335 | + select: { | |
| 336 | + items: 'row', | |
| 337 | + style: 'multi+shift', | |
| 338 | + selector: 'tr>td:not(.not-selectable)' | |
| 339 | + } | |
| 340 | + }).on('select', function (e, dt, type, indexes) { | |
| 341 | + if ('row' == type) { | |
| 342 | + dt.rows(indexes) | |
| 343 | + .nodes() | |
| 344 | + .to$().find('td.check-column .ui.checkbox').checkbox('set checked'); | |
| 345 | + updateUsersBulkActionsState(); | |
| 346 | + } | |
| 347 | + }).on('deselect', function (e, dt, type, indexes) { | |
| 348 | + if ('row' == type) { | |
| 349 | + dt.rows(indexes) | |
| 350 | + .nodes() | |
| 351 | + .to$().find('td.check-column .ui.checkbox').checkbox('set unchecked'); | |
| 352 | + updateUsersBulkActionsState(); | |
| 353 | + } | |
| 354 | + }).on('columns-reordered', function () { | |
| 355 | + setTimeout(() => { | |
| 356 | + jQuery('#mainwp-users-table .ui.dropdown').dropdown(); | |
| 357 | + jQuery('#mainwp-users-table .ui.checkbox').checkbox(); | |
| 358 | + mainwp_datatable_fix_menu_overflow('#mainwp-users-table'); | |
| 359 | + mainwp_table_check_columns_init(); // ajax: to fix checkbox all. | |
| 360 | + }, 1000); | |
| 361 | + }); | |
| 362 | + }); | |
| 306 | 363 | }; |
| 307 | 364 | |
| 308 | 365 | |
| 309 | 366 | |
| 310 | - | |
| 311 | 367 | /** |
| 312 | 368 | * Bulk upload new user |
| 313 | 369 | */ |
| 314 | -var import_user_stop_by_user = false; | |
| 315 | -var import_user_current_line_number = 0; | |
| 316 | -var import_user_total_import = 0; | |
| 317 | -var import_user_count_created_users = 0; | |
| 318 | -var import_user_count_create_fails = 0; | |
| 370 | +jQuery(function () { | |
| 371 | + import_user_total_import = jQuery('#import_user_total_import').val(); | |
| 319 | 372 | |
| 320 | -jQuery( document ).ready( function () { | |
| 321 | - import_user_total_import = jQuery( '#import_user_total_import' ).val(); | |
| 322 | - | |
| 323 | - jQuery( '#import_user_btn_import' ).on( 'click', function () { | |
| 324 | - if ( import_user_stop_by_user == false ) { | |
| 325 | - import_user_stop_by_user = true; | |
| 326 | - jQuery( '#import_user_import_logging .log' ).append( _( 'Paused import by user.' ) + "\n" ); | |
| 327 | - jQuery( '#import_user_btn_import' ).val( __( 'Continue' ) ); | |
| 328 | - jQuery( '#MainWPBulkUploadUserLoading' ).hide(); | |
| 329 | - jQuery( '#import_user_btn_save_csv' ).prop("disabled", false); //Enable | |
| 330 | - } else | |
| 331 | - { | |
| 373 | + jQuery('#import_user_btn_import').on('click', function () { | |
| 374 | + if (import_user_stop_by_user) { | |
| 332 | 375 | import_user_stop_by_user = false; |
| 333 | - jQuery( '#import_user_import_logging .log' ).append( __( 'Continue import.' ) + "\n" ); | |
| 334 | - jQuery( '#import_user_btn_import' ).val( __( 'Pause' ) ); | |
| 335 | - jQuery( '#MainWPBulkUploadUserLoading' ).show(); | |
| 336 | - jQuery( '#import_user_btn_save_csv' ).attr( 'disabled', 'true' ); // Disable | |
| 376 | + jQuery('#import_user_import_logging .log').append(MainWP.I18n.t('Continue import.') + "\n"); | |
| 377 | + jQuery('#import_user_btn_import').val(MainWP.I18n.t('Pause')); | |
| 378 | + jQuery('#MainWPBulkUploadUserLoading').show(); | |
| 379 | + if (import_user_count_create_fails > 0) { | |
| 380 | + jQuery('#import_user_btn_save_csv').attr("style", 'display:inline-block;'); //Enable | |
| 381 | + } | |
| 337 | 382 | mainwp_import_users_next(); |
| 383 | + } else { | |
| 384 | + import_user_stop_by_user = true; | |
| 385 | + jQuery('#import_user_import_logging .log').append(_('Paused import by user.') + "\n"); | |
| 386 | + jQuery('#import_user_btn_import').val(MainWP.I18n.t('Continue')); | |
| 387 | + jQuery('#MainWPBulkUploadUserLoading').hide(); | |
| 388 | + if (import_user_count_create_fails > 0) { | |
| 389 | + jQuery('#import_user_btn_save_csv').attr("style", 'display:inline-block;'); //Enable | |
| 390 | + } | |
| 338 | 391 | } |
| 339 | - } ); | |
| 392 | + }); | |
| 340 | 393 | |
| 341 | 394 | |
| 342 | - jQuery( '#import_user_btn_save_csv' ).on( 'click', function () { | |
| 343 | - var fail_data = ''; | |
| 344 | - jQuery( '#import_user_import_failed_rows span' ).each(function(){ | |
| 395 | + jQuery('#import_user_btn_save_csv').on('click', function () { | |
| 396 | + let fail_data = ''; | |
| 397 | + jQuery('#import_user_import_failed_rows span').each(function () { | |
| 345 | 398 | fail_data += jQuery(this).html() + "\r\n"; |
| 346 | 399 | }); |
| 347 | - var blob = new Blob( [ fail_data ], { type: "text/plain;charset=utf-8" } ); | |
| 348 | - saveAs( blob, "import_users_fails.csv" ); | |
| 349 | - } ); | |
| 400 | + let blob = new Blob([fail_data], { type: "text/plain;charset=utf-8" }); | |
| 401 | + saveAs(blob, "import_users_fails.csv"); | |
| 402 | + }); | |
| 350 | 403 | |
| 351 | - if ( jQuery( '#import_user_do_import' ).val() == 1 ) { | |
| 352 | - jQuery( '#MainWPBulkUploadUserLoading' ).show(); | |
| 404 | + if (jQuery('#import_user_do_import').val() == 1) { | |
| 405 | + jQuery('#MainWPBulkUploadUserLoading').show(); | |
| 353 | 406 | mainwp_import_users_next(); |
| 354 | 407 | } |
| 355 | -} ); | |
| 408 | +}); | |
| 356 | 409 | |
| 357 | 410 | |
| 358 | -mainwp_bulkupload_users = function () { | |
| 359 | - if ( jQuery( '#import_user_file_bulkupload' ).val() == '' ) { | |
| 360 | - feedback( 'mainwp-message-zone', __( 'Please enter CSV file for upload.' ), 'yellow' ); | |
| 361 | - jQuery( '#import_user_file_bulkupload' ).parent().parent().addClass( 'form-invalid' ); | |
| 411 | +globalThis.mainwp_bulkupload_users = function () { | |
| 412 | + if (jQuery('#import_user_file_bulkupload').val() == '') { | |
| 413 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please enter CSV file for upload.'), 'yellow'); | |
| 414 | + jQuery('#import_user_file_bulkupload').parent().parent().addClass('form-invalid'); | |
| 362 | 415 | } else { |
| 363 | - jQuery( '#createuser' ).submit(); | |
| 416 | + jQuery('#createuser').submit(); | |
| 364 | 417 | } |
| 365 | 418 | }; |
| 366 | 419 | |
| 367 | -mainwp_import_users_next = function () { | |
| 420 | +let mainwp_import_users_next = function () { | |
| 368 | 421 | |
| 369 | - if ( import_user_stop_by_user == true ) | |
| 422 | + if (import_user_stop_by_user) | |
| 370 | 423 | return; |
| 371 | 424 | |
| 425 | + if (!jQuery('[id^="user_import_csv_line_"]').length) { | |
| 426 | + return; | |
| 427 | + } | |
| 428 | + | |
| 372 | 429 | import_user_current_line_number++; |
| 373 | 430 | |
| 374 | - if ( import_user_current_line_number > import_user_total_import ) { | |
| 431 | + if (import_user_current_line_number > import_user_total_import) { | |
| 375 | 432 | mainwp_import_users_finished(); |
| 376 | 433 | return; |
| 377 | 434 | } |
| 378 | 435 | |
| 379 | - var import_data = jQuery( '#user_import_csv_line_' + import_user_current_line_number ).attr('encoded-data'); | |
| 380 | - var original_line = jQuery( '#user_import_csv_line_' + import_user_current_line_number ).attr('original-line'); | |
| 436 | + let import_data = jQuery('#user_import_csv_line_' + import_user_current_line_number).attr('encoded-data'); | |
| 437 | + let original_line = jQuery('#user_import_csv_line_' + import_user_current_line_number).attr('original-line'); | |
| 381 | 438 | |
| 382 | - var decoded_data = false; | |
| 383 | - var pos_data = [ ]; | |
| 384 | - var errors = [ ]; | |
| 439 | + let decoded_data = false; | |
| 440 | + let pos_data = []; | |
| 441 | + let errors = []; | |
| 385 | 442 | |
| 386 | 443 | try { |
| 387 | - decoded_data = JSON.parse( import_data ); | |
| 388 | - } catch(e) { | |
| 389 | - decoded_data = false; | |
| 390 | - errors.push( __( 'Invalid import data.' ) ); | |
| 444 | + decoded_data = JSON.parse(import_data); | |
| 445 | + } catch { | |
| 446 | + decoded_data = false; | |
| 447 | + errors.push(MainWP.I18n.t('Invalid import data.')); | |
| 391 | 448 | } |
| 392 | 449 | |
| 393 | - if ( false != decoded_data ) { | |
| 394 | - jQuery( '#import_user_import_logging .log' ).append( '[' + import_user_current_line_number + '] ' + original_line + '\n'); | |
| 395 | - var valid = mainwp_import_users_valid_data( decoded_data ); | |
| 396 | - pos_data = valid.data; | |
| 397 | - errors = valid.errors; | |
| 450 | + if (decoded_data) { | |
| 451 | + jQuery('#import_user_import_logging .log').append('[' + import_user_current_line_number + '] ' + original_line + '\n'); | |
| 452 | + let valid = mainwp_import_users_valid_data(decoded_data); | |
| 453 | + pos_data = valid.data; | |
| 454 | + errors = valid.errors; | |
| 398 | 455 | } |
| 399 | 456 | |
| 400 | - if ( errors.length > 0 ) { | |
| 401 | - jQuery( '#import_user_import_failed_rows' ).append( '<span>' + original_line + '</span>' ); | |
| 402 | - jQuery( '#import_user_import_logging .log' ).append( '[' + import_user_current_line_number + ']>> Error - ' + errors.join( " " ) + '\n' ); | |
| 457 | + if (errors.length > 0) { | |
| 458 | + jQuery('#import_user_import_failed_rows').append('<span>' + original_line + '</span>'); | |
| 459 | + jQuery('#import_user_import_logging .log').append('[' + import_user_current_line_number + ']>> Error - ' + errors.join(" ") + '\n'); | |
| 403 | 460 | import_user_count_create_fails++; |
| 404 | 461 | mainwp_import_users_next(); |
| 405 | 462 | return; |
| 406 | 463 | } |
| 407 | 464 | |
| 408 | - if ( 0 == pos_data.length ) { | |
| 409 | - console.log( 'Error: import user data!' ); | |
| 410 | - return; | |
| 411 | - } | |
| 465 | + if (0 == pos_data.length) { | |
| 466 | + console.log('Error: import user data!'); | |
| 467 | + return; | |
| 468 | + } | |
| 412 | 469 | |
| 413 | - pos_data.action = 'mainwp_importuser'; | |
| 414 | - pos_data.line_number = import_user_current_line_number; | |
| 415 | - var data = mainwp_secure_data( pos_data ); | |
| 470 | + pos_data.action = 'mainwp_importuser'; | |
| 471 | + pos_data.line_number = import_user_current_line_number; | |
| 472 | + let data = mainwp_secure_data(pos_data); | |
| 416 | 473 | |
| 417 | 474 | //Add user via ajax!! |
| 418 | - jQuery.post( ajaxurl, data, function ( response_data ) { | |
| 419 | - if ( response_data.error != undefined ) | |
| 420 | - return; | |
| 421 | - mainwp_import_users_response( response_data ); | |
| 422 | - mainwp_import_users_next(); | |
| 423 | - }, 'json' ); | |
| 475 | + jQuery.post(ajaxurl, data, function (response_data) { | |
| 476 | + if (response_data.error != undefined) | |
| 477 | + return; | |
| 478 | + mainwp_import_users_response(response_data); | |
| 479 | + mainwp_import_users_next(); | |
| 480 | + }, 'json'); | |
| 424 | 481 | }; |
| 425 | 482 | |
| 426 | 483 | /* eslint-disable complexity */ |
| 427 | -mainwp_import_users_valid_data = function( decoded_data ) { | |
| 484 | +let mainwp_import_users_valid_data = function (decoded_data) { // NOSONAR - complexity, multi user's fields. | |
| 428 | 485 | |
| 429 | - var errors = []; // array. | |
| 430 | - var val_data = {}; // object. | |
| 486 | + let errors = []; // array. | |
| 487 | + let val_data = {}; // object. | |
| 431 | 488 | |
| 432 | - val_data.user_login = decoded_data.user_login == undefined ? '' : decoded_data.user_login; | |
| 433 | - val_data.email = decoded_data.email == undefined ? '' : decoded_data.email; | |
| 434 | - val_data.first_name = decoded_data.first_name == undefined ? '' : decoded_data.first_name; | |
| 435 | - val_data.last_name = decoded_data.last_name == undefined ? '' : decoded_data.last_name ; | |
| 436 | - val_data.url = decoded_data.url == undefined ? '' : decoded_data.url; | |
| 437 | - val_data.pass1 = decoded_data.pass1 == undefined ? '' : decoded_data.pass1; | |
| 438 | - val_data.send_password = decoded_data.send_password == undefined ? '' : decoded_data.send_password; | |
| 439 | - val_data.role = decoded_data.role == undefined ? '' : decoded_data.role; | |
| 440 | - val_data.select_sites = decoded_data.select_sites == undefined ? '' : decoded_data.select_sites; | |
| 441 | - val_data.select_groups = decoded_data.select_groups == undefined ? '' : decoded_data.select_groups; | |
| 442 | - val_data.select_by = ''; | |
| 489 | + val_data.user_login = decoded_data.user_login == undefined ? '' : decoded_data.user_login; | |
| 490 | + val_data.email = decoded_data.email == undefined ? '' : decoded_data.email; | |
| 491 | + val_data.first_name = decoded_data.first_name == undefined ? '' : decoded_data.first_name; | |
| 492 | + val_data.last_name = decoded_data.last_name == undefined ? '' : decoded_data.last_name; | |
| 493 | + val_data.url = decoded_data.url == undefined ? '' : decoded_data.url; | |
| 494 | + val_data.pass1 = decoded_data.pass1 == undefined ? '' : decoded_data.pass1; | |
| 495 | + val_data.send_password = decoded_data.send_password == undefined ? '' : decoded_data.send_password; | |
| 496 | + val_data.role = decoded_data.role == undefined ? '' : decoded_data.role; | |
| 497 | + val_data.select_sites = decoded_data.select_sites == undefined ? '' : decoded_data.select_sites; | |
| 498 | + val_data.select_groups = decoded_data.select_groups == undefined ? '' : decoded_data.select_groups; | |
| 499 | + val_data.select_by = ''; | |
| 443 | 500 | |
| 444 | - if ( val_data.user_login == '' ) { | |
| 445 | - errors.push( __( 'Please enter a username.' ) ); | |
| 446 | - } | |
| 501 | + if (val_data.user_login == '') { | |
| 502 | + errors.push(MainWP.I18n.t('Please enter a username.')); | |
| 503 | + } | |
| 447 | 504 | |
| 448 | - if ( val_data.email == '' ) { | |
| 449 | - errors.push( __( 'Please enter an email.' ) ); | |
| 450 | - } | |
| 505 | + if (val_data.email == '') { | |
| 506 | + errors.push(MainWP.I18n.t('Please enter an email.')); | |
| 507 | + } | |
| 451 | 508 | |
| 452 | - if ( val_data.pass1 == '' ) { | |
| 453 | - errors.push( __( 'Please enter a password.' ) ); | |
| 454 | - } | |
| 509 | + if (val_data.pass1 == '') { | |
| 510 | + errors.push(MainWP.I18n.t('Please enter a password.')); | |
| 511 | + } | |
| 455 | 512 | |
| 456 | - var allowed_roles = [ 'subscriber', 'administrator', 'editor', 'author', 'contributor' ]; | |
| 457 | - if ( jQuery.inArray( val_data.role, allowed_roles ) == -1 ) { | |
| 458 | - errors.push( __( 'Please select a data role.' ) ); | |
| 459 | - } | |
| 513 | + let allowed_roles = ['subscriber', 'administrator', 'editor', 'author', 'contributor']; | |
| 514 | + if (jQuery.inArray(val_data.role, allowed_roles) == -1) { | |
| 515 | + errors.push(MainWP.I18n.t('Please select a data role.')); | |
| 516 | + } | |
| 460 | 517 | |
| 461 | - if ( val_data.select_sites != '' ) { | |
| 462 | - var selected_sites = val_data.select_sites.split( ';' ); | |
| 463 | - if ( selected_sites.length == 0 ) { | |
| 464 | - errors.push( __( 'Please select websites or groups to add a user.' ) ); | |
| 465 | - } else { | |
| 466 | - val_data.select_sites = selected_sites; | |
| 467 | - val_data.select_by = 'site'; | |
| 468 | - } | |
| 469 | - } else { | |
| 470 | - var selected_groups = val_data.select_groups.split( ';' ); | |
| 471 | - if ( selected_groups.length == 0 ) { | |
| 472 | - errors.push( __( 'Please select websites or groups to add a user.' ) ); | |
| 473 | - } else { | |
| 474 | - val_data.select_groups = selected_groups; | |
| 475 | - val_data.select_by = 'group'; | |
| 476 | - } | |
| 477 | - } | |
| 478 | - return { | |
| 479 | - errors: errors, | |
| 480 | - data: val_data | |
| 481 | - }; | |
| 518 | + if (val_data.select_sites == '') { | |
| 482 | 519 | |
| 520 | + let selected_groups = val_data.select_groups.split(';'); | |
| 521 | + if (selected_groups.length == 0) { | |
| 522 | + errors.push(MainWP.I18n.t('Please select websites or groups to add a user.')); | |
| 523 | + } else { | |
| 524 | + val_data.select_groups = selected_groups; | |
| 525 | + val_data.select_by = 'group'; | |
| 526 | + } | |
| 527 | + } else { | |
| 528 | + let selected_sites = val_data.select_sites.split(';'); | |
| 529 | + if (selected_sites.length == 0) { | |
| 530 | + errors.push(MainWP.I18n.t('Please select websites or groups to add a user.')); | |
| 531 | + } else { | |
| 532 | + val_data.select_sites = selected_sites; | |
| 533 | + val_data.select_by = 'site'; | |
| 534 | + } | |
| 535 | + } | |
| 536 | + return { | |
| 537 | + errors: errors, | |
| 538 | + data: val_data | |
| 539 | + }; | |
| 540 | + | |
| 483 | 541 | }; |
| 484 | 542 | /* eslint-enable complexity */ |
| 485 | 543 | |
| 486 | -mainwp_import_users_response = function( response_data ) { | |
| 487 | - var line_num = response_data.line_number; | |
| 488 | - var okList = response_data.ok_list; | |
| 489 | - var errorList = response_data.error_list; | |
| 490 | - if ( okList != undefined ) | |
| 491 | - for ( var i = 0; i < okList.length; i++ ) { | |
| 492 | - import_user_count_created_users++; | |
| 493 | - jQuery( '#import_user_import_logging .log' ).append( '[' + line_num + ']>> ' + okList[i] + '\n' ); | |
| 494 | - } | |
| 544 | +let mainwp_import_users_response = function (response_data) { | |
| 545 | + let line_num = response_data.line_number; | |
| 546 | + let okList = response_data.ok_list; | |
| 547 | + let errorList = response_data.error_list; | |
| 548 | + if (okList != undefined) | |
| 549 | + for (let iok of okList) { | |
| 550 | + import_user_count_created_users++; | |
| 551 | + jQuery('#import_user_import_logging .log').append('[' + line_num + ']>> ' + iok + '\n'); | |
| 552 | + } | |
| 495 | 553 | |
| 496 | - if ( errorList != undefined ) | |
| 497 | - for ( var i = 0; i < errorList.length; i++ ) { | |
| 498 | - import_user_count_create_fails++; | |
| 499 | - jQuery( '#import_user_import_logging .log' ).append( '[' + line_num + ']>> ' + errorList[i] + '\n' ); | |
| 500 | - } | |
| 554 | + if (errorList != undefined) | |
| 555 | + for (let ie of errorList) { | |
| 556 | + import_user_count_create_fails++; | |
| 557 | + jQuery('#import_user_import_logging .log').append('[' + line_num + ']>> ' + ie + '\n'); | |
| 558 | + } | |
| 501 | 559 | |
| 502 | - if ( response_data.failed_logging != '' && response_data.failed_logging != undefined ) { | |
| 503 | - jQuery( '#import_user_import_failed_rows' ).append( '<span>' + response_data.failed_logging + '</span>' ); | |
| 504 | - } | |
| 505 | - jQuery( '#import_user_import_logging' ).scrollTop( jQuery( '#import_user_import_logging .log' ).height() ); | |
| 560 | + if (response_data.failed_logging != '' && response_data.failed_logging != undefined) { | |
| 561 | + jQuery('#import_user_import_failed_rows').append('<span>' + response_data.failed_logging + '</span>'); | |
| 562 | + } | |
| 563 | + jQuery('#import_user_import_logging').scrollTop(jQuery('#import_user_import_logging .log').height()); | |
| 506 | 564 | }; |
| 507 | 565 | |
| 508 | -mainwp_import_users_finished = function() { | |
| 509 | - jQuery( '#import_user_btn_import' ).val( 'Finished' ).attr( 'disabled', 'true' ); | |
| 510 | - jQuery( '#MainWPBulkUploadUserLoading' ).hide(); | |
| 511 | - jQuery( '#import_user_import_logging .log' ).append( '\n' + __( 'Number of users to import: %1 Created users: %2 Failed: %3', import_user_total_import, import_user_count_created_users, import_user_count_create_fails ) + '\n' ); | |
| 512 | - if ( import_user_count_create_fails > 0 ) { | |
| 513 | - jQuery( '#import_user_btn_save_csv' ).prop("disabled", false); //Enable | |
| 514 | - } | |
| 515 | - jQuery( '#import_user_import_logging' ).scrollTop( jQuery( '#import_user_import_logging .log' ).height() ); | |
| 566 | +let mainwp_import_users_finished = function () { | |
| 567 | + jQuery('#import_user_btn_import').val('Finished').attr('disabled', 'true'); | |
| 568 | + jQuery('#MainWPBulkUploadUserLoading').hide(); | |
| 569 | + jQuery('#import_user_import_logging .log').append('\n' + MainWP.I18n.t('Number of users to import: %1 Created users: %2 Failed: %3', import_user_total_import, import_user_count_created_users, import_user_count_create_fails) + '\n'); | |
| 570 | + if (import_user_count_create_fails > 0) { | |
| 571 | + jQuery('#import_user_btn_save_csv').attr("style", 'display:inline-block;'); //Enable | |
| 572 | + } | |
| 573 | + jQuery('#import_user_import_logging').scrollTop(jQuery('#import_user_import_logging .log').height()); | |
| 516 | 574 | } |