2019-11-02 00:06:25 +01:00
|
|
|
const render_settings_admin_auth_methods_list = require('../templates/settings/admin_auth_methods_list.hbs');
|
|
|
|
const render_settings_admin_realm_domains_list = require("../templates/settings/admin_realm_domains_list.hbs");
|
|
|
|
const render_settings_admin_realm_dropdown_stream_list = require("../templates/settings/admin_realm_dropdown_stream_list.hbs");
|
|
|
|
const render_settings_organization_settings_tip = require("../templates/settings/organization_settings_tip.hbs");
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const meta = {
|
2017-04-08 18:13:39 +02:00
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2017-04-17 16:51:27 +02:00
|
|
|
exports.reset = function () {
|
|
|
|
meta.loaded = false;
|
|
|
|
};
|
|
|
|
|
2018-08-03 22:52:21 +02:00
|
|
|
|
2018-12-08 17:37:57 +01:00
|
|
|
exports.maybe_disable_widgets = function () {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-profile']")
|
|
|
|
.find("input, textarea, button, select").attr("disabled", true);
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-settings']")
|
|
|
|
.find("input, textarea, button, select").attr("disabled", true);
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-settings']")
|
|
|
|
.find(".control-label-disabled").addClass('enabled');
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-permissions']")
|
|
|
|
.find("input, textarea, button, select").attr("disabled", true);
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-permissions']")
|
|
|
|
.find(".control-label-disabled").addClass('enabled');
|
|
|
|
|
|
|
|
$(".organization-box [data-name='auth-methods']")
|
|
|
|
.find("input, button, select, checked").attr("disabled", true);
|
|
|
|
};
|
|
|
|
|
2018-08-03 22:52:21 +02:00
|
|
|
exports.email_address_visibility_values = {
|
|
|
|
everyone: {
|
|
|
|
code: 1,
|
2019-05-22 07:58:00 +02:00
|
|
|
description: i18n.t("Admins, members, and guests"),
|
2018-08-03 22:52:21 +02:00
|
|
|
},
|
|
|
|
//// Backend support for this configuration is not available yet.
|
|
|
|
// admins_and_members: {
|
|
|
|
// code: 2,
|
|
|
|
// description: i18n.t("Members and admins"),
|
|
|
|
// },
|
|
|
|
admins_only: {
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins only"),
|
2018-03-28 23:53:20 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-23 07:01:34 +01:00
|
|
|
exports.create_stream_policy_values = {
|
|
|
|
by_admins_only: {
|
|
|
|
order: 1,
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
by_full_members: {
|
|
|
|
order: 2,
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins and full members"),
|
|
|
|
},
|
|
|
|
by_members: {
|
|
|
|
order: 3,
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-25 10:23:40 +01:00
|
|
|
exports.invite_to_stream_policy_values = exports.create_stream_policy_values;
|
|
|
|
|
2020-01-26 16:55:09 +01:00
|
|
|
exports.user_group_edit_policy_values = {
|
|
|
|
by_admins_only: {
|
|
|
|
order: 1,
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
by_members: {
|
|
|
|
order: 2,
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 07:51:44 +01:00
|
|
|
exports.private_message_policy_values = {
|
|
|
|
by_anyone: {
|
|
|
|
order: 1,
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins, members, and guests"),
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
order: 2,
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Private messages disabled"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-23 07:01:34 +01:00
|
|
|
exports.get_sorted_options_list = function (option_values_object) {
|
|
|
|
const options_list = Object.keys(option_values_object).map((key) => {
|
|
|
|
return _.extend(option_values_object[key], {key: key});
|
|
|
|
});
|
|
|
|
let comparator = (x, y) => x.order - y.order;
|
|
|
|
if (!options_list[0].order) {
|
|
|
|
comparator = (x, y) => {
|
|
|
|
const key_x = x.key.toUpperCase();
|
|
|
|
const key_y = y.key.toUpperCase();
|
|
|
|
if (key_x < key_y) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (key_x > key_y) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
options_list.sort(comparator);
|
|
|
|
return options_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_organization_settings_options = () => {
|
|
|
|
const options = {};
|
|
|
|
options.create_stream_policy_values = exports.get_sorted_options_list(
|
|
|
|
exports.create_stream_policy_values);
|
2020-01-25 10:23:40 +01:00
|
|
|
options.invite_to_stream_policy_values = exports.get_sorted_options_list(
|
|
|
|
exports.invite_to_stream_policy_values);
|
2020-01-26 16:55:09 +01:00
|
|
|
options.user_group_edit_policy_values = exports.get_sorted_options_list(
|
|
|
|
exports.user_group_edit_policy_values);
|
2020-01-28 07:51:44 +01:00
|
|
|
options.private_message_policy_values = exports.get_sorted_options_list(
|
|
|
|
exports.private_message_policy_values);
|
2020-01-23 07:01:34 +01:00
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
2019-04-20 18:08:29 +02:00
|
|
|
exports.show_email = function () {
|
|
|
|
// TODO: Extend this when we add support for admins_and_members above.
|
2019-07-18 15:21:09 +02:00
|
|
|
if (page_params.realm_email_address_visibility ===
|
|
|
|
exports.email_address_visibility_values.everyone.code) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (page_params.realm_email_address_visibility ===
|
|
|
|
exports.email_address_visibility_values.admins_only.code) {
|
|
|
|
return page_params.is_admin;
|
|
|
|
}
|
2019-04-20 18:08:29 +02:00
|
|
|
};
|
|
|
|
|
2018-04-28 15:35:14 +02:00
|
|
|
exports.get_realm_time_limits_in_minutes = function (property) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let val = (page_params[property] / 60).toFixed(1);
|
2018-04-28 15:35:14 +02:00
|
|
|
if (parseFloat(val, 10) === parseInt(val, 10)) {
|
|
|
|
val = parseInt(val, 10);
|
|
|
|
}
|
|
|
|
return val.toString();
|
|
|
|
};
|
|
|
|
|
2018-04-01 08:56:18 +02:00
|
|
|
function get_property_value(property_name) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let value;
|
2018-06-16 13:27:56 +02:00
|
|
|
|
2018-03-29 12:52:57 +02:00
|
|
|
if (property_name === 'realm_message_content_edit_limit_minutes') {
|
2018-04-28 15:35:14 +02:00
|
|
|
return exports.get_realm_time_limits_in_minutes('realm_message_content_edit_limit_seconds');
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_message_content_delete_limit_minutes') {
|
2018-04-28 15:35:14 +02:00
|
|
|
return exports.get_realm_time_limits_in_minutes('realm_message_content_delete_limit_seconds');
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
if (property_name === 'realm_waiting_period_setting') {
|
|
|
|
if (page_params.realm_waiting_period_threshold === 0) {
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
if (page_params.realm_waiting_period_threshold === 3) {
|
|
|
|
return "three_days";
|
|
|
|
}
|
|
|
|
return "custom_days";
|
|
|
|
}
|
|
|
|
|
2018-06-16 13:27:56 +02:00
|
|
|
if (property_name === 'realm_add_emoji_by_admins_only') {
|
2018-03-29 12:52:57 +02:00
|
|
|
if (page_params.realm_add_emoji_by_admins_only) {
|
|
|
|
return "by_admins_only";
|
|
|
|
}
|
|
|
|
return "by_anyone";
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_msg_edit_limit_setting') {
|
2018-04-02 11:18:40 +02:00
|
|
|
if (!page_params.realm_allow_message_editing) {
|
|
|
|
return "never";
|
|
|
|
}
|
2017-11-26 09:12:10 +01:00
|
|
|
value = _.findKey(exports.msg_edit_limit_dropdown_values, function (elem) {
|
2018-04-02 11:18:40 +02:00
|
|
|
return elem.seconds === page_params.realm_message_content_edit_limit_seconds;
|
|
|
|
});
|
|
|
|
if (value === undefined) {
|
|
|
|
return "custom_limit";
|
|
|
|
}
|
|
|
|
return value;
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_msg_delete_limit_setting') {
|
2017-11-26 09:12:10 +01:00
|
|
|
if (!page_params.realm_allow_message_deleting) {
|
|
|
|
return "never";
|
|
|
|
}
|
|
|
|
value = _.findKey(exports.msg_delete_limit_dropdown_values, function (elem) {
|
|
|
|
return elem.seconds === page_params.realm_message_content_delete_limit_seconds;
|
|
|
|
});
|
|
|
|
if (value === undefined) {
|
|
|
|
return "custom_limit";
|
|
|
|
}
|
|
|
|
return value;
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_org_join_restrictions') {
|
2018-07-27 23:26:29 +02:00
|
|
|
if (page_params.realm_emails_restricted_to_domains) {
|
2018-04-05 00:54:31 +02:00
|
|
|
return "only_selected_domain";
|
|
|
|
}
|
|
|
|
if (page_params.realm_disallow_disposable_email_addresses) {
|
|
|
|
return "no_disposable_email";
|
|
|
|
}
|
|
|
|
return "no_restriction";
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_user_invite_restriction') {
|
2018-04-30 18:26:59 +02:00
|
|
|
if (!page_params.realm_invite_required) {
|
|
|
|
return "no_invite_required";
|
|
|
|
}
|
|
|
|
if (page_params.realm_invite_by_admins_only) {
|
|
|
|
return "by_admins_only";
|
|
|
|
}
|
|
|
|
return "by_anyone";
|
2018-03-29 12:52:57 +02:00
|
|
|
}
|
2018-06-16 13:27:56 +02:00
|
|
|
|
2019-07-30 09:52:06 +02:00
|
|
|
if (property_name === 'realm_default_twenty_four_hour_time') {
|
|
|
|
return JSON.stringify(page_params[property_name]);
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:32:38 +01:00
|
|
|
if (property_name === 'realm_notifications_stream') {
|
|
|
|
return page_params.realm_notifications_stream_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_signup_notifications_stream') {
|
|
|
|
return page_params.realm_signup_notifications_stream_id;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:45:47 +02:00
|
|
|
return page_params[property_name];
|
2018-03-29 12:52:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.extract_property_name = function (elem) {
|
|
|
|
return elem.attr('id').split('-').join('_').replace("id_", "");
|
|
|
|
};
|
|
|
|
|
2019-05-05 22:37:09 +02:00
|
|
|
function get_subsection_property_elements(element) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const subsection = $(element).closest('.org-subsection-parent');
|
2019-05-05 22:37:09 +02:00
|
|
|
return subsection.find('.prop-element');
|
|
|
|
}
|
|
|
|
|
2020-02-03 12:40:36 +01:00
|
|
|
const simple_dropdown_properties = ['realm_create_stream_policy',
|
|
|
|
'realm_invite_to_stream_policy',
|
|
|
|
'realm_user_group_edit_policy',
|
|
|
|
'realm_private_message_policy',
|
|
|
|
'realm_add_emoji_by_admins_only',
|
|
|
|
'realm_user_invite_restriction'];
|
|
|
|
|
|
|
|
function set_property_dropdown_value(property_name) {
|
|
|
|
$('#id_' + property_name).val(get_property_value(property_name));
|
|
|
|
}
|
|
|
|
|
2020-02-03 13:03:53 +01:00
|
|
|
function change_element_block_display_property(elem_id, show_element) {
|
|
|
|
const elem = $("#" + elem_id);
|
|
|
|
if (show_element) {
|
|
|
|
elem.parent().show();
|
|
|
|
} else {
|
|
|
|
elem.parent().hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
function set_realm_waiting_period_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_waiting_period_setting");
|
2019-05-07 19:06:05 +02:00
|
|
|
$("#id_realm_waiting_period_setting").val(value);
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_waiting_period_threshold',
|
|
|
|
value === "custom_days");
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-01-05 15:34:10 +01:00
|
|
|
|
2018-04-23 14:51:30 +02:00
|
|
|
function set_video_chat_provider_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const chat_provider_id = page_params.realm_video_chat_provider;
|
|
|
|
const available_providers = page_params.realm_available_video_chat_providers;
|
2019-05-09 09:54:38 +02:00
|
|
|
|
|
|
|
$("#id_realm_video_chat_provider").val(chat_provider_id);
|
|
|
|
if (chat_provider_id === available_providers.google_hangouts.id) {
|
2018-04-23 14:51:30 +02:00
|
|
|
$("#google_hangouts_domain").show();
|
2018-12-28 20:45:54 +01:00
|
|
|
$(".zoom_credentials").hide();
|
2018-04-23 14:51:30 +02:00
|
|
|
$("#id_realm_google_hangouts_domain").val(page_params.realm_google_hangouts_domain);
|
2019-05-09 09:54:38 +02:00
|
|
|
} else if (chat_provider_id === available_providers.zoom.id) {
|
2018-12-28 20:45:54 +01:00
|
|
|
$("#google_hangouts_domain").hide();
|
|
|
|
$(".zoom_credentials").show();
|
|
|
|
$("#id_realm_zoom_user_id").val(page_params.realm_zoom_user_id);
|
|
|
|
$("#id_realm_zoom_api_key").val(page_params.realm_zoom_api_key);
|
|
|
|
$("#id_realm_zoom_api_secret").val(page_params.realm_zoom_api_secret);
|
2018-04-23 14:51:30 +02:00
|
|
|
} else {
|
|
|
|
$("#google_hangouts_domain").hide();
|
2018-12-28 20:45:54 +01:00
|
|
|
$(".zoom_credentials").hide();
|
2018-04-23 14:51:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const time_limit_dropdown_values = {
|
2018-05-30 19:01:46 +02:00
|
|
|
any_time: {
|
|
|
|
text: i18n.t("Any time"),
|
|
|
|
seconds: 0,
|
|
|
|
},
|
|
|
|
never: {
|
|
|
|
text: i18n.t("Never"),
|
|
|
|
},
|
|
|
|
upto_two_min: {
|
|
|
|
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("2 minutes")}),
|
2018-06-04 21:13:07 +02:00
|
|
|
seconds: 2 * 60,
|
2018-05-30 19:01:46 +02:00
|
|
|
},
|
|
|
|
upto_ten_min: {
|
|
|
|
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("10 minutes")}),
|
2018-06-04 21:13:07 +02:00
|
|
|
seconds: 10 * 60,
|
2018-05-30 19:01:46 +02:00
|
|
|
},
|
|
|
|
upto_one_hour: {
|
|
|
|
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 hour")}),
|
2018-06-04 21:13:07 +02:00
|
|
|
seconds: 60 * 60,
|
2018-05-30 19:01:46 +02:00
|
|
|
},
|
|
|
|
upto_one_day: {
|
|
|
|
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 day")}),
|
2018-06-04 21:13:07 +02:00
|
|
|
seconds: 24 * 60 * 60,
|
2018-05-30 19:01:46 +02:00
|
|
|
},
|
|
|
|
upto_one_week: {
|
|
|
|
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 week")}),
|
2018-06-04 21:13:07 +02:00
|
|
|
seconds: 7 * 24 * 60 * 60,
|
2018-05-30 19:01:46 +02:00
|
|
|
},
|
|
|
|
custom_limit: {
|
|
|
|
text: i18n.t("Up to N minutes after posting"),
|
|
|
|
},
|
2018-04-02 11:18:40 +02:00
|
|
|
};
|
2018-05-30 19:01:46 +02:00
|
|
|
exports.msg_edit_limit_dropdown_values = time_limit_dropdown_values;
|
|
|
|
exports.msg_delete_limit_dropdown_values = time_limit_dropdown_values;
|
2018-04-02 11:18:40 +02:00
|
|
|
|
|
|
|
function set_msg_edit_limit_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_msg_edit_limit_setting");
|
2018-04-02 11:18:40 +02:00
|
|
|
$("#id_realm_msg_edit_limit_setting").val(value);
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_message_content_edit_limit_minutes',
|
|
|
|
value === "custom_limit");
|
2018-08-18 12:31:21 +02:00
|
|
|
settings_ui.disable_sub_setting_onchange(value !== "never",
|
|
|
|
"id_realm_allow_community_topic_editing", true);
|
2018-04-02 11:18:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-26 09:12:10 +01:00
|
|
|
function set_msg_delete_limit_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_msg_delete_limit_setting");
|
2017-11-26 09:12:10 +01:00
|
|
|
$("#id_realm_msg_delete_limit_setting").val(value);
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_message_content_delete_limit_minutes',
|
|
|
|
value === "custom_limit");
|
2017-11-26 09:12:10 +01:00
|
|
|
}
|
|
|
|
|
2018-04-05 00:54:31 +02:00
|
|
|
function set_org_join_restrictions_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_org_join_restrictions");
|
2018-04-05 00:54:31 +02:00
|
|
|
$("#id_realm_org_join_restrictions").val(value);
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('allowed_domains_label',
|
|
|
|
value === 'only_selected_domain');
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:04:08 +01:00
|
|
|
function set_message_content_in_email_notifications_visiblity() {
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property(
|
|
|
|
'message_content_in_email_notifications_label',
|
|
|
|
page_params.realm_message_content_allowed_in_email_notifications);
|
2019-01-14 14:04:08 +01:00
|
|
|
}
|
|
|
|
|
2019-05-08 08:11:30 +02:00
|
|
|
function set_digest_emails_weekday_visibility() {
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_digest_weekday',
|
|
|
|
page_params.realm_digest_emails_enabled);
|
2019-05-08 08:11:30 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
exports.populate_realm_domains = function (realm_domains) {
|
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const domains_list = _.map(realm_domains, function (realm_domain) {
|
2018-06-06 18:19:09 +02:00
|
|
|
return realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain;
|
2017-04-08 18:13:39 +02:00
|
|
|
});
|
2019-11-02 00:06:25 +01:00
|
|
|
let domains = domains_list.join(', ');
|
2017-04-08 18:13:39 +02:00
|
|
|
if (domains.length === 0) {
|
|
|
|
domains = i18n.t("None");
|
|
|
|
}
|
2018-04-05 00:54:31 +02:00
|
|
|
$("#allowed_domains_label").text(i18n.t("Allowed domains: __domains__", {domains: domains}));
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_domains_table_body = $("#realm_domains_table tbody").expectOne();
|
2017-04-08 18:13:39 +02:00
|
|
|
realm_domains_table_body.find("tr").remove();
|
|
|
|
_.each(realm_domains, function (realm_domain) {
|
2019-07-09 21:24:00 +02:00
|
|
|
realm_domains_table_body.append(
|
|
|
|
render_settings_admin_realm_domains_list({
|
|
|
|
realm_domain: realm_domain,
|
|
|
|
})
|
|
|
|
);
|
2017-04-08 18:13:39 +02:00
|
|
|
});
|
|
|
|
};
|
2019-04-07 18:56:32 +02:00
|
|
|
function sort_object_by_key(obj) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const keys = _.keys(obj).sort();
|
|
|
|
const new_obj = {};
|
2019-04-07 18:56:32 +02:00
|
|
|
_.each(keys, function (key) {
|
|
|
|
new_obj[key] = obj[key];
|
|
|
|
});
|
|
|
|
return new_obj;
|
|
|
|
}
|
2017-04-08 18:13:39 +02:00
|
|
|
exports.populate_auth_methods = function (auth_methods) {
|
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const auth_methods_table = $("#id_realm_authentication_methods").expectOne();
|
2019-04-07 18:56:32 +02:00
|
|
|
auth_methods = sort_object_by_key(auth_methods);
|
2019-11-02 00:06:25 +01:00
|
|
|
let rendered_auth_method_rows = "";
|
2019-04-07 18:56:32 +02:00
|
|
|
_.each(auth_methods, function (value, auth_method) {
|
2019-07-09 21:24:00 +02:00
|
|
|
rendered_auth_method_rows += render_settings_admin_auth_methods_list({
|
2019-04-06 08:43:34 +02:00
|
|
|
method: auth_method,
|
|
|
|
enabled: value,
|
|
|
|
is_admin: page_params.is_admin,
|
|
|
|
});
|
2017-04-08 18:13:39 +02:00
|
|
|
});
|
2019-04-06 08:43:34 +02:00
|
|
|
auth_methods_table.html(rendered_auth_method_rows);
|
2017-04-08 18:13:39 +02:00
|
|
|
};
|
|
|
|
|
2019-04-07 18:32:42 +02:00
|
|
|
function insert_tip_box() {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const tip_box = render_settings_organization_settings_tip({is_admin: page_params.is_admin});
|
2019-04-07 18:32:42 +02:00
|
|
|
$(".organization-box").find(".settings-section:not(.can-edit)")
|
|
|
|
.not("#emoji-settings")
|
|
|
|
.not("#user-groups-admin")
|
|
|
|
.prepend(tip_box);
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:55:17 +01:00
|
|
|
exports.render_notifications_stream_ui = function (stream_id, notification_type) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const name = stream_data.maybe_get_stream_name(stream_id);
|
2017-06-16 14:39:21 +02:00
|
|
|
|
2020-01-11 21:55:17 +01:00
|
|
|
$(`#id_realm_${notification_type}_stream`).data("stream-id", stream_id);
|
|
|
|
|
|
|
|
const elem = $(`#realm_${notification_type}_stream_name`);
|
|
|
|
|
2017-06-16 14:39:21 +02:00
|
|
|
if (!name) {
|
|
|
|
elem.text(i18n.t("Disabled"));
|
|
|
|
elem.addClass("text-warning");
|
2018-04-03 22:25:18 +02:00
|
|
|
elem.closest('.input-group').find('.notification-disable').hide();
|
2017-06-16 14:39:21 +02:00
|
|
|
return;
|
2017-06-10 07:03:53 +02:00
|
|
|
}
|
2017-06-16 14:39:21 +02:00
|
|
|
|
|
|
|
// Happy path
|
|
|
|
elem.text('#' + name);
|
|
|
|
elem.removeClass('text-warning');
|
2018-04-03 22:25:18 +02:00
|
|
|
elem.closest('.input-group').find('.notification-disable').show();
|
2017-06-10 07:03:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.populate_notifications_stream_dropdown = function (stream_list) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const dropdown_list_body = $("#id_realm_notifications_stream .dropdown-list-body").expectOne();
|
|
|
|
const search_input = $("#id_realm_notifications_stream .dropdown-search > input[type=text]");
|
2017-06-10 07:03:53 +02:00
|
|
|
|
2018-06-20 18:32:39 +02:00
|
|
|
list_render.create(dropdown_list_body, stream_list, {
|
2017-10-20 16:55:04 +02:00
|
|
|
name: "admin-realm-notifications-stream-dropdown-list",
|
2017-06-10 07:03:53 +02:00
|
|
|
modifier: function (item) {
|
2019-07-09 21:24:00 +02:00
|
|
|
return render_settings_admin_realm_dropdown_stream_list({ stream: item });
|
2017-06-10 07:03:53 +02:00
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: search_input,
|
2019-12-30 17:44:24 +01:00
|
|
|
predicate: function (item, value) {
|
2017-08-25 03:30:54 +02:00
|
|
|
return item.name.toLowerCase().indexOf(value) >= 0;
|
2017-06-10 07:03:53 +02:00
|
|
|
},
|
2017-09-27 19:01:04 +02:00
|
|
|
onupdate: function () {
|
2019-01-09 14:30:35 +01:00
|
|
|
ui.reset_scrollbar(dropdown_list_body);
|
2017-09-27 19:01:04 +02:00
|
|
|
},
|
2017-06-10 07:03:53 +02:00
|
|
|
},
|
|
|
|
}).init();
|
|
|
|
|
|
|
|
$("#id_realm_notifications_stream .dropdown-search").click(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#id_realm_notifications_stream .dropdown-toggle").click(function () {
|
|
|
|
search_input.val("").trigger("input");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-20 16:55:04 +02:00
|
|
|
exports.populate_signup_notifications_stream_dropdown = function (stream_list) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const dropdown_list_body = $("#id_realm_signup_notifications_stream .dropdown-list-body").expectOne();
|
|
|
|
const search_input = $("#id_realm_signup_notifications_stream .dropdown-search > input[type=text]");
|
2017-10-20 16:55:04 +02:00
|
|
|
|
2018-06-20 18:32:39 +02:00
|
|
|
list_render.create(dropdown_list_body, stream_list, {
|
2017-10-20 16:55:04 +02:00
|
|
|
name: "admin-realm-signup-notifications-stream-dropdown-list",
|
|
|
|
modifier: function (item) {
|
2019-07-09 21:24:00 +02:00
|
|
|
return render_settings_admin_realm_dropdown_stream_list({ stream: item });
|
2017-10-20 16:55:04 +02:00
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: search_input,
|
2019-12-30 17:44:24 +01:00
|
|
|
predicate: function (item, value) {
|
2017-10-20 16:55:04 +02:00
|
|
|
return item.name.toLowerCase().indexOf(value) >= 0;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).init();
|
|
|
|
|
|
|
|
$("#id_realm_signup_notifications_stream .dropdown-search").click(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#id_realm_signup_notifications_stream .dropdown-toggle").click(function () {
|
|
|
|
search_input.val("").trigger("input");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-04-01 08:56:18 +02:00
|
|
|
function update_dependent_subsettings(property_name) {
|
2020-02-03 12:40:36 +01:00
|
|
|
if (simple_dropdown_properties.indexOf(property_name) !== -1) {
|
|
|
|
set_property_dropdown_value(property_name);
|
|
|
|
} else if (property_name === 'realm_waiting_period_threshold') {
|
2019-05-07 19:06:05 +02:00
|
|
|
set_realm_waiting_period_dropdown();
|
2018-05-06 21:43:17 +02:00
|
|
|
} else if (property_name === 'realm_video_chat_provider' ||
|
2018-12-28 20:45:54 +01:00
|
|
|
property_name === 'realm_google_hangouts_domain' ||
|
|
|
|
property_name.startsWith('realm_zoom')) {
|
2018-04-23 14:51:30 +02:00
|
|
|
set_video_chat_provider_dropdown();
|
2018-05-06 21:43:17 +02:00
|
|
|
} else if (property_name === 'realm_msg_edit_limit_setting' ||
|
|
|
|
property_name === 'realm_message_content_edit_limit_minutes') {
|
2018-04-02 11:18:40 +02:00
|
|
|
set_msg_edit_limit_dropdown();
|
2017-11-26 09:12:10 +01:00
|
|
|
} else if (property_name === 'realm_msg_delete_limit_setting' ||
|
|
|
|
property_name === 'realm_message_content_delete_limit_minutes') {
|
|
|
|
set_msg_delete_limit_dropdown();
|
2018-04-05 00:54:31 +02:00
|
|
|
} else if (property_name === 'realm_org_join_restrictions') {
|
|
|
|
set_org_join_restrictions_dropdown();
|
2019-01-14 14:04:08 +01:00
|
|
|
} else if (property_name === 'realm_message_content_allowed_in_email_notifications') {
|
|
|
|
set_message_content_in_email_notifications_visiblity();
|
2019-04-06 06:34:49 +02:00
|
|
|
} else if (property_name === 'realm_digest_emails_enabled') {
|
2019-05-10 08:45:46 +02:00
|
|
|
settings_notifications.set_enable_digest_emails_visibility();
|
2019-05-08 08:11:30 +02:00
|
|
|
set_digest_emails_weekday_visibility();
|
2018-03-29 12:52:57 +02:00
|
|
|
}
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-03-29 12:52:57 +02:00
|
|
|
|
2018-03-29 12:58:35 +02:00
|
|
|
function discard_property_element_changes(elem) {
|
|
|
|
elem = $(elem);
|
2019-11-02 00:06:25 +01:00
|
|
|
const property_name = exports.extract_property_name(elem);
|
|
|
|
const property_value = get_property_value(property_name);
|
2018-03-29 12:58:35 +02:00
|
|
|
|
2020-01-13 10:45:41 +01:00
|
|
|
if (property_name === 'realm_authentication_methods') {
|
|
|
|
exports.populate_auth_methods(property_value);
|
2020-01-13 12:32:38 +01:00
|
|
|
} else if (property_name === 'realm_notifications_stream') {
|
|
|
|
exports.render_notifications_stream_ui(property_value, "notifications");
|
|
|
|
} else if (property_name === 'realm_signup_notifications_stream') {
|
|
|
|
exports.render_notifications_stream_ui(property_value, "signup_notifications");
|
2020-01-13 10:45:41 +01:00
|
|
|
} else if (typeof property_value === 'boolean') {
|
2018-03-29 12:58:35 +02:00
|
|
|
elem.prop('checked', property_value);
|
|
|
|
} else if (typeof property_value === 'string' || typeof property_value === 'number') {
|
|
|
|
elem.val(property_value);
|
|
|
|
} else {
|
|
|
|
blueslip.error('Element refers to unknown property ' + property_name);
|
|
|
|
}
|
|
|
|
|
2018-04-01 08:56:18 +02:00
|
|
|
update_dependent_subsettings(property_name);
|
2018-03-29 12:58:35 +02:00
|
|
|
}
|
|
|
|
|
2018-03-29 13:15:50 +02:00
|
|
|
exports.sync_realm_settings = function (property) {
|
|
|
|
if (!overlays.settings_open()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'message_content_edit_limit_seconds') {
|
|
|
|
property = 'message_content_edit_limit_minutes';
|
2018-04-02 11:18:40 +02:00
|
|
|
} else if (property === 'allow_message_editing') {
|
|
|
|
property = 'msg_edit_limit_setting';
|
2018-07-27 23:26:29 +02:00
|
|
|
} else if (property === 'emails_restricted_to_domains' || property === 'disallow_disposable_email_addresses') {
|
2018-04-05 00:54:31 +02:00
|
|
|
property = 'org_join_restrictions';
|
2017-11-26 09:12:10 +01:00
|
|
|
} else if (property === 'message_content_delete_limit_seconds') {
|
|
|
|
property = 'message_content_delete_limit_minutes';
|
|
|
|
} else if (property === 'allow_message_deleting') {
|
|
|
|
property = 'msg_delete_limit_setting';
|
2018-04-30 18:26:59 +02:00
|
|
|
} else if (property === 'invite_required' || property === 'invite_by_admins_only') {
|
|
|
|
property = 'user_invite_restriction';
|
2018-03-29 13:15:50 +02:00
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const element = $('#id_realm_' + property);
|
2018-03-29 13:15:50 +02:00
|
|
|
if (element.length) {
|
|
|
|
discard_property_element_changes(element);
|
|
|
|
}
|
|
|
|
};
|
2019-03-07 15:18:10 +01:00
|
|
|
|
2018-03-29 13:15:50 +02:00
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
exports.change_save_button_state = function ($element, state) {
|
2019-03-07 15:18:10 +01:00
|
|
|
function show_hide_element($element, show, fadeout_delay) {
|
|
|
|
if (show) {
|
|
|
|
$element.removeClass('hide').addClass('.show').fadeIn(300);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setTimeout(function () {
|
|
|
|
$element.fadeOut(300);
|
|
|
|
}, fadeout_delay);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const $saveBtn = $element.find('.save-button');
|
|
|
|
const $textEl = $saveBtn.find('.icon-button-text');
|
2019-03-07 15:18:10 +01:00
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
if (state !== "saving") {
|
|
|
|
$saveBtn.removeClass('saving');
|
|
|
|
}
|
2019-03-07 15:18:10 +01:00
|
|
|
|
|
|
|
if (state === "discarded") {
|
2019-08-18 14:48:40 +02:00
|
|
|
show_hide_element($element, false, 0);
|
2019-03-07 15:18:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let button_text;
|
|
|
|
let data_status;
|
|
|
|
let is_show;
|
2018-03-29 02:02:01 +02:00
|
|
|
if (state === "unsaved") {
|
2019-03-09 08:34:53 +01:00
|
|
|
button_text = i18n.t("Save changes");
|
|
|
|
data_status = "unsaved";
|
|
|
|
is_show = true;
|
2019-03-07 15:18:10 +01:00
|
|
|
|
|
|
|
$element.find('.discard-button').show();
|
2018-03-29 02:02:01 +02:00
|
|
|
} else if (state === "saved") {
|
2019-03-09 08:34:53 +01:00
|
|
|
button_text = i18n.t("Save changes");
|
|
|
|
data_status = "";
|
|
|
|
is_show = false;
|
2018-03-29 02:02:01 +02:00
|
|
|
} else if (state === "saving") {
|
2019-03-09 08:34:53 +01:00
|
|
|
button_text = i18n.t("Saving");
|
|
|
|
data_status = "saving";
|
|
|
|
is_show = true;
|
2019-03-07 15:18:10 +01:00
|
|
|
|
|
|
|
$element.find('.discard-button').hide();
|
2018-03-29 02:02:01 +02:00
|
|
|
$saveBtn.addClass('saving');
|
|
|
|
} else if (state === "failed") {
|
2019-03-09 08:34:53 +01:00
|
|
|
button_text = i18n.t("Save changes");
|
|
|
|
data_status = "failed";
|
|
|
|
is_show = true;
|
2018-03-29 02:02:01 +02:00
|
|
|
} else if (state === 'succeeded') {
|
2019-03-09 08:34:53 +01:00
|
|
|
button_text = i18n.t("Saved");
|
|
|
|
data_status = "saved";
|
|
|
|
is_show = false;
|
|
|
|
}
|
|
|
|
|
2019-03-07 15:18:10 +01:00
|
|
|
$textEl.text(button_text);
|
|
|
|
$saveBtn.attr("data-status", data_status);
|
|
|
|
show_hide_element($element, is_show, 800);
|
2018-03-29 02:02:01 +02:00
|
|
|
};
|
|
|
|
|
2018-05-30 18:03:34 +02:00
|
|
|
exports.set_up = function () {
|
2018-12-08 18:16:37 +01:00
|
|
|
exports.build_page();
|
|
|
|
exports.maybe_disable_widgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.build_page = function () {
|
2017-04-08 18:13:39 +02:00
|
|
|
meta.loaded = true;
|
|
|
|
|
|
|
|
loading.make_indicator($('#admin_page_auth_methods_loading_indicator'));
|
|
|
|
|
2017-06-10 07:03:53 +02:00
|
|
|
// Populate notifications stream modal
|
|
|
|
if (page_params.is_admin) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const streams = stream_data.get_streams_for_settings_page();
|
2017-10-20 16:55:04 +02:00
|
|
|
exports.populate_notifications_stream_dropdown(streams);
|
|
|
|
exports.populate_signup_notifications_stream_dropdown(streams);
|
2017-06-10 07:03:53 +02:00
|
|
|
}
|
2020-01-11 21:55:17 +01:00
|
|
|
exports.render_notifications_stream_ui(page_params.realm_notifications_stream_id, 'notifications');
|
|
|
|
exports.render_notifications_stream_ui(page_params.realm_signup_notifications_stream_id, 'signup_notifications');
|
2017-06-10 07:03:53 +02:00
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
// Populate realm domains
|
2017-04-20 07:30:51 +02:00
|
|
|
exports.populate_realm_domains(page_params.realm_domains);
|
2017-04-08 18:13:39 +02:00
|
|
|
|
|
|
|
// Populate authentication methods table
|
|
|
|
exports.populate_auth_methods(page_params.realm_authentication_methods);
|
2019-04-07 18:32:42 +02:00
|
|
|
insert_tip_box();
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2020-02-03 12:40:36 +01:00
|
|
|
simple_dropdown_properties.forEach(set_property_dropdown_value);
|
2017-05-25 00:50:07 +02:00
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
set_realm_waiting_period_dropdown();
|
2018-04-23 14:51:30 +02:00
|
|
|
set_video_chat_provider_dropdown();
|
2018-04-02 11:18:40 +02:00
|
|
|
set_msg_edit_limit_dropdown();
|
2017-11-26 09:12:10 +01:00
|
|
|
set_msg_delete_limit_dropdown();
|
2018-04-05 00:54:31 +02:00
|
|
|
set_org_join_restrictions_dropdown();
|
2019-01-14 14:04:08 +01:00
|
|
|
set_message_content_in_email_notifications_visiblity();
|
2019-05-08 08:11:30 +02:00
|
|
|
set_digest_emails_weekday_visibility();
|
2018-03-05 19:19:19 +01:00
|
|
|
|
2019-04-06 08:43:34 +02:00
|
|
|
function get_auth_method_table_data() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_auth_methods = {};
|
|
|
|
const auth_method_rows = $("#id_realm_authentication_methods").find('tr.method_row');
|
2019-04-06 08:43:34 +02:00
|
|
|
_.each(auth_method_rows, function (method_row) {
|
|
|
|
new_auth_methods[$(method_row).data('method')] = $(method_row).find('input').prop('checked');
|
|
|
|
});
|
|
|
|
return new_auth_methods;
|
|
|
|
}
|
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
function check_property_changed(elem) {
|
|
|
|
elem = $(elem);
|
2019-11-02 00:06:25 +01:00
|
|
|
const property_name = exports.extract_property_name(elem);
|
|
|
|
let changed_val;
|
|
|
|
let current_val = get_property_value(property_name);
|
2020-01-13 10:45:41 +01:00
|
|
|
|
|
|
|
if (property_name === 'realm_authentication_methods') {
|
|
|
|
current_val = sort_object_by_key(current_val);
|
|
|
|
current_val = JSON.stringify(current_val);
|
|
|
|
changed_val = get_auth_method_table_data();
|
|
|
|
changed_val = JSON.stringify(changed_val);
|
2020-01-13 12:32:38 +01:00
|
|
|
} else if (property_name === 'realm_notifications_stream') {
|
|
|
|
changed_val = parseInt($("#id_realm_notifications_stream").data('stream-id'), 10);
|
|
|
|
} else if (property_name === 'realm_signup_notifications_stream') {
|
|
|
|
changed_val = parseInt($("#id_realm_signup_notifications_stream").data('stream-id'), 10);
|
2020-01-13 10:45:41 +01:00
|
|
|
} else if (typeof current_val === 'boolean') {
|
2018-03-14 23:50:17 +01:00
|
|
|
changed_val = elem.prop('checked');
|
|
|
|
} else if (typeof current_val === 'string') {
|
|
|
|
changed_val = elem.val().trim();
|
|
|
|
} else if (typeof current_val === 'number') {
|
|
|
|
current_val = current_val.toString();
|
|
|
|
changed_val = elem.val().trim();
|
|
|
|
} else {
|
2018-03-22 13:50:27 +01:00
|
|
|
blueslip.error('Element refers to unknown property ' + property_name);
|
2018-03-14 23:50:17 +01:00
|
|
|
}
|
|
|
|
return current_val !== changed_val;
|
|
|
|
}
|
|
|
|
|
2020-01-13 10:28:45 +01:00
|
|
|
function save_discard_widget_status_handler(subsection) {
|
|
|
|
subsection.find('.subsection-failed-status p').hide();
|
|
|
|
subsection.find('.save-button').show();
|
|
|
|
const properties_elements = get_subsection_property_elements(subsection);
|
|
|
|
let show_change_process_button = false;
|
|
|
|
_.each(properties_elements, function (elem) {
|
|
|
|
if (check_property_changed(elem)) {
|
|
|
|
show_change_process_button = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const save_btn_controls = subsection.find('.subsection-header .save-button-controls');
|
|
|
|
const button_state = show_change_process_button ? "unsaved" : "discarded";
|
|
|
|
exports.change_save_button_state(save_btn_controls, button_state);
|
|
|
|
}
|
|
|
|
|
2018-03-26 12:06:42 +02:00
|
|
|
$('.admin-realm-form').on('change input', 'input, select, textarea', function (e) {
|
2018-03-14 23:50:17 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-08-22 01:48:38 +02:00
|
|
|
// This event handler detects whether after these input
|
|
|
|
// changes, any fields have different values from the current
|
|
|
|
// official values stored in the database and page_params. If
|
|
|
|
// they do, we transition to the "unsaved" state showing the
|
|
|
|
// save/discard widget; otherwise, we hide that widget (the
|
|
|
|
// "discarded" state).
|
2019-08-05 21:11:30 +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;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const subsection = $(e.target).closest('.org-subsection-parent');
|
2020-01-13 10:28:45 +01:00
|
|
|
save_discard_widget_status_handler(subsection);
|
2018-03-14 23:50:17 +01:00
|
|
|
});
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
$('.organization').on('click', '.subsection-header .subsection-changes-discard .button', function (e) {
|
2018-03-22 13:27:52 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-03-25 15:11:25 +02:00
|
|
|
_.each(get_subsection_property_elements(e.target), discard_property_element_changes);
|
2019-11-02 00:06:25 +01:00
|
|
|
const save_btn_controls = $(e.target).closest('.save-button-controls');
|
2018-03-29 02:02:01 +02:00
|
|
|
exports.change_save_button_state(save_btn_controls, "discarded");
|
2018-03-14 23:52:36 +01:00
|
|
|
});
|
|
|
|
|
2019-03-25 11:52:55 +01:00
|
|
|
exports.save_organization_settings = function (data, save_button) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const subsection_parent = save_button.closest('.org-subsection-parent');
|
|
|
|
const save_btn_container = subsection_parent.find('.save-button-controls');
|
|
|
|
const failed_alert_elem = subsection_parent.find('.subsection-failed-status p');
|
2018-03-29 02:02:01 +02:00
|
|
|
exports.change_save_button_state(save_btn_container, "saving");
|
2017-04-08 18:13:39 +02:00
|
|
|
channel.patch({
|
2018-03-14 23:45:42 +01:00
|
|
|
url: "/json/realm",
|
2017-04-08 18:13:39 +02:00
|
|
|
data: data,
|
2019-03-25 11:52:55 +01:00
|
|
|
success: function () {
|
2018-03-14 23:45:42 +01:00
|
|
|
failed_alert_elem.hide();
|
2019-03-07 15:18:10 +01:00
|
|
|
exports.change_save_button_state(save_btn_container, "succeeded");
|
2017-05-25 00:50:07 +02:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2018-03-29 02:02:01 +02:00
|
|
|
exports.change_save_button_state(save_btn_container, "failed");
|
2018-04-30 15:27:35 +02:00
|
|
|
save_button.hide();
|
|
|
|
ui_report.error(i18n.t("Save failed"), xhr, failed_alert_elem);
|
2017-05-25 00:50:07 +02:00
|
|
|
},
|
|
|
|
});
|
2018-01-11 17:47:37 +01:00
|
|
|
};
|
|
|
|
|
2018-08-04 08:18:21 +02:00
|
|
|
exports.parse_time_limit = function parse_time_limit(elem) {
|
2018-04-28 15:35:14 +02:00
|
|
|
return Math.floor(parseFloat(elem.val(), 10).toFixed(1) * 60);
|
2018-08-04 08:18:21 +02:00
|
|
|
};
|
2018-04-28 15:35:14 +02:00
|
|
|
|
2018-03-21 00:50:00 +01:00
|
|
|
function get_complete_data_for_subsection(subsection) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let data = {};
|
2018-03-14 23:45:42 +01:00
|
|
|
if (subsection === 'msg_editing') {
|
2019-11-02 00:06:25 +01:00
|
|
|
const edit_limit_setting_value = $("#id_realm_msg_edit_limit_setting").val();
|
2018-04-02 11:18:40 +02:00
|
|
|
if (edit_limit_setting_value === 'never') {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.allow_message_editing = false;
|
2018-04-02 11:18:40 +02:00
|
|
|
} else if (edit_limit_setting_value === 'custom_limit') {
|
2018-08-04 08:18:21 +02:00
|
|
|
data.message_content_edit_limit_seconds = exports.parse_time_limit($('#id_realm_message_content_edit_limit_minutes'));
|
2018-04-28 15:35:14 +02:00
|
|
|
// Disable editing if the parsed time limit is 0 seconds
|
2019-03-25 11:52:55 +01:00
|
|
|
data.allow_message_editing = !!data.message_content_edit_limit_seconds;
|
2018-04-02 11:18:40 +02:00
|
|
|
} else {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.allow_message_editing = true;
|
|
|
|
data.message_content_edit_limit_seconds =
|
2018-04-02 11:18:40 +02:00
|
|
|
exports.msg_edit_limit_dropdown_values[edit_limit_setting_value].seconds;
|
2018-03-14 23:45:42 +01:00
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val();
|
2017-11-26 09:12:10 +01:00
|
|
|
if (delete_limit_setting_value === 'never') {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.allow_message_deleting = false;
|
2017-11-26 09:12:10 +01:00
|
|
|
} else if (delete_limit_setting_value === 'custom_limit') {
|
2018-08-04 08:18:21 +02:00
|
|
|
data.message_content_delete_limit_seconds = exports.parse_time_limit($('#id_realm_message_content_delete_limit_minutes'));
|
2018-04-28 15:35:14 +02:00
|
|
|
// Disable deleting if the parsed time limit is 0 seconds
|
2019-03-25 11:52:55 +01:00
|
|
|
data.allow_message_deleting = !!data.message_content_delete_limit_seconds;
|
2017-11-26 09:12:10 +01:00
|
|
|
} else {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.allow_message_deleting = true;
|
|
|
|
data.message_content_delete_limit_seconds =
|
2017-11-26 09:12:10 +01:00
|
|
|
exports.msg_delete_limit_dropdown_values[delete_limit_setting_value].seconds;
|
|
|
|
}
|
2020-01-13 12:32:38 +01:00
|
|
|
} else if (subsection === 'notifications') {
|
|
|
|
data.notifications_stream_id = JSON.stringify(
|
|
|
|
parseInt($('#id_realm_notifications_stream').data('stream-id'), 10));
|
|
|
|
data.signup_notifications_stream_id = JSON.stringify(
|
|
|
|
parseInt($('#id_realm_signup_notifications_stream').data('stream-id'), 10));
|
2019-04-27 07:48:03 +02:00
|
|
|
} else if (subsection === 'other_settings') {
|
2019-11-02 00:06:25 +01:00
|
|
|
let new_message_retention_days = $("#id_realm_message_retention_days").val();
|
2018-03-22 14:07:52 +01:00
|
|
|
|
2018-05-06 21:43:17 +02:00
|
|
|
if (parseInt(new_message_retention_days, 10).toString() !== new_message_retention_days
|
|
|
|
&& new_message_retention_days !== "") {
|
|
|
|
new_message_retention_days = "";
|
2018-03-22 14:07:52 +01:00
|
|
|
}
|
|
|
|
|
2019-03-25 11:52:55 +01:00
|
|
|
data.message_retention_days = new_message_retention_days !== "" ?
|
|
|
|
JSON.stringify(parseInt(new_message_retention_days, 10)) : null;
|
2019-03-25 13:48:07 +01:00
|
|
|
} else if (subsection === 'other_permissions') {
|
2019-11-02 00:06:25 +01:00
|
|
|
const waiting_period_threshold = $("#id_realm_waiting_period_setting").val();
|
|
|
|
const add_emoji_permission = $("#id_realm_add_emoji_by_admins_only").val();
|
2018-03-22 14:07:52 +01:00
|
|
|
|
|
|
|
if (add_emoji_permission === "by_admins_only") {
|
|
|
|
data.add_emoji_by_admins_only = true;
|
|
|
|
} else if (add_emoji_permission === "by_anyone") {
|
|
|
|
data.add_emoji_by_admins_only = false;
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
if (waiting_period_threshold === "none") {
|
|
|
|
data.waiting_period_threshold = 0;
|
|
|
|
} else if (waiting_period_threshold === "three_days") {
|
|
|
|
data.waiting_period_threshold = 3;
|
|
|
|
} else if (waiting_period_threshold === "custom_days") {
|
|
|
|
data.waiting_period_threshold = $("#id_realm_waiting_period_threshold").val();
|
|
|
|
}
|
2018-04-05 00:54:31 +02:00
|
|
|
} else if (subsection === 'org_join') {
|
2019-11-02 00:06:25 +01:00
|
|
|
const org_join_restrictions = $('#id_realm_org_join_restrictions').val();
|
2018-04-05 00:54:31 +02:00
|
|
|
if (org_join_restrictions === "only_selected_domain") {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.emails_restricted_to_domains = true;
|
|
|
|
data.disallow_disposable_email_addresses = false;
|
2018-04-05 00:54:31 +02:00
|
|
|
} else if (org_join_restrictions === "no_disposable_email") {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.emails_restricted_to_domains = false;
|
|
|
|
data.disallow_disposable_email_addresses = true;
|
2018-04-05 00:54:31 +02:00
|
|
|
} else if (org_join_restrictions === "no_restriction") {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.disallow_disposable_email_addresses = false;
|
|
|
|
data.emails_restricted_to_domains = false;
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
2018-04-30 18:26:59 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_invite_restriction = $('#id_realm_user_invite_restriction').val();
|
2018-04-30 18:26:59 +02:00
|
|
|
if (user_invite_restriction === 'no_invite_required') {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.invite_required = false;
|
|
|
|
data.invite_by_admins_only = false;
|
2018-04-30 18:26:59 +02:00
|
|
|
} else if (user_invite_restriction === 'by_admins_only') {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.invite_required = true;
|
|
|
|
data.invite_by_admins_only = true;
|
2018-04-30 18:26:59 +02:00
|
|
|
} else {
|
2019-03-25 11:52:55 +01:00
|
|
|
data.invite_required = true;
|
|
|
|
data.invite_by_admins_only = false;
|
2018-04-30 18:26:59 +02:00
|
|
|
}
|
2019-04-06 08:43:34 +02:00
|
|
|
} else if (subsection === 'auth_settings') {
|
|
|
|
data = {};
|
|
|
|
data.authentication_methods = JSON.stringify(get_auth_method_table_data());
|
2019-07-30 09:52:06 +02:00
|
|
|
} else if (subsection === 'user_defaults') {
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_default_twenty_four_hour_time = $('#id_realm_default_twenty_four_hour_time').val();
|
2019-07-30 09:52:06 +02:00
|
|
|
data.default_twenty_four_hour_time = realm_default_twenty_four_hour_time;
|
2018-03-14 23:45:42 +01:00
|
|
|
}
|
2019-03-25 11:52:55 +01:00
|
|
|
return data;
|
2018-03-21 00:50:00 +01:00
|
|
|
}
|
|
|
|
|
2019-05-05 15:13:52 +02:00
|
|
|
function populate_data_for_request(subsection) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
|
|
|
const properties_elements = get_subsection_property_elements(subsection);
|
2019-05-05 15:13:52 +02:00
|
|
|
_.each(properties_elements, function (input_elem) {
|
|
|
|
input_elem = $(input_elem);
|
2019-05-05 15:49:37 +02:00
|
|
|
if (check_property_changed(input_elem)) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const input_type = input_elem.data("setting-widget-type");
|
2019-05-05 15:49:37 +02:00
|
|
|
if (input_type) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const property_name = input_elem.attr('id').replace("id_realm_", "");
|
2019-05-05 15:49:37 +02:00
|
|
|
if (input_type === 'bool') {
|
|
|
|
data[property_name] = JSON.stringify(input_elem.prop('checked'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (input_type === 'text') {
|
|
|
|
data[property_name] = JSON.stringify(input_elem.val().trim());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (input_type === 'integer') {
|
|
|
|
data[property_name] = JSON.stringify(parseInt(input_elem.val().trim(), 10));
|
|
|
|
}
|
2019-05-05 15:13:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
$(".organization").on("click", ".subsection-header .subsection-changes-save .button", function (e) {
|
2018-03-21 00:50:00 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const save_button = $(e.currentTarget);
|
|
|
|
const subsection_id = save_button.attr('id').replace("org-submit-", "");
|
|
|
|
const subsection = subsection_id.split('-').join('_');
|
|
|
|
const subsection_elem = save_button.closest('.org-subsection-parent');
|
2018-03-21 00:50:00 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let data = populate_data_for_request(subsection_elem);
|
2019-03-25 11:52:55 +01:00
|
|
|
data = _.extend(data, get_complete_data_for_subsection(subsection));
|
|
|
|
exports.save_organization_settings(data, save_button);
|
2017-05-25 00:50:07 +02:00
|
|
|
});
|
2017-08-18 01:23:55 +02:00
|
|
|
|
2018-03-22 14:16:53 +01:00
|
|
|
$(".org-subsection-parent").on("keydown", "input", function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(e.target).closest('.org-subsection-parent').find('.subsection-changes-save button').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
$("#id_realm_msg_edit_limit_setting").change(function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_edit_limit_dropdown_value = e.target.value;
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_message_content_edit_limit_minutes',
|
|
|
|
msg_edit_limit_dropdown_value === 'custom_limit');
|
2018-04-02 11:18:40 +02:00
|
|
|
});
|
|
|
|
|
2017-11-26 09:12:10 +01:00
|
|
|
$("#id_realm_msg_delete_limit_setting").change(function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_delete_limit_dropdown_value = e.target.value;
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_message_content_delete_limit_minutes',
|
|
|
|
msg_delete_limit_dropdown_value === 'custom_limit');
|
2017-11-26 09:12:10 +01:00
|
|
|
});
|
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
$("#id_realm_waiting_period_setting").change(function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const waiting_period_threshold = this.value;
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property('id_realm_waiting_period_threshold',
|
|
|
|
waiting_period_threshold === 'custom_days');
|
2018-01-05 15:34:10 +01:00
|
|
|
});
|
|
|
|
|
2018-04-23 14:51:30 +02:00
|
|
|
$("#id_realm_video_chat_provider").change(function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const available_providers = page_params.realm_available_video_chat_providers;
|
|
|
|
const video_chat_provider_id = parseInt(e.target.value, 10);
|
2019-05-09 09:54:38 +02:00
|
|
|
|
|
|
|
if (video_chat_provider_id === available_providers.google_hangouts.id) {
|
2018-12-28 20:45:54 +01:00
|
|
|
$("#google_hangouts_domain").show();
|
|
|
|
$(".zoom_credentials").hide();
|
2019-05-09 09:54:38 +02:00
|
|
|
} else if (video_chat_provider_id === available_providers.zoom.id) {
|
2018-12-28 20:45:54 +01:00
|
|
|
$("#google_hangouts_domain").hide();
|
|
|
|
$(".zoom_credentials").show();
|
2018-04-23 14:51:30 +02:00
|
|
|
} else {
|
2018-12-28 20:45:54 +01:00
|
|
|
$("#google_hangouts_domain").hide();
|
|
|
|
$(".zoom_credentials").hide();
|
2018-04-23 14:51:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-05 00:54:31 +02:00
|
|
|
$("#id_realm_org_join_restrictions").change(function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const org_join_restrictions = e.target.value;
|
|
|
|
const node = $("#allowed_domains_label").parent();
|
2018-04-05 00:54:31 +02:00
|
|
|
if (org_join_restrictions === 'only_selected_domain') {
|
|
|
|
node.show();
|
|
|
|
if (_.isEmpty(page_params.realm_domains)) {
|
|
|
|
overlays.open_modal('realm_domains_modal');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#id_realm_org_join_restrictions").click(function (e) {
|
|
|
|
// This prevents the disappearance of modal when there are
|
|
|
|
// no allowed domains otherwise it gets closed due to
|
|
|
|
// the click event handler attached to `#settings_overlay_container`
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-04-28 21:34:57 +02:00
|
|
|
function fade_status_element(elem) {
|
|
|
|
setTimeout(function () {
|
|
|
|
elem.fadeOut(500);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
$("#realm_domains_table").on("click", ".delete_realm_domain", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const domain = $(this).parents("tr").find(".domain").text();
|
|
|
|
const url = "/json/realm/domains/" + domain;
|
|
|
|
const realm_domains_info = $(".realm_domains_info");
|
2017-04-08 18:13:39 +02:00
|
|
|
|
|
|
|
channel.del({
|
|
|
|
url: url,
|
|
|
|
success: function () {
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.success(i18n.t("Deleted successfully!"), realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#submit-add-realm-domain").click(function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_domains_info = $(".realm_domains_info");
|
|
|
|
const widget = $("#add-realm-domain-widget");
|
|
|
|
const domain = widget.find(".new-realm-domain").val();
|
|
|
|
const allow_subdomains = widget.find(".new-realm-domain-allow-subdomains").prop("checked");
|
|
|
|
const data = {
|
2017-04-08 18:13:39 +02:00
|
|
|
domain: JSON.stringify(domain),
|
|
|
|
allow_subdomains: JSON.stringify(allow_subdomains),
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: "/json/realm/domains",
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
|
|
|
$("#add-realm-domain-widget .new-realm-domain").val("");
|
|
|
|
$("#add-realm-domain-widget .new-realm-domain-allow-subdomains").prop("checked", false);
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.success(i18n.t("Added successfully!"), realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#realm_domains_table").on("change", ".allow-subdomains", function (e) {
|
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_domains_info = $(".realm_domains_info");
|
|
|
|
const domain = $(this).parents("tr").find(".domain").text();
|
|
|
|
const allow_subdomains = $(this).prop('checked');
|
|
|
|
const url = '/json/realm/domains/' + domain;
|
|
|
|
const data = {
|
2017-04-08 18:13:39 +02:00
|
|
|
allow_subdomains: JSON.stringify(allow_subdomains),
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
|
|
|
if (allow_subdomains) {
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.success(i18n.t("Update successful: Subdomains allowed for __domain__",
|
|
|
|
{domain: domain}), realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
} else {
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.success(i18n.t("Update successful: Subdomains no longer allowed for __domain__",
|
|
|
|
{domain: domain}), realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
}
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-12-25 17:49:46 +01:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-01-11 21:25:52 +01:00
|
|
|
function notification_stream_update(stream_id, notification_type) {
|
2020-01-11 21:55:17 +01:00
|
|
|
exports.render_notifications_stream_ui(stream_id, notification_type);
|
2020-01-13 12:32:38 +01:00
|
|
|
save_discard_widget_status_handler($('#org-notifications'));
|
2017-10-20 16:55:04 +02:00
|
|
|
}
|
|
|
|
|
2020-01-11 21:25:52 +01:00
|
|
|
$(".notifications-stream-setting .dropdown-list-body").on("click keypress", ".stream_name", function (e) {
|
|
|
|
const notifications_stream_setting_elem = $(this).closest(".notifications-stream-setting");
|
2017-10-20 16:55:04 +02:00
|
|
|
if (e.type === "keypress") {
|
|
|
|
if (e.which === 13) {
|
2020-01-11 21:25:52 +01:00
|
|
|
notifications_stream_setting_elem.find(".dropdown-menu").dropdown("toggle");
|
2017-10-20 16:55:04 +02:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-12-30 13:20:45 +01:00
|
|
|
const stream_id = parseInt($(this).attr('data-stream-id'), 10);
|
2020-01-11 21:25:52 +01:00
|
|
|
notification_stream_update(stream_id, notifications_stream_setting_elem.data("notifications-type"));
|
2017-10-20 16:55:04 +02:00
|
|
|
});
|
|
|
|
|
2020-01-11 21:25:52 +01:00
|
|
|
$(".notification-disable").click(function (e) {
|
|
|
|
notification_stream_update(-1, e.target.id.replace("_stream_disable", ""));
|
2017-10-20 16:55:04 +02:00
|
|
|
});
|
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
function upload_realm_icon(file_input) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const form_data = new FormData();
|
2017-04-08 18:13:39 +02:00
|
|
|
|
|
|
|
form_data.append('csrfmiddlewaretoken', csrf_token);
|
|
|
|
jQuery.each(file_input[0].files, function (i, file) {
|
2018-06-04 21:13:07 +02:00
|
|
|
form_data.append('file-' + i, file);
|
2017-04-08 18:13:39 +02:00
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const error_field = $("#realm_icon_file_input_error");
|
2018-08-16 01:26:55 +02:00
|
|
|
error_field.hide();
|
2019-11-02 00:06:25 +01:00
|
|
|
const spinner = $("#upload_icon_spinner").expectOne();
|
2019-03-09 17:43:48 +01:00
|
|
|
loading.make_indicator(spinner, {text: i18n.t("Uploading profile picture.")});
|
2018-08-16 01:26:55 +02:00
|
|
|
$("#upload_icon_button_text").expectOne().hide();
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2017-07-05 19:02:54 +02:00
|
|
|
channel.post({
|
2017-04-08 18:13:39 +02:00
|
|
|
url: '/json/realm/icon',
|
|
|
|
data: form_data,
|
|
|
|
cache: false,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success: function () {
|
|
|
|
loading.destroy_indicator($("#upload_icon_spinner"));
|
2018-08-16 01:26:55 +02:00
|
|
|
$("#upload_icon_button_text").expectOne().show();
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2019-01-13 08:51:46 +01:00
|
|
|
loading.destroy_indicator($("#upload_icon_spinner"));
|
|
|
|
$("#upload_icon_button_text").expectOne().show();
|
2018-08-16 01:26:55 +02:00
|
|
|
ui_report.error("", xhr, error_field);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
realm_icon.build_realm_icon_widget(upload_realm_icon);
|
|
|
|
|
2019-01-27 08:25:10 +01:00
|
|
|
function upload_realm_logo(file_input, night) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const form_data = new FormData();
|
|
|
|
let spinner;
|
|
|
|
let error_field;
|
|
|
|
let button_text;
|
2018-08-16 01:26:55 +02:00
|
|
|
|
|
|
|
form_data.append('csrfmiddlewaretoken', csrf_token);
|
|
|
|
jQuery.each(file_input[0].files, function (i, file) {
|
|
|
|
form_data.append('file-' + i, file);
|
|
|
|
});
|
2019-01-27 08:25:10 +01:00
|
|
|
if (night) {
|
2019-08-21 10:37:51 +02:00
|
|
|
error_field = $("#night-logo-section .realm-logo-file-input-error");
|
2019-08-21 12:25:14 +02:00
|
|
|
spinner = $("#night-logo-section .upload-logo-spinner");
|
|
|
|
button_text = $("#night-logo-section .upload-logo-button-text");
|
2019-01-27 08:25:10 +01:00
|
|
|
} else {
|
2019-08-21 10:37:51 +02:00
|
|
|
error_field = $("#day-logo-section .realm-logo-file-input-error");
|
2019-08-21 12:25:14 +02:00
|
|
|
spinner = $("#day-logo-section .upload-logo-spinner");
|
|
|
|
button_text = $("#day-logo-section .upload-logo-button-text");
|
2019-01-27 08:25:10 +01:00
|
|
|
}
|
|
|
|
spinner.expectOne();
|
2018-08-16 01:26:55 +02:00
|
|
|
error_field.hide();
|
2019-01-27 08:25:10 +01:00
|
|
|
button_text.expectOne().hide();
|
2018-08-16 01:26:55 +02:00
|
|
|
loading.make_indicator(spinner, {text: i18n.t("Uploading logo.")});
|
2019-01-27 08:25:10 +01:00
|
|
|
form_data.append('night', JSON.stringify(night));
|
2018-08-16 01:26:55 +02:00
|
|
|
channel.post({
|
|
|
|
url: '/json/realm/logo',
|
|
|
|
data: form_data,
|
|
|
|
cache: false,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success: function () {
|
2019-01-27 08:25:10 +01:00
|
|
|
loading.destroy_indicator(spinner);
|
|
|
|
button_text.expectOne().show();
|
2018-08-16 01:26:55 +02:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2019-01-27 08:25:10 +01:00
|
|
|
loading.destroy_indicator(spinner);
|
|
|
|
button_text.expectOne().show();
|
2018-08-16 01:26:55 +02:00
|
|
|
ui_report.error("", xhr, error_field);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-02-27 15:45:26 +01:00
|
|
|
|
2019-06-12 14:22:37 +02:00
|
|
|
if (page_params.plan_includes_wide_organization_logo) {
|
|
|
|
realm_logo.build_realm_logo_widget(upload_realm_logo, false);
|
|
|
|
realm_logo.build_realm_logo_widget(upload_realm_logo, true);
|
|
|
|
}
|
2019-03-11 16:48:59 +01:00
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
|
2018-01-30 14:58:50 +01:00
|
|
|
$('#deactivate_realm_button').on('click', function (e) {
|
|
|
|
if (!overlays.is_modal_open()) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
overlays.open_modal('deactivate-realm-modal');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#do_deactivate_realm_button').on('click', function () {
|
|
|
|
if (overlays.is_modal_open()) {
|
|
|
|
overlays.close_modal('deactivate-realm-modal');
|
|
|
|
}
|
|
|
|
channel.post({
|
2018-12-18 19:34:45 +01:00
|
|
|
url: '/json/realm/deactivate',
|
2018-01-30 14:58:50 +01:00
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(
|
|
|
|
i18n.t("Failed"), xhr, $('#admin-realm-deactivation-status').expectOne()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2017-04-08 18:13:39 +02:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.settings_org = exports;
|