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