stream_settings: Split code for disabling the stream-privacy choices.

This commit splits the hide_or_disable_stream_privacy_options_if_required
function into three separate functions for public, private and web-public
streams. This is a prep commit for live-updating the stream-privacy choices
on changing the realm setting.
This commit is contained in:
Sahil Batra 2021-11-24 17:41:44 +05:30 committed by Tim Abbott
parent 4eeee7296e
commit 15cf972a8e
1 changed files with 44 additions and 34 deletions

View File

@ -988,12 +988,9 @@ export function sub_or_unsub(sub, stream_row) {
}
}
export function hide_or_disable_stream_privacy_options_if_required(container) {
if (!settings_data.user_can_create_web_public_streams()) {
export function hide_or_disable_web_public_stream_privacy_option(container) {
const web_public_stream_elem = container.find(
`input[value='${CSS.escape(
stream_data.stream_privacy_policy_values.web_public.code,
)}']`,
`input[value='${CSS.escape(stream_data.stream_privacy_policy_values.web_public.code)}']`,
);
if (!web_public_stream_elem.is(":checked")) {
if (
@ -1010,14 +1007,14 @@ export function hide_or_disable_stream_privacy_options_if_required(container) {
}
}
if (!settings_data.user_can_create_public_streams()) {
export function disable_public_stream_privacy_option(container) {
const public_stream_elem = container.find(
`input[value='${CSS.escape(stream_data.stream_privacy_policy_values.public.code)}']`,
);
public_stream_elem.prop("disabled", true);
}
if (!settings_data.user_can_create_private_streams()) {
export function disable_private_stream_privacy_option(container) {
// Disable both "Private, shared history" and "Private, protected history" options.
const private_stream_elem = container.find(
`input[value='${CSS.escape(stream_data.stream_privacy_policy_values.private.code)}']`,
@ -1031,6 +1028,19 @@ export function hide_or_disable_stream_privacy_options_if_required(container) {
private_stream_elem.prop("disabled", true);
private_with_public_history_elem.prop("disabled", true);
}
export function hide_or_disable_stream_privacy_options_if_required(container) {
if (!settings_data.user_can_create_web_public_streams()) {
hide_or_disable_web_public_stream_privacy_option(container);
}
if (!settings_data.user_can_create_public_streams()) {
disable_public_stream_privacy_option(container);
}
if (!settings_data.user_can_create_private_streams()) {
disable_private_stream_privacy_option(container);
}
}
export function initialize() {