realm_emoji: Shift realm_emoji request call in a function.

Relocated the post request in a new `add_realm_emoji`
function to built an better abstraction for `settings_emoji`.
This commit is contained in:
aryanshridhar 2021-04-14 19:31:21 +05:30 committed by Tim Abbott
parent 3fd33fdcce
commit 747209a8ca
1 changed files with 34 additions and 29 deletions

View File

@ -184,24 +184,14 @@ export function set_up() {
e.stopPropagation(); e.stopPropagation();
const emoji_status = $("#admin-emoji-status"); const emoji_status = $("#admin-emoji-status");
const emoji = {}; const emoji = {};
const formData = new FormData();
for (const obj of $(this).serializeArray()) { function submit_custom_emoji_request() {
emoji[obj.name] = obj.value;
}
if (emoji.name.trim() === "") {
ui_report.client_error(
$t_html({defaultMessage: "Failed: Emoji name is required."}),
emoji_status,
);
return;
}
$("#admin_emoji_submit").prop("disabled", true); $("#admin_emoji_submit").prop("disabled", true);
const formData = new FormData();
for (const [i, file] of Array.prototype.entries.call($("#emoji_file_input")[0].files)) { for (const [i, file] of Array.prototype.entries.call($("#emoji_file_input")[0].files)) {
formData.append("file-" + i, file); formData.append("file-" + i, file);
} }
channel.post({ channel.post({
url: "/json/realm/emoji/" + encodeURIComponent(emoji.name), url: "/json/realm/emoji/" + encodeURIComponent(emoji.name),
data: formData, data: formData,
@ -226,5 +216,20 @@ export function set_up() {
$("#admin_emoji_submit").prop("disabled", false); $("#admin_emoji_submit").prop("disabled", false);
}, },
}); });
}
for (const obj of $(this).serializeArray()) {
emoji[obj.name] = obj.value;
}
if (emoji.name.trim() === "") {
ui_report.client_error(
$t_html({defaultMessage: "Failed: Emoji name is required."}),
emoji_status,
);
return;
}
submit_custom_emoji_request();
}); });
} }