From fd55df9f7cd39f7a9cfbfe498d441bcddb92935e Mon Sep 17 00:00:00 2001 From: sahil839 Date: Tue, 6 Jul 2021 00:15:35 +0530 Subject: [PATCH] settings: Use dialog_widget for bot-edit form and remove edit_fields_modal. This commit changes the bot-edit modal to use dialog_widget instead of edit_fields_modal. This commit also removes edit_fields_modal module as it is no longer used. --- static/js/edit_fields_modal.js | 67 ------------------- static/js/settings_users.js | 8 +-- static/styles/settings.css | 5 -- .../templates/settings/edit_fields_modal.hbs | 13 ---- tools/linter_lib/custom_check.py | 1 - tools/test-js-with-node | 1 - 6 files changed, 4 insertions(+), 91 deletions(-) delete mode 100644 static/js/edit_fields_modal.js delete mode 100644 static/templates/settings/edit_fields_modal.hbs diff --git a/static/js/edit_fields_modal.js b/static/js/edit_fields_modal.js deleted file mode 100644 index 2df4ecb8c7..0000000000 --- a/static/js/edit_fields_modal.js +++ /dev/null @@ -1,67 +0,0 @@ -import $ from "jquery"; - -import render_edit_fields_modal from "../templates/settings/edit_fields_modal.hbs"; - -import * as blueslip from "./blueslip"; -import * as overlays from "./overlays"; - -/* - Look for edit_fields_modal in settings_users.js to see an - example of how to use this widget. - - Some things to note: - - 1) We create the DOM elements on the fly, and we remove the - DOM elements once it's closed. - - 2) We attach the DOM elements for the modal to modal_fields.parent. - - 3) The cancel button is driven by bootstrap.js. - - 4) We do not handle closing the modal on clicking "Save - changes" here, because some modals show errors, if the - request fails, in the modal itself without closing. - - 5) If a caller needs to run code after the modal body is added - to DOM, it can do so by passing a post_render hook. -*/ - -export function launch(modal_fields) { - const required_modal_fields = ["html_heading", "parent", "html_body", "on_click"]; - - for (const field of required_modal_fields) { - if (!modal_fields[field]) { - blueslip.error("programmer omitted " + field); - } - } - - const html = render_edit_fields_modal({ - html_heading: modal_fields.html_heading, - }); - const edit_fields_modal = $(html); - modal_fields.parent.append(edit_fields_modal); - - if (overlays.is_modal_open()) { - overlays.close_modal("#edit-fields-modal"); - } - - edit_fields_modal.find(".edit-fields-modal-body").append(modal_fields.html_body); - - if (modal_fields.post_render !== undefined) { - modal_fields.post_render(); - } - - // Set up handlers. - $(".submit-modal-button").on("click", (e) => { - e.preventDefault(); - e.stopPropagation(); - modal_fields.on_click(); - }); - - edit_fields_modal.on("hidden.bs.modal", () => { - edit_fields_modal.remove(); - }); - - // Open the modal - overlays.open_modal("#edit-fields-modal"); -} diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 2d3f248a9a..af3ba19223 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -11,7 +11,6 @@ import * as channel from "./channel"; import * as confirm_dialog from "./confirm_dialog"; import * as dialog_widget from "./dialog_widget"; import {DropdownListWidget as dropdown_list_widget} from "./dropdown_list_widget"; -import * as edit_fields_modal from "./edit_fields_modal"; import {$t, $t_html} from "./i18n"; import * as ListWidget from "./list_widget"; import * as loading from "./loading"; @@ -607,7 +606,7 @@ function handle_bot_form(tbody, status_field) { let owner_widget; function submit_bot_details() { - const full_name = $("#edit-fields-modal").find("input[name='full_name']"); + const full_name = $("#dialog_widget_modal").find("input[name='full_name']"); const url = "/json/bots/" + encodeURIComponent(user_id); const data = { @@ -623,7 +622,7 @@ function handle_bot_form(tbody, status_field) { } settings_ui.do_settings_change(channel.patch, url, data, status_field); - overlays.close_modal("#edit-fields-modal"); + overlays.close_modal("#dialog_widget_modal"); } function get_bot_owner_widget() { @@ -646,12 +645,13 @@ function handle_bot_form(tbody, status_field) { owner_widget = dropdown_list_widget(opts); } - edit_fields_modal.launch({ + dialog_widget.launch({ html_heading: $t({defaultMessage: "Change bot info and owner"}), parent: modal_parent, html_body, on_click: submit_bot_details, post_render: get_bot_owner_widget, + fade: true, }); }); } diff --git a/static/styles/settings.css b/static/styles/settings.css index 9131a1c6c8..62fe857126 100644 --- a/static/styles/settings.css +++ b/static/styles/settings.css @@ -1930,11 +1930,6 @@ body:not(.night-mode) #settings_page .custom_user_field .datepicker { } } -#edit-fields-modal-status { - margin-top: 6px; - margin-bottom: 8px; -} - #edit-linkifier-form { #edit-linkifier-pattern, #edit-linkifier-url-format-string { diff --git a/static/templates/settings/edit_fields_modal.hbs b/static/templates/settings/edit_fields_modal.hbs deleted file mode 100644 index 00353fbdec..0000000000 --- a/static/templates/settings/edit_fields_modal.hbs +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index aee29fa0bc..9ff2d1f813 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -131,7 +131,6 @@ js_rules = RuleList( "static/js/lightbox.js", "static/js/ui_report.ts", "static/js/dialog_widget.js", - "static/js/edit_fields_modal.js", "frontend_tests/", }, "description": "Setting HTML content with jQuery .html() can lead to XSS security bugs. Consider .text() or using rendered_foo as a variable name if content comes from handlebars and thus is already sanitized.", diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 97c4fffb56..70f193c34a 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -62,7 +62,6 @@ EXEMPT_FILES = { "static/js/desktop_integration.js", "static/js/drafts.js", "static/js/echo.js", - "static/js/edit_fields_modal.js", "static/js/emoji_picker.js", "static/js/emojisets.js", "static/js/favicon.js",