Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
custom_profile_fields: Convert new profile field form to a modal.
yogesh sirsat526b55c6fc7d
diff --git a/frontend_tests/puppeteer_tests/custom-profile.ts b/frontend_tests/puppeteer_tests/custom-profile.tsindex 65b2f0ea058..5f2cfc0afbc 100644--- a/frontend_tests/puppeteer_tests/custom-profile.ts+++ b/frontend_tests/puppeteer_tests/custom-profile.ts@@ -9,18 +9,24 @@ const profile_field_row = "#admin_profile_fields_table tr:nth-last-child(2)";const profile_field_form = "#admin_profile_fields_table tr:nth-last-child(1)";async function test_add_new_profile_field(page: Page): Promise<void> {+ await page.click("#add-custom-profile-field-btn");+ await common.wait_for_micromodal_to_open(page);+ assert.strictEqual(+ await common.get_text_from_selector(page, ".dialog_heading"),+ "Add a new custom profile field",+ );+ assert.strictEqual(+ await common.get_text_from_selector(page, "#dialog_widget_modal .dialog_submit_button"),+ "Add",+ );await page.waitForSelector(".admin-profile-field-form", {visible: true});await common.fill_form(page, "form.admin-profile-field-form", {name: "Teams",field_type: "1",});- await page.click("form.admin-profile-field-form button[type='submit']");+ await page.click("#dialog_widget_modal .dialog_submit_button");+ await common.wait_for_micromodal_to_close(page);- await page.waitForSelector("#admin-add-profile-field-status img", {visible: true});- assert.strictEqual(- await common.get_text_from_selector(page, "div#admin-add-profile-field-status"),- "Saved",- );await page.waitForXPath('//*[@id="admin_profile_fields_table"]//tr[last()-1]/td[normalize-space()="Teams"]',);diff --git a/static/js/settings_profile_fields.js b/static/js/settings_profile_fields.jsindex 85b6d46fe0a..eaa5f576fab 100644--- a/static/js/settings_profile_fields.js+++ b/static/js/settings_profile_fields.js@@ -2,11 +2,13 @@ import $ from "jquery";import {Sortable} from "sortablejs";import render_confirm_delete_profile_field_option from "../templates/confirm_dialog/confirm_delete_profile_field_option.hbs";+import render_add_new_custom_profile_field_form from "../templates/settings/add_new_custom_profile_field_form.hbs";import render_admin_profile_field_list from "../templates/settings/admin_profile_field_list.hbs";import render_settings_profile_field_choice from "../templates/settings/profile_field_choice.hbs";import * as channel from "./channel";import * as confirm_dialog from "./confirm_dialog";+import * as dialog_widget from "./dialog_widget";import {$t_html} from "./i18n";import * as loading from "./loading";import {page_params} from "./page_params";@@ -166,6 +168,8 @@ function clear_form_data() {}function set_up_create_field_form() {+ // Hide error on field type change.+ $("#dialog_error").hide();const $field_elem = $("#profile_field_external_accounts");const $field_url_pattern_elem = $("#custom_external_account_url_pattern");@@ -199,35 +203,44 @@ function read_field_data_from_form(field_type_id, field_elem, old_field_data) {return undefined;}-function create_profile_field(e) {- e.preventDefault();- e.stopPropagation();+function open_custom_profile_field_form_modal() {+ const html_body = render_add_new_custom_profile_field_form({+ realm_default_external_accounts: page_params.realm_default_external_accounts,+ custom_profile_field_types: page_params.custom_profile_field_types,+ });- let field_data = {};- const field_type = $("#profile_field_type").val();- const opts = {- success_continuation: clear_form_data,- };- field_data = read_field_data_from_form(- Number.parseInt(field_type, 10),- $(".new-profile-field-form"),- );+ function create_profile_field() {+ let field_data = {};+ const field_type = $("#profile_field_type").val();+ field_data = read_field_data_from_form(+ Number.parseInt(field_type, 10),+ $(".new-profile-field-form"),+ );+ const data = {+ name: $("#profile_field_name").val(),+ hint: $("#profile_field_hint").val(),+ field_type,+ field_data: JSON.stringify(field_data),+ };+ const url = "/json/realm/profile_fields";+ dialog_widget.submit_api_request(channel.post, url, data);+ }- const form_data = {- name: $("#profile_field_name").val(),- field_type,- hint: $("#profile_field_hint").val(),- field_data: JSON.stringify(field_data),- };+ function set_up_form_fields() {+ set_up_select_field();+ set_up_external_account_field();+ clear_form_data();+ }- settings_ui.do_settings_change(- channel.post,- "/json/realm/profile_fields",- form_data,- $("#admin-add-profile-field-status").expectOne(),- opts,- );- update_profile_fields_table_element();+ dialog_widget.launch({+ help_link: "/help/add-custom-profile-fields",+ html_heading: $t_html({defaultMessage: "Add a new custom profile field"}),+ html_body,+ html_submit_button: $t_html({defaultMessage: "Add"}),+ on_click: create_profile_field,+ post_render: set_up_form_fields,+ loading_spinner: true,+ });}function add_choice_row(e) {@@ -523,6 +536,8 @@ function set_up_select_field() {}$("#profile_field_type").on("change", (e) => {+ // Hide error on field type change.+ $("#dialog_error").hide();const selected_field_id = Number.parseInt($(e.target).val(), 10);if (selected_field_id === field_types.SELECT.id) {$("#profile_field_choices_row").show();@@ -570,9 +585,6 @@ export function build_page() {meta.loaded = true;$("#admin_profile_fields_table").on("click", ".delete", delete_profile_field);- $("#profile-field-settings").on("click", "#add-custom-profile-field-btn", create_profile_field);+ $("#add-custom-profile-field-btn").on("click", open_custom_profile_field_form_modal);$("#admin_profile_fields_table").on("click", ".open-edit-form", open_edit_form);- set_up_select_field();- set_up_external_account_field();- clear_form_data();}diff --git a/static/styles/settings.css b/static/styles/settings.cssindex f81fd041986..bdfe551e40b 100644--- a/static/styles/settings.css+++ b/static/styles/settings.css@@ -518,6 +518,11 @@ input[type="checkbox"] {margin-top: 4px;}+#add-custom-profile-field-btn {+ float: right;+ margin-top: 4px;+}+#user-notification-settings {.notification-table {th,@@ -626,7 +631,6 @@ input[type="checkbox"] {vertical-align: middle;}-.add-new-profile-field-box,.add-new-linkifier-box,.add-new-playground-box {button {@@ -1595,14 +1599,14 @@ input[type="checkbox"] {}.choice-row {- margin-top: 5px;+ margin-top: 8px;input {width: 190px;}button {- margin-left: 0 !important;+ margin-left: 2px;}}diff --git a/static/templates/settings/add_new_custom_profile_field_form.hbs b/static/templates/settings/add_new_custom_profile_field_form.hbsnew file mode 100644index 00000000000..e88e3d1ece9--- /dev/null+++ b/static/templates/settings/add_new_custom_profile_field_form.hbs@@ -0,0 +1,40 @@+<form class="form-horizontal admin-profile-field-form new-style">+ <div class="new-profile-field-form wrapper">+ <div class="input-group">+ <label for="profile_field_type" >{{t "Type" }}</label>+ <select id="profile_field_type" name="field_type">+ {{#each custom_profile_field_types}}+ <option value='{{this.id}}'>{{this.name}}</option>+ {{/each}}+ </select>+ </div>+ <div class="input-group" id="profile_field_external_accounts">+ <label for="profile_field_external_accounts_type" >{{t "External account type" }}</label>+ <select id="profile_field_external_accounts_type" name="external_acc_field_type">+ {{#each realm_default_external_accounts}}+ <option value='{{@key}}'>{{this.text}}</option>+ {{/each}}+ <option value="custom">{{t 'Custom' }}</option>+ </select>+ </div>+ <div class="input-group">+ <label for="profile_field_name" >{{t "Label" }}</label>+ <input type="text" id="profile_field_name" name="name" autocomplete="off" maxlength="40" />+ </div>+ <div class="input-group">+ <label for="profile_field_hint" >{{t "Hint (up to 80 characters)" }}</label>+ <input type="text" id="profile_field_hint" name="hint" autocomplete="off" maxlength="80" />+ <div class="alert" id="admin-profile-field-hint-status"></div>+ </div>+ <div class="input-group" id="profile_field_choices_row">+ <label for="profile_field_choices" >{{t "Field choices" }}</label>+ <table class="profile_field_choices_table">+ <tbody id="profile_field_choices" class="profile-field-choices"></tbody>+ </table>+ </div>+ <div class="input-group" id="custom_external_account_url_pattern">+ <label for="custom_field_url_pattern" >{{t "URL pattern" }}</label>+ <input type="url" id="custom_field_url_pattern" name="url_pattern" autocomplete="off" maxlength="1024" placeholder="https://example.com/path/%(username)s"/>+ </div>+ </div>+</form>diff --git a/static/templates/settings/profile_field_choice.hbs b/static/templates/settings/profile_field_choice.hbsindex e65b04f4a12..976cad168a4 100644--- a/static/templates/settings/profile_field_choice.hbs+++ b/static/templates/settings/profile_field_choice.hbs@@ -3,7 +3,7 @@<i class="fa fa-ellipsis-v" aria-hidden="true"></i><input type='text' placeholder='{{t "New option" }}' value="{{ text }}" />- <button type='button' class="button rounded small btn-danger delete-choice" title="{{t 'Delete' }}">+ <button type='button' class="button rounded small delete-choice" title="{{t 'Delete' }}"><i class="fa fa-trash-o" aria-hidden="true"></i></button></div>diff --git a/static/templates/settings/profile_field_settings_admin.hbs b/static/templates/settings/profile_field_settings_admin.hbsindex b5c6231b63c..2ba08d2fb4e 100644--- a/static/templates/settings/profile_field_settings_admin.hbs+++ b/static/templates/settings/profile_field_settings_admin.hbs@@ -2,6 +2,9 @@<div class="settings_panel_list_header"><h3>{{t "Custom profile fields"}}</h3><div class="alert-notification" id="admin-profile-field-status"></div>+ {{#if is_admin}}+ <button class="button rounded sea-green" id="add-custom-profile-field-btn">{{t "Add a new profile field" }}</button>+ {{/if}}</div><div class="admin-table-wrapper"><table class="table table-condensed table-striped admin_profile_fields_table">@@ -15,53 +18,4 @@</tbody></table></div>- {{#if is_admin}}- <form class="form-horizontal admin-profile-field-form">- <div class="add-new-profile-field-box grey-box">- <div class="new-profile-field-form wrapper">- <div class="settings-section-title new-profile-field-section-title inline-block">{{t "Add a new profile field" }}</div>- <div class="alert-notification" id="admin-add-profile-field-status"></div>- <div class="input-group">- <label for="profile_field_type" class="control-label">{{t "Type" }}</label>- <select id="profile_field_type" name="field_type">- {{#each custom_profile_field_types}}- <option value='{{this.id}}'>{{this.name}}</option>- {{/each}}- </select>- </div>- <div class="input-group" id="profile_field_external_accounts">- <label for="profile_field_external_accounts_type" class="control-label">{{t "External account type" }}</label>- <select id="profile_field_external_accounts_type" name="external_acc_field_type">- {{#each realm_default_external_accounts}}- <option value='{{@key}}'>{{this.text}}</option>- {{/each}}- <option value="custom">{{t 'Custom' }}</option>- </select>- </div>- <div class="input-group">- <label for="profile_field_name" class="control-label">{{t "Label" }}</label>- <input type="text" id="profile_field_name" name="name" autocomplete="off" maxlength="40" />- </div>- <div class="input-group">- <label for="profile_field_hint" class="control-label">{{t "Hint (up to 80 characters)" }}</label>- <input type="text" id="profile_field_hint" name="hint" autocomplete="off" maxlength="80" />- <div class="alert" id="admin-profile-field-hint-status"></div>- </div>- <div class="input-group" id="profile_field_choices_row">- <label for="profile_field_choices" class="control-label">{{t "Field choices" }}</label>- <table class="profile_field_choices_table">- <tbody id="profile_field_choices" class="profile-field-choices"></tbody>- </table>- </div>- <div class="input-group" id="custom_external_account_url_pattern">- <label for="custom_field_url_pattern" class="control-label">{{t "URL pattern" }}</label>- <input type="url" id="custom_field_url_pattern" name="url_pattern" autocomplete="off" maxlength="1024" placeholder="https://example.com/path/%(username)s"/>- </div>- <button type="submit" class="button rounded sea-green" id="add-custom-profile-field-btn">- {{t 'Add profile field' }}- </button>- </div>- </div>- </form>- {{/if}}</div>