2022-03-04 11:07:16 +01:00
|
|
|
import ClipboardJS from "clipboard";
|
2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-06-21 11:01:44 +02:00
|
|
|
import render_settings_deactivation_stream_modal from "../templates/confirm_dialog/confirm_deactivate_stream.hbs";
|
2023-02-24 11:27:42 +01:00
|
|
|
import render_inline_decorated_stream_name from "../templates/inline_decorated_stream_name.hbs";
|
2021-07-18 14:53:17 +02:00
|
|
|
import render_change_stream_info_modal from "../templates/stream_settings/change_stream_info_modal.hbs";
|
2022-03-04 11:07:16 +01:00
|
|
|
import render_copy_email_address_modal from "../templates/stream_settings/copy_email_address_modal.hbs";
|
2021-07-17 21:24:41 +02:00
|
|
|
import render_stream_description from "../templates/stream_settings/stream_description.hbs";
|
2021-07-18 13:49:31 +02:00
|
|
|
import render_stream_settings from "../templates/stream_settings/stream_settings.hbs";
|
2021-02-28 00:55:38 +01:00
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-03-22 16:09:12 +01:00
|
|
|
import * as browser_history from "./browser_history";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as channel from "./channel";
|
2021-06-26 15:28:24 +02:00
|
|
|
import * as components from "./components";
|
2020-08-07 00:38:19 +02:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2023-09-23 10:07:32 +02:00
|
|
|
import {show_copied_confirmation} from "./copied_tooltip";
|
2021-07-17 16:44:31 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2023-07-19 16:18:20 +02:00
|
|
|
import * as dropdown_widget from "./dropdown_widget";
|
2021-02-28 01:07:13 +01:00
|
|
|
import * as hash_util from "./hash_util";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2022-09-28 08:27:24 +02:00
|
|
|
import * as keydown_util from "./keydown_util";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as narrow_state from "./narrow_state";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2023-04-25 18:01:02 +02:00
|
|
|
import * as scroll_util from "./scroll_util";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2022-10-18 11:03:09 +02:00
|
|
|
import * as settings_org from "./settings_org";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as stream_color from "./stream_color";
|
|
|
|
import * as stream_data from "./stream_data";
|
2022-02-21 18:42:35 +01:00
|
|
|
import * as stream_edit_subscribers from "./stream_edit_subscribers";
|
2023-10-03 21:27:54 +02:00
|
|
|
import * as stream_settings_api from "./stream_settings_api";
|
2021-12-15 15:07:39 +01:00
|
|
|
import * as stream_settings_containers from "./stream_settings_containers";
|
2021-04-04 15:15:18 +02:00
|
|
|
import * as stream_settings_data from "./stream_settings_data";
|
2021-07-09 15:51:31 +02:00
|
|
|
import * as stream_settings_ui from "./stream_settings_ui";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as stream_ui_updates from "./stream_ui_updates";
|
2021-04-15 17:02:54 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-02-28 00:58:55 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2022-09-19 09:18:33 +02:00
|
|
|
import * as user_groups from "./user_groups";
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as util from "./util";
|
|
|
|
|
2021-06-26 15:28:24 +02:00
|
|
|
export let toggler;
|
|
|
|
export let select_tab = "personal_settings";
|
2022-09-19 09:18:33 +02:00
|
|
|
export let can_remove_subscribers_group_widget = null;
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2017-10-03 00:15:42 +02:00
|
|
|
function setup_subscriptions_stream_hash(sub) {
|
2022-03-01 19:14:26 +01:00
|
|
|
const hash = hash_util.stream_edit_url(sub);
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.update(hash);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function setup_subscriptions_tab_hash(tab_key_value) {
|
2023-03-09 19:03:05 +01:00
|
|
|
if ($("#subscription_overlay .right").hasClass("show")) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-06 12:55:16 +02:00
|
|
|
if (tab_key_value === "all-streams") {
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.update("#streams/all");
|
2019-04-06 12:55:16 +02:00
|
|
|
} else if (tab_key_value === "subscribed") {
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.update("#streams/subscribed");
|
2019-04-06 12:55:16 +02:00
|
|
|
} else {
|
|
|
|
blueslip.debug("Unknown tab_key_value: " + tab_key_value);
|
|
|
|
}
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2019-04-06 12:55:16 +02:00
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function get_display_text_for_realm_message_retention_setting() {
|
2020-06-15 17:00:00 +02:00
|
|
|
const realm_message_retention_days = page_params.realm_message_retention_days;
|
2020-06-26 00:10:17 +02:00
|
|
|
if (realm_message_retention_days === settings_config.retain_message_forever) {
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t({defaultMessage: "(forever)"});
|
2020-06-15 17:00:00 +02:00
|
|
|
}
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t(
|
|
|
|
{defaultMessage: "({message_retention_days} days)"},
|
|
|
|
{message_retention_days: realm_message_retention_days},
|
|
|
|
);
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2020-06-15 17:00:00 +02:00
|
|
|
|
2019-04-03 07:14:10 +02:00
|
|
|
function get_stream_id(target) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(target).closest(
|
2023-01-02 18:53:33 +01:00
|
|
|
".stream-row, .stream-notifications-row, .stream_settings_header, .subscription_settings, .save-button",
|
2021-06-26 15:28:24 +02:00
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
return Number.parseInt($row.attr("data-stream-id"), 10);
|
2019-04-03 07:14:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_sub_for_target(target) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = get_stream_id(target);
|
2019-04-03 07:14:10 +02:00
|
|
|
if (!stream_id) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Cannot find stream id for target");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2019-04-03 07:14:10 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2019-04-03 07:14:10 +02:00
|
|
|
if (!sub) {
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.error("get_sub_for_target() failed id lookup", {stream_id});
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2019-04-03 07:14:10 +02:00
|
|
|
}
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function open_edit_panel_for_row(stream_row) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = get_sub_for_target(stream_row);
|
2019-04-03 07:14:10 +02:00
|
|
|
|
2020-07-08 23:54:13 +02:00
|
|
|
$(".stream-row.active").removeClass("active");
|
2022-01-28 11:30:48 +01:00
|
|
|
stream_settings_ui.show_subs_pane.settings(sub);
|
2018-12-01 21:53:09 +01:00
|
|
|
$(stream_row).addClass("active");
|
2019-04-03 07:14:10 +02:00
|
|
|
setup_subscriptions_stream_hash(sub);
|
2021-06-26 15:28:24 +02:00
|
|
|
setup_stream_settings(stream_row);
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2018-12-01 21:53:09 +01:00
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function open_edit_panel_empty() {
|
2022-08-26 08:01:32 +02:00
|
|
|
const tab_key = stream_settings_ui.get_active_data().$tabs.first().attr("data-tab-key");
|
2020-07-08 23:54:13 +02:00
|
|
|
$(".stream-row.active").removeClass("active");
|
2023-03-09 19:03:05 +01:00
|
|
|
$("#subscription_overlay .right").removeClass("show");
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.show_subs_pane.nothing_selected();
|
2021-02-28 00:55:38 +01:00
|
|
|
setup_subscriptions_tab_hash(tab_key);
|
|
|
|
}
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function update_stream_name(sub, new_name) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $edit_container = stream_settings_containers.get_edit_container(sub);
|
|
|
|
$edit_container.find(".email-address").text(sub.email_address);
|
|
|
|
$edit_container.find(".sub-stream-name").text(new_name);
|
2022-01-27 08:58:28 +01:00
|
|
|
|
|
|
|
const active_data = stream_settings_ui.get_active_data();
|
|
|
|
if (active_data.id === sub.stream_id) {
|
|
|
|
stream_settings_ui.set_right_panel_title(sub);
|
|
|
|
}
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function update_stream_description(sub) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $edit_container = stream_settings_containers.get_edit_container(sub);
|
|
|
|
$edit_container.find("input.description").val(sub.description);
|
2021-07-08 23:21:47 +02:00
|
|
|
const html = render_stream_description({
|
|
|
|
rendered_description: util.clean_user_content_links(sub.rendered_description),
|
|
|
|
});
|
2022-01-25 11:36:19 +01:00
|
|
|
$edit_container.find(".stream-description").html(html);
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2020-08-28 10:40:00 +02:00
|
|
|
function show_subscription_settings(sub) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $edit_container = stream_settings_containers.get_edit_container(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $colorpicker = $edit_container.find(".colorpicker");
|
2023-06-27 01:40:25 +02:00
|
|
|
const color = stream_data.get_color(sub.stream_id);
|
2022-01-25 11:36:19 +01:00
|
|
|
stream_color.set_colorpicker_color($colorpicker, color);
|
2019-05-03 07:59:31 +02:00
|
|
|
stream_ui_updates.update_add_subscriptions_elements(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2021-05-04 18:47:17 +02:00
|
|
|
if (!sub.render_subscribers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-19 15:41:15 +01:00
|
|
|
if (!stream_data.can_toggle_subscription(sub)) {
|
2023-05-20 22:15:52 +02:00
|
|
|
stream_ui_updates.initialize_cant_subscribe_popover();
|
2021-12-19 15:41:15 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $subscriber_container = $edit_container.find(".edit_subscribers_for_stream");
|
2022-02-21 18:42:35 +01:00
|
|
|
stream_edit_subscribers.enable_subscriber_management({
|
2021-12-21 17:39:05 +01:00
|
|
|
sub,
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent_container: $subscriber_container,
|
2021-12-21 17:39:05 +01:00
|
|
|
});
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function is_notification_setting(setting_label) {
|
js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitBinaryExpression(path) {
const { operator, left, right } = path.node;
if (
n.CallExpression.check(left) &&
n.MemberExpression.check(left.callee) &&
!left.callee.computed &&
n.Identifier.check(left.callee.property) &&
left.callee.property.name === "indexOf" &&
left.arguments.length === 1 &&
checkExpression(left.arguments[0]) &&
((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
n.UnaryExpression.check(right) &&
right.operator == "-" &&
n.Literal.check(right.argument) &&
right.argument.value === 1) ||
([">=", "<"].includes(operator) &&
n.Literal.check(right) &&
right.value === 0))
) {
const test = b.callExpression(
b.memberExpression(left.callee.object, b.identifier("includes")),
[left.arguments[0]]
);
path.replace(
["!==", "!=", ">", ">="].includes(operator)
? test
: b.unaryExpression("!", test)
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 04:55:06 +01:00
|
|
|
if (setting_label.includes("_notifications")) {
|
2019-06-14 14:42:48 +02:00
|
|
|
return true;
|
js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitBinaryExpression(path) {
const { operator, left, right } = path.node;
if (
n.CallExpression.check(left) &&
n.MemberExpression.check(left.callee) &&
!left.callee.computed &&
n.Identifier.check(left.callee.property) &&
left.callee.property.name === "indexOf" &&
left.arguments.length === 1 &&
checkExpression(left.arguments[0]) &&
((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
n.UnaryExpression.check(right) &&
right.operator == "-" &&
n.Literal.check(right.argument) &&
right.argument.value === 1) ||
([">=", "<"].includes(operator) &&
n.Literal.check(right) &&
right.value === 0))
) {
const test = b.callExpression(
b.memberExpression(left.callee.object, b.identifier("includes")),
[left.arguments[0]]
);
path.replace(
["!==", "!=", ">", ">="].includes(operator)
? test
: b.unaryExpression("!", test)
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 04:55:06 +01:00
|
|
|
} else if (setting_label.includes("_notify")) {
|
2019-11-26 02:37:12 +01:00
|
|
|
return true;
|
2019-06-14 14:42:48 +02:00
|
|
|
}
|
|
|
|
return false;
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2019-06-14 14:42:48 +02:00
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function stream_settings(sub) {
|
2020-04-01 19:43:34 +02:00
|
|
|
const settings_labels = settings_config.general_notifications_table_labels.stream;
|
2021-08-27 15:46:23 +02:00
|
|
|
const check_realm_setting =
|
|
|
|
settings_config.all_notifications(user_settings).show_push_notifications_tooltip;
|
2020-04-01 19:43:34 +02:00
|
|
|
|
2020-01-27 13:18:04 +01:00
|
|
|
const settings = Object.keys(settings_labels).map((setting) => {
|
|
|
|
const ret = {
|
|
|
|
name: setting,
|
|
|
|
label: settings_labels[setting],
|
2020-01-27 18:54:44 +01:00
|
|
|
disabled_realm_setting: check_realm_setting[setting],
|
2020-01-27 18:50:49 +01:00
|
|
|
is_disabled: check_realm_setting[setting],
|
2021-02-28 00:55:38 +01:00
|
|
|
is_notification_setting: is_notification_setting(setting),
|
2020-01-27 13:18:04 +01:00
|
|
|
};
|
2021-02-28 00:55:38 +01:00
|
|
|
if (is_notification_setting(setting)) {
|
2021-04-04 19:35:45 +02:00
|
|
|
// This block ensures we correctly display to users the
|
|
|
|
// current state of stream-level notification settings
|
|
|
|
// with a value of `null`, which inherit the user's global
|
|
|
|
// notification settings for streams.
|
|
|
|
ret.is_checked =
|
|
|
|
stream_data.receives_notifications(sub.stream_id, setting) &&
|
|
|
|
!check_realm_setting[setting];
|
2020-01-27 18:50:49 +01:00
|
|
|
ret.is_disabled = ret.is_disabled || sub.is_muted;
|
2020-01-27 13:18:04 +01:00
|
|
|
return ret;
|
2019-06-14 14:42:48 +02:00
|
|
|
}
|
2020-01-27 18:42:35 +01:00
|
|
|
ret.is_checked = sub[setting] && !check_realm_setting[setting];
|
2020-01-27 13:18:04 +01:00
|
|
|
return ret;
|
2019-06-14 14:42:48 +02:00
|
|
|
});
|
|
|
|
return settings;
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2019-06-14 14:42:48 +02:00
|
|
|
|
2023-07-19 16:18:20 +02:00
|
|
|
function setup_dropdown(sub, slim_sub) {
|
|
|
|
can_remove_subscribers_group_widget = new dropdown_widget.DropdownWidget({
|
|
|
|
widget_name: "can_remove_subscribers_group",
|
|
|
|
get_options: () =>
|
|
|
|
user_groups.get_realm_user_groups_for_dropdown_list_widget(
|
|
|
|
"can_remove_subscribers_group",
|
|
|
|
),
|
|
|
|
item_click_callback(event, dropdown) {
|
|
|
|
dropdown.hide();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
can_remove_subscribers_group_widget.render();
|
|
|
|
settings_org.save_discard_widget_status_handler(
|
|
|
|
$("#stream_permission_settings"),
|
|
|
|
false,
|
|
|
|
slim_sub,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
$events_container: $("#subscription_overlay .subscription_settings"),
|
|
|
|
tippy_props: {
|
|
|
|
placement: "bottom-start",
|
|
|
|
},
|
|
|
|
default_id: sub.can_remove_subscribers_group,
|
|
|
|
unique_id_type: dropdown_widget.DATA_TYPES.NUMBER,
|
|
|
|
on_mount_callback(dropdown) {
|
|
|
|
$(dropdown.popper).css("min-width", "300px");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
can_remove_subscribers_group_widget.setup();
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function show_settings_for(node) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = get_stream_id(node);
|
2021-04-15 17:02:54 +02:00
|
|
|
const slim_sub = sub_store.get(stream_id);
|
2021-04-04 20:00:22 +02:00
|
|
|
stream_data.clean_up_description(slim_sub);
|
|
|
|
const sub = stream_settings_data.get_sub_for_settings(slim_sub);
|
2021-08-06 09:45:45 +02:00
|
|
|
const all_settings = stream_settings(sub);
|
|
|
|
|
|
|
|
const other_settings = [];
|
|
|
|
const notification_settings = all_settings.filter((setting) => {
|
|
|
|
if (setting.is_notification_setting) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
other_settings.push(setting);
|
|
|
|
return false;
|
|
|
|
});
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2021-07-18 13:49:31 +02:00
|
|
|
const html = render_stream_settings({
|
2020-07-20 22:18:43 +02:00
|
|
|
sub,
|
2021-08-06 09:45:45 +02:00
|
|
|
notification_settings,
|
|
|
|
other_settings,
|
2023-10-04 22:48:28 +02:00
|
|
|
stream_post_policy_values: settings_config.stream_post_policy_values,
|
|
|
|
stream_privacy_policy_values: settings_config.stream_privacy_policy_values,
|
2022-10-18 11:03:09 +02:00
|
|
|
stream_privacy_policy: stream_data.get_stream_privacy_policy(stream_id),
|
2023-07-22 12:24:55 +02:00
|
|
|
check_default_stream: stream_data.is_default_stream_id(stream_id),
|
2022-10-18 11:03:09 +02:00
|
|
|
zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
|
|
|
|
upgrade_text_for_wide_organization_logo:
|
|
|
|
page_params.upgrade_text_for_wide_organization_logo,
|
2023-01-06 08:46:50 +01:00
|
|
|
is_business_type_org:
|
|
|
|
page_params.realm_org_type === settings_config.all_org_type_values.business.code,
|
2022-10-18 11:03:09 +02:00
|
|
|
is_admin: page_params.is_admin,
|
|
|
|
org_level_message_retention_setting: get_display_text_for_realm_message_retention_setting(),
|
2019-06-14 14:42:48 +02:00
|
|
|
});
|
2023-04-25 18:01:02 +02:00
|
|
|
scroll_util.get_content_element($("#stream_settings")).html(html);
|
2021-06-26 15:28:24 +02:00
|
|
|
|
|
|
|
$("#stream_settings .tab-container").prepend(toggler.get());
|
|
|
|
stream_ui_updates.update_toggler_for_sub(sub);
|
2017-05-10 20:02:21 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $edit_container = stream_settings_containers.get_edit_container(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2017-05-10 20:02:21 +02:00
|
|
|
$(".nothing-selected").hide();
|
2021-07-05 11:26:23 +02:00
|
|
|
$("#subscription_overlay .stream_change_property_info").hide();
|
2017-07-28 14:07:58 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$edit_container.addClass("show");
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2020-08-28 10:40:00 +02:00
|
|
|
show_subscription_settings(sub);
|
2022-10-18 11:03:09 +02:00
|
|
|
settings_org.set_message_retention_setting_dropdown(sub);
|
|
|
|
stream_ui_updates.enable_or_disable_permission_settings_in_edit_panel(sub);
|
2023-07-19 16:18:20 +02:00
|
|
|
setup_dropdown(sub, slim_sub);
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2017-04-24 04:11:25 +02:00
|
|
|
|
2021-06-26 15:28:24 +02:00
|
|
|
export function setup_stream_settings(node) {
|
|
|
|
toggler = components.toggle({
|
|
|
|
child_wants_focus: true,
|
|
|
|
values: [
|
|
|
|
{label: $t({defaultMessage: "General"}), key: "general_settings"},
|
|
|
|
{label: $t({defaultMessage: "Personal"}), key: "personal_settings"},
|
|
|
|
{label: $t({defaultMessage: "Subscribers"}), key: "subscriber_settings"},
|
|
|
|
],
|
2023-06-29 21:59:08 +02:00
|
|
|
callback(_name, key) {
|
2021-06-26 15:28:24 +02:00
|
|
|
$(".stream_section").hide();
|
2023-04-01 01:42:40 +02:00
|
|
|
$(`.${CSS.escape(key)}`).show();
|
2021-06-26 15:28:24 +02:00
|
|
|
select_tab = key;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
show_settings_for(node);
|
|
|
|
}
|
|
|
|
|
2022-03-03 23:03:32 +01:00
|
|
|
export function update_muting_rendering(sub) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $edit_container = stream_settings_containers.get_edit_container(sub);
|
|
|
|
const $notification_checkboxes = $edit_container.find(".sub_notification_setting");
|
|
|
|
const $is_muted_checkbox = $edit_container.find("#sub_is_muted_setting .sub_setting_control");
|
|
|
|
|
|
|
|
$is_muted_checkbox.prop("checked", sub.is_muted);
|
|
|
|
$edit_container.find(".mute-note").toggleClass("hide-mute-note", !sub.is_muted);
|
|
|
|
$notification_checkboxes.toggleClass("muted-sub", sub.is_muted);
|
|
|
|
$notification_checkboxes.find("input[type='checkbox']").prop("disabled", sub.is_muted);
|
2022-03-03 23:03:32 +01:00
|
|
|
}
|
|
|
|
|
2020-07-22 00:43:11 +02:00
|
|
|
function stream_is_muted_changed(e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = get_sub_for_target(e.target);
|
2017-04-24 04:11:25 +02:00
|
|
|
if (!sub) {
|
2020-07-22 00:43:11 +02:00
|
|
|
blueslip.error("stream_is_muted_changed() fails");
|
2017-04-24 04:11:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-03 21:27:54 +02:00
|
|
|
stream_settings_api.set_stream_property(
|
2021-02-03 23:23:32 +01:00
|
|
|
sub,
|
2023-10-03 21:09:15 +02:00
|
|
|
"is_muted",
|
2021-02-03 23:23:32 +01:00
|
|
|
e.target.checked,
|
|
|
|
`#stream_change_property_status${CSS.escape(sub.stream_id)}`,
|
|
|
|
);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function stream_setting_changed(e, from_notification_settings) {
|
2020-07-22 00:43:11 +02:00
|
|
|
if (e.target.name === "is_muted") {
|
2020-02-04 11:46:36 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-02-04 13:36:10 +01:00
|
|
|
|
2020-04-06 19:31:58 +02:00
|
|
|
const sub = get_sub_for_target(e.target);
|
2020-07-22 00:43:11 +02:00
|
|
|
const status_element = from_notification_settings
|
|
|
|
? $(e.target).closest(".subsection-parent").find(".alert-notification")
|
2021-02-03 23:23:32 +01:00
|
|
|
: $(`#stream_change_property_status${CSS.escape(sub.stream_id)}`);
|
2020-07-22 00:43:11 +02:00
|
|
|
const setting = e.target.name;
|
2019-06-14 15:41:28 +02:00
|
|
|
if (!sub) {
|
2020-07-22 00:43:11 +02:00
|
|
|
blueslip.error("undefined sub in stream_setting_changed()");
|
2019-06-14 15:41:28 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-02-28 00:55:38 +01:00
|
|
|
if (is_notification_setting(setting) && sub[setting] === null) {
|
2022-08-25 21:09:32 +02:00
|
|
|
sub[setting] =
|
|
|
|
user_settings[settings_config.generalize_stream_notification_setting[setting]];
|
2019-06-14 15:41:28 +02:00
|
|
|
}
|
2023-10-03 21:27:54 +02:00
|
|
|
stream_settings_api.set_stream_property(sub, setting, e.target.checked, status_element);
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2018-02-14 14:53:10 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function archive_stream(stream_id, $alert_element, $stream_row) {
|
2018-04-30 14:08:10 +02:00
|
|
|
channel.del({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/streams/" + stream_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2022-01-25 11:36:19 +01:00
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $alert_element);
|
2018-04-30 14:08:10 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_row.remove();
|
2018-04-30 14:08:10 +02:00
|
|
|
},
|
|
|
|
});
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|
2018-04-30 14:08:10 +02:00
|
|
|
|
2022-03-04 11:14:07 +01:00
|
|
|
export function get_stream_email_address(flags, address) {
|
|
|
|
const clean_address = address
|
|
|
|
.replace(".show-sender", "")
|
|
|
|
.replace(".include-footer", "")
|
|
|
|
.replace(".include-quotes", "")
|
|
|
|
.replace(".prefer-html", "");
|
|
|
|
|
|
|
|
const flag_string = flags.map((flag) => "." + flag).join("");
|
|
|
|
|
|
|
|
return clean_address.replace("@", flag_string + "@");
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:55:38 +01:00
|
|
|
export function initialize() {
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#main_div").on("click", ".stream_sub_unsub_button", (e) => {
|
2017-04-24 04:11:25 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2020-07-08 22:45:35 +02:00
|
|
|
const sub = narrow_state.stream_sub();
|
|
|
|
if (sub === undefined) {
|
2017-04-24 04:11:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-07-08 22:45:35 +02:00
|
|
|
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.sub_or_unsub(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
});
|
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("click", "#open_stream_info_modal", (e) => {
|
2021-07-05 11:26:23 +02:00
|
|
|
e.preventDefault();
|
2018-05-31 19:20:23 +02:00
|
|
|
e.stopPropagation();
|
2021-07-05 11:26:23 +02:00
|
|
|
const stream_id = get_stream_id(e.target);
|
|
|
|
const stream = sub_store.get(stream_id);
|
|
|
|
const template_data = {
|
|
|
|
stream_name: stream.name,
|
|
|
|
stream_description: stream.description,
|
2022-11-28 11:54:18 +01:00
|
|
|
max_stream_name_length: page_params.max_stream_name_length,
|
|
|
|
max_stream_description_length: page_params.max_stream_description_length,
|
2021-07-05 11:26:23 +02:00
|
|
|
};
|
|
|
|
const change_stream_info_modal = render_change_stream_info_modal(template_data);
|
2021-07-17 16:44:31 +02:00
|
|
|
dialog_widget.launch({
|
|
|
|
html_heading: $t_html(
|
|
|
|
{defaultMessage: "Edit #{stream_name}"},
|
|
|
|
{stream_name: stream.name},
|
|
|
|
),
|
|
|
|
html_body: change_stream_info_modal,
|
|
|
|
id: "change_stream_info_modal",
|
2023-03-07 15:18:38 +01:00
|
|
|
loading_spinner: true,
|
2021-07-17 16:44:31 +02:00
|
|
|
on_click: save_stream_info,
|
2022-11-17 23:33:43 +01:00
|
|
|
post_render() {
|
2021-07-17 16:44:31 +02:00
|
|
|
$("#change_stream_info_modal .dialog_submit_button")
|
|
|
|
.addClass("save-button")
|
|
|
|
.attr("data-stream-id", stream_id);
|
|
|
|
},
|
2023-09-20 08:44:27 +02:00
|
|
|
update_submit_disabled_state_on_change: true,
|
2021-07-17 16:44:31 +02:00
|
|
|
});
|
2017-04-24 04:11:25 +02:00
|
|
|
});
|
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("keypress", "#change_stream_description", (e) => {
|
2021-07-05 11:26:23 +02:00
|
|
|
// Stream descriptions can not be multiline, so disable enter key
|
|
|
|
// to prevent new line
|
2022-09-28 08:27:24 +02:00
|
|
|
if (keydown_util.is_enter_event(e)) {
|
2021-07-05 11:26:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2023-08-09 22:30:51 +02:00
|
|
|
$("#streams_overlay_container").on(
|
|
|
|
"click",
|
|
|
|
".stream-permissions-warning-banner .main-view-banner-close-button",
|
|
|
|
(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
$("#stream_permission_settings .stream-permissions-warning-banner").empty();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
$("#streams_overlay_container").on(
|
|
|
|
"click",
|
|
|
|
".stream-permissions-warning-banner .main-view-banner-action-button",
|
|
|
|
(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
const $target = $(event.target).parents(".main-view-banner");
|
|
|
|
const stream_id = Number.parseInt($target.attr("data-stream-id"), 10);
|
|
|
|
// Makes sure we take the correct stream_row.
|
|
|
|
const $stream_row = $(
|
|
|
|
`#streams_overlay_container div.stream-row[data-stream-id='${CSS.escape(
|
|
|
|
stream_id,
|
|
|
|
)}']`,
|
|
|
|
);
|
|
|
|
const sub = sub_store.get(stream_id);
|
|
|
|
stream_settings_ui.sub_or_unsub(sub, $stream_row);
|
|
|
|
$("#stream_permission_settings .stream-permissions-warning-banner").empty();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-07-17 16:44:31 +02:00
|
|
|
function save_stream_info(e) {
|
2021-07-05 11:26:23 +02:00
|
|
|
const sub = get_sub_for_target(e.currentTarget);
|
|
|
|
|
|
|
|
const url = `/json/streams/${sub.stream_id}`;
|
|
|
|
const data = {};
|
|
|
|
const new_name = $("#change_stream_name").val().trim();
|
|
|
|
const new_description = $("#change_stream_description").val().trim();
|
|
|
|
|
|
|
|
if (new_name !== sub.name) {
|
|
|
|
data.new_name = new_name;
|
|
|
|
}
|
|
|
|
if (new_description !== sub.description) {
|
|
|
|
data.description = new_description;
|
|
|
|
}
|
|
|
|
|
2023-03-07 15:18:38 +01:00
|
|
|
dialog_widget.submit_api_request(channel.patch, url, data);
|
2021-07-17 16:44:31 +02:00
|
|
|
}
|
2021-07-05 11:26:23 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("click", ".copy_email_button", (e) => {
|
2022-03-04 11:07:16 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
const stream_id = get_stream_id(e.target);
|
|
|
|
const stream = sub_store.get(stream_id);
|
2022-03-04 11:14:07 +01:00
|
|
|
let address = stream.email_address;
|
2022-03-04 11:07:16 +01:00
|
|
|
|
|
|
|
const copy_email_address = render_copy_email_address_modal({
|
|
|
|
email_address: address,
|
2022-03-04 11:14:07 +01:00
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
name: "show-sender",
|
|
|
|
description: $t({
|
|
|
|
defaultMessage: "The sender's email address",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "include-footer",
|
|
|
|
description: $t({defaultMessage: "Email footers (e.g., signature)"}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "include-quotes",
|
|
|
|
description: $t({defaultMessage: "Quoted original email (in replies)"}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "prefer-html",
|
|
|
|
description: $t({
|
|
|
|
defaultMessage: "Use html encoding (not recommended)",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
],
|
2022-03-04 11:07:16 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
dialog_widget.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Generate stream email address"}),
|
|
|
|
html_body: copy_email_address,
|
|
|
|
id: "copy_email_address_modal",
|
|
|
|
html_submit_button: $t_html({defaultMessage: "Copy address"}),
|
2023-07-25 05:41:52 +02:00
|
|
|
html_exit_button: $t_html({defaultMessage: "Close"}),
|
2022-03-04 11:14:07 +01:00
|
|
|
help_link: "/help/message-a-stream-by-email#configuration-options",
|
2022-11-17 23:33:43 +01:00
|
|
|
on_click() {},
|
2023-07-09 20:47:32 +02:00
|
|
|
close_on_submit: false,
|
2022-03-04 11:07:16 +01:00
|
|
|
});
|
2022-03-04 11:14:07 +01:00
|
|
|
$("#show-sender").prop("checked", true);
|
2022-03-04 11:07:16 +01:00
|
|
|
|
2023-07-09 20:47:32 +02:00
|
|
|
const clipboard = new ClipboardJS("#copy_email_address_modal .dialog_submit_button", {
|
2022-03-04 11:07:16 +01:00
|
|
|
text() {
|
|
|
|
return address;
|
|
|
|
},
|
|
|
|
});
|
2022-03-04 11:14:07 +01:00
|
|
|
|
2023-07-09 20:47:32 +02:00
|
|
|
// Show a tippy tooltip when the stream email address copied
|
|
|
|
clipboard.on("success", (e) => {
|
|
|
|
show_copied_confirmation(e.trigger);
|
|
|
|
});
|
|
|
|
|
2022-03-04 11:14:07 +01:00
|
|
|
$("#copy_email_address_modal .tag-checkbox").on("change", () => {
|
|
|
|
const $checked_checkboxes = $(".copy-email-modal").find("input:checked");
|
|
|
|
|
|
|
|
const flags = [];
|
|
|
|
|
|
|
|
$($checked_checkboxes).each(function () {
|
|
|
|
flags.push($(this).attr("id"));
|
|
|
|
});
|
|
|
|
|
|
|
|
address = get_stream_email_address(flags, address);
|
|
|
|
|
|
|
|
$(".email-address").text(address);
|
|
|
|
});
|
2022-03-04 11:07:16 +01:00
|
|
|
});
|
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on(
|
2020-07-22 00:43:11 +02:00
|
|
|
"change",
|
|
|
|
"#sub_is_muted_setting .sub_setting_control",
|
|
|
|
stream_is_muted_changed,
|
|
|
|
);
|
2019-06-14 15:41:28 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on(
|
2020-07-22 00:43:11 +02:00
|
|
|
"change",
|
|
|
|
".sub_setting_checkbox .sub_setting_control",
|
2021-02-28 00:55:38 +01:00
|
|
|
stream_setting_changed,
|
2020-07-22 00:43:11 +02:00
|
|
|
);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
|
|
|
// This handler isn't part of the normal edit interface; it's the convenient
|
|
|
|
// checkmark in the subscriber list.
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("click", ".sub_unsub_button", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = get_sub_for_target(e.target);
|
2020-04-26 21:36:28 +02:00
|
|
|
// Makes sure we take the correct stream_row.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_row = $(
|
2023-04-18 04:45:32 +02:00
|
|
|
`#streams_overlay_container div.stream-row[data-stream-id='${CSS.escape(
|
2021-12-21 19:41:13 +01:00
|
|
|
sub.stream_id,
|
|
|
|
)}']`,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
stream_settings_ui.sub_or_unsub(sub, $stream_row);
|
2020-04-23 23:49:50 +02:00
|
|
|
|
2017-04-24 04:11:25 +02:00
|
|
|
if (!sub.subscribed) {
|
2022-01-25 11:36:19 +01:00
|
|
|
open_edit_panel_for_row($stream_row);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
2019-04-02 18:37:24 +02:00
|
|
|
stream_ui_updates.update_regular_sub_settings(sub);
|
2017-04-24 04:11:25 +02:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("click", ".deactivate", (e) => {
|
2018-02-13 11:47:17 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = get_stream_id(e.target);
|
2018-02-13 11:47:17 +01:00
|
|
|
if (!stream_id) {
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.client_error(
|
2022-05-27 14:04:40 +02:00
|
|
|
$t_html({defaultMessage: "Invalid stream ID"}),
|
2021-04-13 05:18:25 +02:00
|
|
|
$(".stream_change_property_info"),
|
|
|
|
);
|
2018-02-13 11:47:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-05-26 18:27:48 +02:00
|
|
|
|
|
|
|
function do_archive_stream() {
|
2021-07-05 12:41:37 +02:00
|
|
|
const stream_id = $(".dialog_submit_button").data("stream-id");
|
2021-05-26 18:27:48 +02:00
|
|
|
if (!stream_id) {
|
|
|
|
ui_report.client_error(
|
2022-05-27 14:04:40 +02:00
|
|
|
$t_html({defaultMessage: "Invalid stream ID"}),
|
2021-05-26 18:27:48 +02:00
|
|
|
$(".stream_change_property_info"),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(".stream-row.active");
|
|
|
|
archive_stream(stream_id, $(".stream_change_property_info"), $row);
|
2021-05-26 18:27:48 +02:00
|
|
|
}
|
|
|
|
|
2022-08-04 19:41:55 +02:00
|
|
|
const stream = sub_store.get(stream_id);
|
2023-02-24 11:27:42 +01:00
|
|
|
|
|
|
|
const stream_name_with_privacy_symbol_html = render_inline_decorated_stream_name({stream});
|
2023-06-25 12:06:27 +02:00
|
|
|
|
|
|
|
const is_new_stream_notification_stream =
|
|
|
|
stream_id === page_params.realm_notifications_stream_id;
|
|
|
|
const is_signup_notification_stream =
|
|
|
|
stream_id === page_params.realm_signup_notifications_stream_id;
|
|
|
|
const is_notification_stream =
|
|
|
|
is_new_stream_notification_stream || is_signup_notification_stream;
|
|
|
|
|
2021-05-26 18:27:48 +02:00
|
|
|
const html_body = render_settings_deactivation_stream_modal({
|
2023-02-24 11:27:42 +01:00
|
|
|
stream_name_with_privacy_symbol_html,
|
2023-06-25 12:06:27 +02:00
|
|
|
is_new_stream_notification_stream,
|
|
|
|
is_signup_notification_stream,
|
|
|
|
is_notification_stream,
|
2019-06-12 21:01:38 +02:00
|
|
|
});
|
2018-02-13 11:47:17 +01:00
|
|
|
|
2021-05-26 18:27:48 +02:00
|
|
|
confirm_dialog.launch({
|
|
|
|
html_heading: $t_html(
|
2023-02-24 11:27:42 +01:00
|
|
|
{defaultMessage: "Archive <z-link></z-link>?"},
|
|
|
|
{"z-link": () => stream_name_with_privacy_symbol_html},
|
2021-05-26 18:27:48 +02:00
|
|
|
),
|
2022-08-04 19:41:55 +02:00
|
|
|
id: "archive-stream-modal",
|
2021-05-26 18:27:48 +02:00
|
|
|
help_link: "/help/archive-a-stream",
|
|
|
|
html_body,
|
|
|
|
on_click: do_archive_stream,
|
|
|
|
});
|
|
|
|
|
2021-07-05 12:41:37 +02:00
|
|
|
$(".dialog_submit_button").attr("data-stream-id", stream_id);
|
2018-02-13 11:47:17 +01:00
|
|
|
});
|
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("click", ".stream-row", function (e) {
|
2017-04-24 04:11:25 +02:00
|
|
|
if ($(e.target).closest(".check, .subscription_settings").length === 0) {
|
2021-02-28 00:55:38 +01:00
|
|
|
open_edit_panel_for_row(this);
|
2017-04-24 04:11:25 +02:00
|
|
|
}
|
|
|
|
});
|
2022-10-18 11:03:09 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("change", ".stream_message_retention_setting", (e) => {
|
2022-10-18 11:03:09 +02:00
|
|
|
const message_retention_setting_dropdown_value = e.target.value;
|
|
|
|
settings_org.change_element_block_display_property(
|
|
|
|
"stream_message_retention_custom_input",
|
|
|
|
message_retention_setting_dropdown_value === "custom_period",
|
|
|
|
);
|
|
|
|
});
|
2022-10-18 11:36:52 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on("change input", "input, select, textarea", (e) => {
|
2022-10-18 11:36:52 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2022-09-19 09:18:33 +02:00
|
|
|
if ($(e.target).hasClass("no-input-change-detection")) {
|
|
|
|
// This is to prevent input changes detection in elements
|
|
|
|
// within a subsection whose changes should not affect the
|
|
|
|
// visibility of the discard button
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-18 11:36:52 +02:00
|
|
|
const stream_id = get_stream_id(e.target);
|
|
|
|
const sub = sub_store.get(stream_id);
|
|
|
|
const $subsection = $(e.target).closest(".settings-subsection-parent");
|
|
|
|
settings_org.save_discard_widget_status_handler($subsection, false, sub);
|
2023-07-22 12:24:55 +02:00
|
|
|
if (sub) {
|
|
|
|
stream_ui_updates.update_default_stream_and_stream_privacy_state($subsection);
|
|
|
|
}
|
2022-09-19 09:18:33 +02:00
|
|
|
return true;
|
2022-10-18 11:36:52 +02:00
|
|
|
});
|
2022-10-18 11:56:03 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on(
|
2022-10-18 12:05:56 +02:00
|
|
|
"click",
|
|
|
|
".subsection-header .subsection-changes-save button",
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const $save_button = $(e.currentTarget);
|
|
|
|
const $subsection_elem = $save_button.closest(".settings-subsection-parent");
|
|
|
|
|
|
|
|
const stream_id = $save_button.closest(".subscription_settings.show").data("stream-id");
|
|
|
|
const sub = sub_store.get(stream_id);
|
|
|
|
const data = settings_org.populate_data_for_request($subsection_elem, false, sub);
|
|
|
|
|
|
|
|
const url = "/json/streams/" + stream_id;
|
|
|
|
settings_org.save_organization_settings(data, $save_button, url);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container").on(
|
2022-10-18 11:56:03 +02:00
|
|
|
"click",
|
|
|
|
".subsection-header .subsection-changes-discard button",
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
const stream_id = $(e.target).closest(".subscription_settings.show").data("stream-id");
|
|
|
|
const sub = sub_store.get(stream_id);
|
|
|
|
|
|
|
|
const $subsection = $(e.target).closest(".settings-subsection-parent");
|
|
|
|
for (const elem of settings_org.get_subsection_property_elements($subsection)) {
|
|
|
|
settings_org.discard_property_element_changes(elem, false, sub);
|
|
|
|
}
|
2023-07-22 12:24:55 +02:00
|
|
|
stream_ui_updates.update_default_stream_and_stream_privacy_state($subsection);
|
2022-10-18 11:56:03 +02:00
|
|
|
const $save_btn_controls = $(e.target).closest(".save-button-controls");
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "discarded");
|
|
|
|
},
|
|
|
|
);
|
2021-02-28 00:55:38 +01:00
|
|
|
}
|