Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

dialog_widget: Add option to hide footer from dialog widget modal.

Pratik Chanda1c4a7cb31a6f
diff --git a/web/src/dialog_widget.ts b/web/src/dialog_widget.ts
index 5d95a38fac3..744439398de 100644
--- a/web/src/dialog_widget.ts
+++ b/web/src/dialog_widget.ts
@@ -64,7 +64,8 @@ export type DialogWidgetConfig = {
html_heading?: string;
text_heading?: string;
html_body: string;
- on_click: (e: JQuery.ClickEvent) => void;
+ on_click?: (e: JQuery.ClickEvent) => void;
+ hide_footer?: boolean;
html_submit_button?: string;
html_exit_button?: string;
close_on_submit?: boolean;
@@ -163,12 +164,13 @@ export function launch(conf: DialogWidgetConfig): string {
// Mandatory fields:
// * html_heading | text_heading
// * html_body
- // * on_click
// The html_ fields should be safe HTML. If callers
// interpolate user data into strings, they should use
// templates.
// Optional parameters:
+ // * on_click: Callback to run when submit button is clicked and footer is enabled.
+ // * hide_footer: Whether to disable footer and hide its associated buttons.
// * html_submit_button: Submit button text.
// * html_exit_button: Exit button text.
// * close_on_submit: Whether to close modal on clicking submit.
@@ -209,6 +211,7 @@ export function launch(conf: DialogWidgetConfig): string {
always_visible_scrollbar: conf.always_visible_scrollbar,
footer_minor_text: conf.footer_minor_text,
close_on_overlay_click: conf.close_on_overlay_click ?? true,
+ hide_footer: conf.hide_footer,
});
const $dialog = $(html);
$("body").append($dialog);
@@ -219,6 +222,21 @@ export function launch(conf: DialogWidgetConfig): string {
}
}, 0);
+ if (conf.hide_footer) {
+ modals.open(modal_unique_id, {
+ autoremove: true,
+ on_show() {
+ if (conf.on_show) {
+ conf.on_show();
+ }
+ },
+ on_hide: conf?.on_hide,
+ on_shown: conf?.on_shown,
+ on_hidden: conf?.on_hidden,
+ });
+ return modal_unique_id;
+ }
+
const $submit_button = $dialog.find(".dialog_submit_button");
if (conf.update_submit_disabled_state_on_change) {
@@ -249,6 +267,7 @@ export function launch(conf: DialogWidgetConfig): string {
// Set up handlers.
$submit_button.on("click", (e: JQuery.ClickEvent) => {
e.preventDefault();
+ assert(conf.on_click !== undefined);
if (conf.validate_input && !conf.validate_input(e)) {
return;
diff --git a/web/styles/modal.css b/web/styles/modal.css
index c18c1767721..028da018cba 100644
--- a/web/styles/modal.css
+++ b/web/styles/modal.css
@@ -491,6 +491,10 @@
will-change: transform;
}
+.micromodal .modal__content.footer-hidden {
+ margin-bottom: 1.25em;
+}
+
.modal__spinner .loading_indicator_spinner {
height: 16px;
diff --git a/web/templates/dialog_widget.hbs b/web/templates/dialog_widget.hbs
index 35871bf217c..0990a19ecdc 100644
--- a/web/templates/dialog_widget.hbs
+++ b/web/templates/dialog_widget.hbs
@@ -14,10 +14,11 @@
</h1>
<button class="modal__close" aria-label="{{t 'Close modal' }}" data-micromodal-close></button>
</header>
- <main class="modal__content" data-simplebar data-simplebar-tab-index="-1" {{#if always_visible_scrollbar}}data-simplebar-auto-hide="false"{{/if}}>
+ <main class="modal__content {{#if hide_footer}} footer-hidden {{/if}}" data-simplebar data-simplebar-tab-index="-1" {{#if always_visible_scrollbar}}data-simplebar-auto-hide="false"{{/if}}>
<div class="alert" id="dialog_error"></div>
{{{ body_html }}}
</main>
+ {{#unless hide_footer}}
<footer class="modal__footer">
{{#if footer_minor_text }}
<div class="dialog-widget-footer-minor-text">{{footer_minor_text}}</div>
@@ -32,6 +33,7 @@
</button>
</div>
</footer>
+ {{/unless}}
</div>
</div>
</div>