compose: Create a helper function to calculate input information.

Function retrieves the input information based on the target event
and returns it as an object. It determines if the input is an edit
form or a compose form and returns the appropriate banner container.
This commit is contained in:
Daniil Fadeev
2023-05-08 17:17:59 +04:00
committed by Tim Abbott
parent e22c44131b
commit 815aeccd04

View File

@@ -460,6 +460,15 @@ export function initialize() {
upload.feature_check($("#compose .compose_upload_file"));
function get_input_info(event) {
const $edit_banners_container = $(event.target).closest(".edit_form_banners");
const is_edit_input = Boolean($edit_banners_container.length);
const $banner_container = $edit_banners_container.length
? $edit_banners_container
: $("#compose_banners");
return {is_edit_input, $banner_container};
}
$("body").on(
"click",
`.${CSS.escape(compose_banner.CLASSNAMES.wildcard_warning)} .compose_banner_action_button`,
@@ -536,9 +545,7 @@ export function initialize() {
)} .compose_banner_action_button`,
(event) => {
event.preventDefault();
const $edit_form = $(event.target)
.closest(".message_edit_form")
.find(".edit_form_banners");
const {$banner_container} = get_input_info(event);
const $invite_row = $(event.target).parents(".compose_banner");
const user_id = Number.parseInt($invite_row.data("user-id"), 10);
@@ -553,7 +560,7 @@ export function initialize() {
compose_banner.show_error_message(
error_msg,
compose_banner.CLASSNAMES.generic_compose_error,
$edit_form.length ? $edit_form : $("#compose_banners"),
$banner_container,
$("#compose-textarea"),
);
$(event.target).prop("disabled", true);