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.

settings: Add avatar change option to bot edit modal in org settings.

Sahil Batra7f53699a3aae
diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js
index 0572aba659b..f17b8e58f7d 100644
--- a/static/js/settings_bots.js
+++ b/static/js/settings_bots.js
@@ -20,6 +20,7 @@ import * as loading from "./loading";
import {page_params} from "./page_params";
import * as people from "./people";
import * as settings_config from "./settings_config";
+import * as ui_report from "./ui_report";
const OUTGOING_WEBHOOK_BOT_TYPE = "3";
const GENERIC_BOT_TYPE = "1";
@@ -254,26 +255,45 @@ export function show_edit_bot_info_modal(user_id, from_user_info_popover) {
});
let owner_widget;
+ let avatar_widget;
function submit_bot_details() {
const role = Number.parseInt($("#bot-role-select").val().trim(), 10);
const $full_name = $("#dialog_widget_modal").find("input[name='full_name']");
+ const url = "/json/bots/" + encodeURIComponent(bot.user_id);
- const url = "/json/bots/" + encodeURIComponent(user_id);
- const data = {
- full_name: $full_name.val(),
- role: JSON.stringify(role),
- };
+ const formData = new FormData();
+ formData.append("csrfmiddlewaretoken", csrf_token);
+ formData.append("full_name", $full_name.val());
+ formData.append("role", JSON.stringify(role));
if (owner_widget === undefined) {
blueslip.error("get_bot_owner_widget not called");
}
const human_user_id = owner_widget.value();
if (human_user_id) {
- data.bot_owner_id = human_user_id;
+ formData.append("bot_owner_id", human_user_id);
+ }
+
+ const $file_input = $("#bot-edit-form").find(".edit_bot_avatar_file_input");
+ for (const [i, file] of Array.prototype.entries.call($file_input[0].files)) {
+ formData.append("file-" + i, file);
}
- dialog_widget.submit_api_request(channel.patch, url, data);
+ channel.patch({
+ url,
+ data: formData,
+ processData: false,
+ contentType: false,
+ success() {
+ avatar_widget.clear();
+ dialog_widget.close_modal();
+ },
+ error(xhr) {
+ ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $("#dialog_error"));
+ dialog_widget.hide_dialog_spinner();
+ },
+ });
}
function edit_bot_post_render() {
@@ -303,6 +323,8 @@ export function show_edit_bot_info_modal(user_id, from_user_info_popover) {
.hide();
}
+ avatar_widget = avatar.build_bot_edit_widget($("#bot-edit-form"));
+
$("#bot-edit-form").on("click", ".deactivate_bot_button", (e) => {
e.preventDefault();
e.stopPropagation();
diff --git a/static/templates/settings/edit_bot_form.hbs b/static/templates/settings/edit_bot_form.hbs
index a99b56331c4..17c59033f4a 100644
--- a/static/templates/settings/edit_bot_form.hbs
+++ b/static/templates/settings/edit_bot_form.hbs
@@ -27,6 +27,14 @@
widget_name="edit_bot_owner"
list_placeholder=(t 'Filter users')}}
</div>
+ <div class="input-group edit-avatar-section">
+ <label>Avatar</label>
+ <input type="file" name="bot_avatar_file_input" class="notvisible edit_bot_avatar_file_input" value="{{t 'Upload profile picture' }}" />
+ <div class="edit_bot_avatar_file"></div>
+ <button type="button" class="button white rounded edit_bot_avatar_upload_button">{{t "Choose avatar" }}</button>
+ <button type="button" class="button white rounded edit_bot_avatar_clear_button" style="display: none;">{{t "Clear profile picture" }}</button>
+ <div><label for="edit_bot_avatar_file" generated="true" class="edit_bot_avatar_error text-error"></label></div>
+ </div>
<div class="input-group new-style">
<button class="button rounded btn-danger deactivate_bot_button">
{{t 'Deactivate bot' }}