mirror of https://github.com/zulip/zulip.git
settings: Move show_edit_bot_info_modal to settings_bots.
We move show_edit_bot_info_modal function to settings_bots.js as this code will be used for modals opened from the personal bot settings section as well when we would make both the modals same and this will help us in avoiding cyclic imports.
This commit is contained in:
parent
25df7088e5
commit
f9a5c39908
|
@ -42,6 +42,7 @@ import * as realm_playground from "./realm_playground";
|
|||
import * as reminder from "./reminder";
|
||||
import * as resize from "./resize";
|
||||
import * as rows from "./rows";
|
||||
import * as settings_bots from "./settings_bots";
|
||||
import * as settings_config from "./settings_config";
|
||||
import * as settings_data from "./settings_data";
|
||||
import * as settings_users from "./settings_users";
|
||||
|
@ -1296,7 +1297,7 @@ export function register_click_handlers() {
|
|||
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
||||
const user = people.get_by_user_id(user_id);
|
||||
if (user.is_bot) {
|
||||
settings_users.show_edit_bot_info_modal(user_id, true);
|
||||
settings_bots.show_edit_bot_info_modal(user_id, true);
|
||||
} else {
|
||||
settings_users.show_edit_user_info_modal(user_id, true);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ import $ from "jquery";
|
|||
|
||||
import render_bot_avatar_row from "../templates/settings/bot_avatar_row.hbs";
|
||||
import render_edit_bot from "../templates/settings/edit_bot.hbs";
|
||||
import render_edit_bot_form from "../templates/settings/edit_bot_form.hbs";
|
||||
import render_settings_edit_embedded_bot_service from "../templates/settings/edit_embedded_bot_service.hbs";
|
||||
import render_settings_edit_outgoing_webhook_service from "../templates/settings/edit_outgoing_webhook_service.hbs";
|
||||
|
||||
import * as avatar from "./avatar";
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as bot_data from "./bot_data";
|
||||
import * as channel from "./channel";
|
||||
import {csrf_token} from "./csrf";
|
||||
|
@ -16,6 +18,7 @@ import {$t, $t_html} from "./i18n";
|
|||
import * as loading from "./loading";
|
||||
import {page_params} from "./page_params";
|
||||
import * as people from "./people";
|
||||
import * as settings_config from "./settings_config";
|
||||
|
||||
const OUTGOING_WEBHOOK_BOT_TYPE = "3";
|
||||
const GENERIC_BOT_TYPE = "1";
|
||||
|
@ -220,6 +223,95 @@ export function update_bot_permissions_ui() {
|
|||
}
|
||||
}
|
||||
|
||||
export function show_edit_bot_info_modal(user_id, from_user_info_popover) {
|
||||
const bot = people.get_by_user_id(user_id);
|
||||
|
||||
if (!bot) {
|
||||
return;
|
||||
}
|
||||
|
||||
const html_body = render_edit_bot_form({
|
||||
user_id,
|
||||
email: bot.email,
|
||||
full_name: bot.full_name,
|
||||
user_role_values: settings_config.user_role_values,
|
||||
disable_role_dropdown: bot.is_owner && !page_params.is_owner,
|
||||
});
|
||||
|
||||
let owner_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(user_id);
|
||||
const data = {
|
||||
full_name: $full_name.val(),
|
||||
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;
|
||||
}
|
||||
|
||||
dialog_widget.submit_api_request(channel.patch, url, data);
|
||||
}
|
||||
|
||||
function edit_bot_post_render() {
|
||||
const owner_id = bot_data.get(user_id).owner_id;
|
||||
|
||||
const user_ids = people.get_active_human_ids();
|
||||
const users_list = user_ids.map((user_id) => ({
|
||||
name: people.get_full_name(user_id),
|
||||
value: user_id.toString(),
|
||||
}));
|
||||
|
||||
const opts = {
|
||||
widget_name: "edit_bot_owner",
|
||||
data: users_list,
|
||||
default_text: $t({defaultMessage: "No owner"}),
|
||||
value: owner_id,
|
||||
};
|
||||
// Note: Rendering this is quite expensive in
|
||||
// organizations with 10Ks of users.
|
||||
owner_widget = new DropdownListWidget(opts);
|
||||
owner_widget.setup();
|
||||
|
||||
$("#bot-role-select").val(bot.role);
|
||||
if (!page_params.is_owner) {
|
||||
$("#bot-role-select")
|
||||
.find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`)
|
||||
.hide();
|
||||
}
|
||||
|
||||
$("#bot-edit-form").on("click", ".deactivate_bot_button", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const bot_id = $("#bot-edit-form").data("user-id");
|
||||
function handle_confirm() {
|
||||
const url = "/json/bots/" + encodeURIComponent(bot_id);
|
||||
dialog_widget.submit_api_request(channel.del, url);
|
||||
}
|
||||
const open_deactivate_modal_callback = () =>
|
||||
confirm_bot_deactivation(bot_id, handle_confirm, true);
|
||||
dialog_widget.close_modal(open_deactivate_modal_callback);
|
||||
});
|
||||
}
|
||||
|
||||
dialog_widget.launch({
|
||||
html_heading: $t_html({defaultMessage: "Manage bot"}),
|
||||
html_body,
|
||||
id: "edit_bot_modal",
|
||||
on_click: submit_bot_details,
|
||||
post_render: edit_bot_post_render,
|
||||
loading_spinner: from_user_info_popover,
|
||||
});
|
||||
}
|
||||
|
||||
export function set_up() {
|
||||
$("#payload_url_inputbox").hide();
|
||||
$("#create_payload_url").val("");
|
||||
|
|
|
@ -5,14 +5,12 @@ import render_settings_deactivation_user_modal from "../templates/confirm_dialog
|
|||
import render_settings_reactivation_user_modal from "../templates/confirm_dialog/confirm_reactivate_user.hbs";
|
||||
import render_admin_human_form from "../templates/settings/admin_human_form.hbs";
|
||||
import render_admin_user_list from "../templates/settings/admin_user_list.hbs";
|
||||
import render_edit_bot_form from "../templates/settings/edit_bot_form.hbs";
|
||||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as bot_data from "./bot_data";
|
||||
import * as channel from "./channel";
|
||||
import * as confirm_dialog from "./confirm_dialog";
|
||||
import * as dialog_widget from "./dialog_widget";
|
||||
import {DropdownListWidget} from "./dropdown_list_widget";
|
||||
import {$t, $t_html} from "./i18n";
|
||||
import * as ListWidget from "./list_widget";
|
||||
import * as loading from "./loading";
|
||||
|
@ -652,101 +650,12 @@ function handle_human_form($tbody) {
|
|||
});
|
||||
}
|
||||
|
||||
export function show_edit_bot_info_modal(user_id, from_user_info_popover) {
|
||||
const bot = people.get_by_user_id(user_id);
|
||||
|
||||
if (!bot) {
|
||||
return;
|
||||
}
|
||||
|
||||
const html_body = render_edit_bot_form({
|
||||
user_id,
|
||||
email: bot.email,
|
||||
full_name: bot.full_name,
|
||||
user_role_values: settings_config.user_role_values,
|
||||
disable_role_dropdown: bot.is_owner && !page_params.is_owner,
|
||||
});
|
||||
|
||||
let owner_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(user_id);
|
||||
const data = {
|
||||
full_name: $full_name.val(),
|
||||
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;
|
||||
}
|
||||
|
||||
dialog_widget.submit_api_request(channel.patch, url, data);
|
||||
}
|
||||
|
||||
function edit_bot_post_render() {
|
||||
const owner_id = bot_data.get(user_id).owner_id;
|
||||
|
||||
const user_ids = people.get_active_human_ids();
|
||||
const users_list = user_ids.map((user_id) => ({
|
||||
name: people.get_full_name(user_id),
|
||||
value: user_id.toString(),
|
||||
}));
|
||||
|
||||
const opts = {
|
||||
widget_name: "edit_bot_owner",
|
||||
data: users_list,
|
||||
default_text: $t({defaultMessage: "No owner"}),
|
||||
value: owner_id,
|
||||
};
|
||||
// Note: Rendering this is quite expensive in
|
||||
// organizations with 10Ks of users.
|
||||
owner_widget = new DropdownListWidget(opts);
|
||||
owner_widget.setup();
|
||||
|
||||
$("#bot-role-select").val(bot.role);
|
||||
if (!page_params.is_owner) {
|
||||
$("#bot-role-select")
|
||||
.find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`)
|
||||
.hide();
|
||||
}
|
||||
|
||||
$("#bot-edit-form").on("click", ".deactivate_bot_button", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const bot_id = $("#bot-edit-form").data("user-id");
|
||||
function handle_confirm() {
|
||||
const url = "/json/bots/" + encodeURIComponent(bot_id);
|
||||
dialog_widget.submit_api_request(channel.del, url);
|
||||
}
|
||||
const open_deactivate_modal_callback = () =>
|
||||
confirm_bot_deactivation(bot_id, handle_confirm, true);
|
||||
dialog_widget.close_modal(open_deactivate_modal_callback);
|
||||
});
|
||||
}
|
||||
|
||||
dialog_widget.launch({
|
||||
html_heading: $t_html({defaultMessage: "Manage bot"}),
|
||||
html_body,
|
||||
id: "edit_bot_modal",
|
||||
on_click: submit_bot_details,
|
||||
post_render: edit_bot_post_render,
|
||||
loading_spinner: from_user_info_popover,
|
||||
});
|
||||
}
|
||||
|
||||
function handle_bot_form($tbody) {
|
||||
$tbody.on("click", ".open-user-form", (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
const user_id = Number.parseInt($(e.currentTarget).attr("data-user-id"), 10);
|
||||
show_edit_bot_info_modal(user_id, false);
|
||||
settings_bots.show_edit_bot_info_modal(user_id, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue