polls: Add option for modal to create polls.

Earlier the `/poll` slash command was the only way to create polls.
To increase user friendliness with a GUI, a button to launch a modal
to create a poll, has been added to the compose box. This button is
enabled only when the compose box is empty, to avoid complexities with
losing / having to save as draft any message already being composed.

The modal has a form which on submission frames a message using the
`/poll` syntax and the data input in the form, and sets the content of
the compose box to that message, which the user can then send. The
question field is mandatory for form submission.

Fixes: #20304.
This commit is contained in:
N-Shar-ma
2022-07-16 18:10:59 +05:30
committed by Tim Abbott
parent 084718b776
commit 143db56992
12 changed files with 256 additions and 0 deletions

View File

@@ -209,6 +209,22 @@ export function initialize(): void {
},
});
delegate("body", {
target: "#add-poll-modal .dialog_submit_button_container",
appendTo: () => document.body,
onShow(instance) {
const content = $t({defaultMessage: "Please enter a question."});
const $elem = $(instance.reference);
// Show tooltip to enter question only if submit button is disabled
// (due to question field being empty).
if ($elem.find(".dialog_submit_button").is(":disabled")) {
instance.setContent(content);
return undefined;
}
return false;
},
});
$("body").on(
"blur",
".message_control_button, .delete-selected-drafts-button-container",