From fd3d7fa9f2b19e616288b25ac97471a711c6bc9f Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 9 May 2020 12:40:22 +0000 Subject: [PATCH] user settings: Move get_human_profile_data(). This is a purely lexical move (apart from changing a closure variable to an argument), which is simply designed to make less indentation for the reader and to de-clutter `handle_human_form`. --- static/js/settings_users.js | 60 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/static/js/settings_users.js b/static/js/settings_users.js index f825f5eb8c..26e9baed98 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -359,6 +359,39 @@ function open_human_form(person) { }; } +function get_human_profile_data(fields_user_pills) { + /* + This formats custom profile field data to send to the server. + See render_admin_human_form and open_human_form + to see how the form is built. + + TODO: Ideally, this logic would be cleaned up or deduplicated with + the settings_account.js logic. + */ + const new_profile_data = []; + $("#admin-human-form .custom_user_field_value").each(function () { + // Remove duplicate datepicker input element generated flatpicker library + if (!$(this).hasClass("form-control")) { + new_profile_data.push({ + id: parseInt($(this).closest(".custom_user_field").attr("data-field-id"), 10), + value: $(this).val(), + }); + } + }); + // Append user type field values also + for (const [field_id, field_pills] of fields_user_pills) { + if (field_pills) { + const user_ids = user_pill.get_user_ids(field_pills); + new_profile_data.push({ + id: field_id, + value: user_ids, + }); + } + } + + return new_profile_data; +} + function open_bot_form(person) { const html = render_admin_bot_form({ user_id: person.user_id, @@ -497,34 +530,9 @@ function handle_human_form() { const admin_status = get_status_field(); - function get_profile_data() { - const new_profile_data = []; - $("#admin-human-form .custom_user_field_value").each(function () { - // Remove duplicate datepicker input element generated flatpicker library - if (!$(this).hasClass("form-control")) { - new_profile_data.push({ - id: parseInt($(this).closest(".custom_user_field").attr("data-field-id"), 10), - value: $(this).val(), - }); - } - }); - // Append user type field values also - for (const [field_id, field_pills] of fields_user_pills) { - if (field_pills) { - const user_ids = user_pill.get_user_ids(field_pills); - new_profile_data.push({ - id: field_id, - value: user_ids, - }); - } - } - - return new_profile_data; - } - const user_role_select_value = modal.find('#user-role-select').val(); const full_name = modal.find("input[name='full_name']"); - const profile_data = get_profile_data(); + const profile_data = get_human_profile_data(fields_user_pills); const url = "/json/users/" + encodeURIComponent(user_id); const data = {