2017-04-08 18:13:39 +02:00
|
|
|
var settings_org = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var meta = {
|
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2017-04-17 16:51:27 +02:00
|
|
|
exports.reset = function () {
|
|
|
|
meta.loaded = false;
|
|
|
|
};
|
|
|
|
|
2018-03-28 23:53:20 +02:00
|
|
|
var org_profile = {
|
|
|
|
name: {
|
|
|
|
type: 'text',
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: 'text',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var org_settings = {
|
|
|
|
msg_editing: {
|
|
|
|
allow_edit_history: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
2018-04-21 19:30:32 +02:00
|
|
|
allow_community_topic_editing: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
2018-03-28 23:53:20 +02:00
|
|
|
},
|
|
|
|
msg_feed: {
|
|
|
|
inline_image_preview: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
|
|
|
inline_url_embed_preview: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
|
|
|
mandatory_topics: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
|
|
|
},
|
2018-04-23 14:51:30 +02:00
|
|
|
video_chat: {
|
|
|
|
video_chat_provider: {
|
|
|
|
type: 'text',
|
|
|
|
},
|
|
|
|
google_hangouts_domain: {
|
|
|
|
type: 'text',
|
|
|
|
},
|
|
|
|
},
|
2018-03-31 07:39:22 +02:00
|
|
|
user_defaults: {
|
2018-03-28 23:53:20 +02:00
|
|
|
default_language: {
|
|
|
|
type: 'text',
|
|
|
|
},
|
2018-03-30 22:38:16 +02:00
|
|
|
default_twenty_four_hour_time: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
2018-03-31 07:39:22 +02:00
|
|
|
},
|
|
|
|
notifications: {
|
2018-03-28 23:53:20 +02:00
|
|
|
send_welcome_emails: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var org_permissions = {
|
|
|
|
user_identity: {
|
|
|
|
name_changes_disabled: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
|
|
|
email_changes_disabled: {
|
|
|
|
type: 'bool',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
other_permissions: {
|
|
|
|
bot_creation_policy: {
|
|
|
|
type: 'integer',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-03-29 12:52:57 +02:00
|
|
|
function get_subsection_property_types(subsection) {
|
|
|
|
if (_.has(org_settings, subsection)) {
|
|
|
|
return org_settings[subsection];
|
|
|
|
} else if (_.has(org_permissions, subsection)) {
|
|
|
|
return org_permissions[subsection];
|
|
|
|
} else if (subsection === 'org_profile') {
|
|
|
|
return org_profile;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:35:14 +02:00
|
|
|
exports.get_realm_time_limits_in_minutes = function (property) {
|
2018-06-04 21:13:07 +02:00
|
|
|
var 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) {
|
2017-11-26 09:12:10 +01:00
|
|
|
var 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
|
|
|
}
|
|
|
|
|
|
|
|
if (property_name === 'realm_create_stream_permission') {
|
2018-03-29 12:52:57 +02:00
|
|
|
if (page_params.realm_create_stream_by_admins_only) {
|
|
|
|
return "by_admins_only";
|
|
|
|
}
|
|
|
|
if (page_params.realm_waiting_period_threshold === 0) {
|
|
|
|
return "by_anyone";
|
|
|
|
}
|
|
|
|
if (page_params.realm_waiting_period_threshold === 3) {
|
|
|
|
return "by_admin_user_with_three_days_old";
|
|
|
|
}
|
|
|
|
return "by_admin_user_with_custom_time";
|
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
|
|
|
|
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_", "");
|
|
|
|
};
|
|
|
|
|
2018-04-01 08:49:10 +02:00
|
|
|
function set_create_stream_permission_dropdown() {
|
2018-04-02 00:16:50 +02:00
|
|
|
var value = get_property_value("realm_create_stream_permission");
|
|
|
|
$("#id_realm_create_stream_permission").val(value);
|
|
|
|
if (value === "by_admin_user_with_custom_time") {
|
2018-01-05 15:34:10 +01:00
|
|
|
$("#id_realm_waiting_period_threshold").parent().show();
|
2018-04-02 00:16:50 +02:00
|
|
|
} else {
|
|
|
|
$("#id_realm_waiting_period_threshold").parent().hide();
|
2018-01-05 15:34:10 +01:00
|
|
|
}
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-01-05 15:34:10 +01:00
|
|
|
|
2018-04-01 08:49:10 +02:00
|
|
|
function set_add_emoji_permission_dropdown() {
|
2018-04-02 00:16:50 +02:00
|
|
|
$("#id_realm_add_emoji_by_admins_only").val(get_property_value("realm_add_emoji_by_admins_only"));
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-01-21 09:49:23 +01:00
|
|
|
|
2018-04-23 14:51:30 +02:00
|
|
|
function set_video_chat_provider_dropdown() {
|
|
|
|
var chat_provider = page_params.realm_video_chat_provider;
|
|
|
|
$("#id_realm_video_chat_provider").val(chat_provider);
|
|
|
|
if (chat_provider === "Google Hangouts") {
|
|
|
|
$("#google_hangouts_domain").show();
|
|
|
|
$("#id_realm_google_hangouts_domain").val(page_params.realm_google_hangouts_domain);
|
|
|
|
} else {
|
|
|
|
$("#google_hangouts_domain").hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 19:01:46 +02:00
|
|
|
var time_limit_dropdown_values = {
|
|
|
|
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() {
|
|
|
|
var value = get_property_value("realm_msg_edit_limit_setting");
|
|
|
|
$("#id_realm_msg_edit_limit_setting").val(value);
|
|
|
|
if (value === "custom_limit") {
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes").parent().show();
|
|
|
|
} else {
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes").parent().hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 09:12:10 +01:00
|
|
|
function set_msg_delete_limit_dropdown() {
|
|
|
|
var value = get_property_value("realm_msg_delete_limit_setting");
|
|
|
|
$("#id_realm_msg_delete_limit_setting").val(value);
|
|
|
|
if (value === "custom_limit") {
|
|
|
|
$("#id_realm_message_content_delete_limit_minutes").parent().show();
|
|
|
|
} else {
|
|
|
|
$("#id_realm_message_content_delete_limit_minutes").parent().hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:26:59 +02:00
|
|
|
function set_user_invite_restriction_dropdown() {
|
|
|
|
$("#id_realm_user_invite_restriction").val(get_property_value("realm_user_invite_restriction"));
|
|
|
|
}
|
|
|
|
|
2018-04-05 00:54:31 +02:00
|
|
|
function set_org_join_restrictions_dropdown() {
|
|
|
|
var value = get_property_value("realm_org_join_restrictions");
|
|
|
|
$("#id_realm_org_join_restrictions").val(value);
|
|
|
|
var node = $("#allowed_domains_label").parent();
|
|
|
|
if (value === 'only_selected_domain') {
|
|
|
|
node.show();
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
exports.populate_realm_domains = function (realm_domains) {
|
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var 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
|
|
|
});
|
|
|
|
var domains = domains_list.join(', ');
|
|
|
|
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
|
|
|
|
|
|
|
var realm_domains_table_body = $("#realm_domains_table tbody").expectOne();
|
|
|
|
realm_domains_table_body.find("tr").remove();
|
|
|
|
_.each(realm_domains, function (realm_domain) {
|
|
|
|
realm_domains_table_body.append(templates.render("admin-realm-domains-list", {realm_domain: realm_domain}));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.populate_auth_methods = function (auth_methods) {
|
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var auth_methods_table = $("#admin_auth_methods_table").expectOne();
|
|
|
|
auth_methods_table.find('tr.method_row').remove();
|
|
|
|
_.each(_.keys(auth_methods).sort(), function (key) {
|
|
|
|
auth_methods_table.append(templates.render('admin_auth_methods_list', {
|
|
|
|
method: {
|
|
|
|
method: key,
|
|
|
|
enabled: auth_methods[key],
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
loading.destroy_indicator($('#admin_page_auth_methods_loading_indicator'));
|
2017-05-17 20:54:09 +02:00
|
|
|
if (!page_params.is_admin) {
|
|
|
|
$(".organization-box [data-name='auth-methods']")
|
|
|
|
.find("input, button, select, checked").attr("disabled", true);
|
2017-09-07 06:00:54 +02:00
|
|
|
var tip_box = $("<div class='tip'></div>")
|
|
|
|
.text(i18n.t("Only organization administrators can edit these settings."));
|
2017-07-13 20:53:27 +02:00
|
|
|
// Don't prepend a tip to custom emoji settings page. We handle it separately.
|
2017-06-02 06:30:00 +02:00
|
|
|
$(".organization-box").find(".settings-section:not(.can-edit)")
|
2017-07-13 20:53:27 +02:00
|
|
|
.not("#emoji-settings")
|
2018-02-19 13:35:18 +01:00
|
|
|
.not("#user-groups-admin")
|
2017-09-07 06:00:54 +02:00
|
|
|
.prepend(tip_box);
|
2017-05-17 20:54:09 +02:00
|
|
|
}
|
2017-04-08 18:13:39 +02:00
|
|
|
};
|
|
|
|
|
2017-06-16 14:39:21 +02:00
|
|
|
|
2018-03-31 03:08:33 +02:00
|
|
|
exports.render_notifications_stream_ui = function (stream_id, elem) {
|
2017-06-16 14:39:21 +02:00
|
|
|
|
2017-07-15 08:31:55 +02:00
|
|
|
var name = stream_data.maybe_get_stream_name(stream_id);
|
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) {
|
|
|
|
var dropdown_list_body = $("#id_realm_notifications_stream .dropdown-list-body").expectOne();
|
|
|
|
var search_input = $("#id_realm_notifications_stream .dropdown-search > input[type=text]");
|
|
|
|
|
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) {
|
|
|
|
return templates.render("admin-realm-dropdown-stream-list", { stream: item });
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: search_input,
|
|
|
|
callback: 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 () {
|
|
|
|
ui.update_scrollbar(dropdown_list_body);
|
|
|
|
},
|
2017-06-10 07:03:53 +02:00
|
|
|
},
|
|
|
|
}).init();
|
|
|
|
|
2017-09-27 19:01:04 +02:00
|
|
|
ui.set_up_scrollbar(dropdown_list_body);
|
|
|
|
|
2017-06-10 07:03:53 +02:00
|
|
|
$("#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) {
|
|
|
|
var dropdown_list_body = $("#id_realm_signup_notifications_stream .dropdown-list-body").expectOne();
|
|
|
|
var search_input = $("#id_realm_signup_notifications_stream .dropdown-search > input[type=text]");
|
|
|
|
|
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) {
|
|
|
|
return templates.render("admin-realm-dropdown-stream-list", { stream: item });
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: search_input,
|
|
|
|
callback: function (item, value) {
|
|
|
|
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) {
|
2018-03-29 13:31:20 +02:00
|
|
|
if (property_name === 'realm_create_stream_permission' || property_name === 'realm_waiting_period_threshold') {
|
2018-04-01 08:49:10 +02:00
|
|
|
set_create_stream_permission_dropdown();
|
2018-05-06 21:43:17 +02:00
|
|
|
} else if (property_name === 'realm_video_chat_provider' ||
|
|
|
|
property_name === 'realm_google_hangouts_domain') {
|
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();
|
2018-04-30 18:26:59 +02:00
|
|
|
} else if (property_name === 'realm_user_invite_restriction') {
|
|
|
|
set_user_invite_restriction_dropdown();
|
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);
|
|
|
|
var property_name = exports.extract_property_name(elem);
|
2018-04-01 08:56:18 +02:00
|
|
|
var property_value = get_property_value(property_name);
|
2018-03-29 12:58:35 +02:00
|
|
|
|
|
|
|
if (typeof property_value === 'boolean') {
|
|
|
|
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-03-29 13:31:20 +02:00
|
|
|
} else if (property === 'create_stream_by_admins_only') {
|
2018-03-29 13:15:50 +02:00
|
|
|
property = 'create_stream_permission';
|
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
|
|
|
}
|
2018-06-04 21:13:07 +02:00
|
|
|
var element = $('#id_realm_' + property);
|
2018-03-29 13:15:50 +02:00
|
|
|
if (element.length) {
|
|
|
|
discard_property_element_changes(element);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
exports.change_save_button_state = function ($element, state) {
|
|
|
|
var show_hide_element = function (state) {
|
|
|
|
if (state === 'show') {
|
2018-04-30 15:01:55 +02:00
|
|
|
$element.removeClass('hide').addClass('.show').fadeIn(300);
|
2018-03-29 02:02:01 +02:00
|
|
|
} else {
|
2018-04-30 15:01:55 +02:00
|
|
|
$element.fadeOut(300);
|
2018-03-29 02:02:01 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var $saveBtn = $element.find('.save-button');
|
|
|
|
var $textEl = $saveBtn.find('.icon-button-text');
|
|
|
|
if (state !== "saving") {
|
|
|
|
$saveBtn.removeClass('saving');
|
|
|
|
}
|
|
|
|
if (state === "unsaved") {
|
|
|
|
$textEl.text(i18n.t("Save changes"));
|
|
|
|
$saveBtn.attr("data-status", "unsaved");
|
|
|
|
show_hide_element('show');
|
|
|
|
} else if (state === "saved") {
|
|
|
|
$textEl.text(i18n.t("Save changes"));
|
|
|
|
$saveBtn.attr("data-status", "");
|
|
|
|
show_hide_element('hide');
|
|
|
|
} else if (state === "discarded") {
|
|
|
|
$element.removeClass('saving');
|
|
|
|
show_hide_element('hide');
|
|
|
|
} else if (state === "saving") {
|
|
|
|
$saveBtn.addClass('saving');
|
|
|
|
$textEl.text(i18n.t("Saving"));
|
|
|
|
$saveBtn.attr("data-status", "saving");
|
|
|
|
show_hide_element('show');
|
|
|
|
} else if (state === "failed") {
|
|
|
|
show_hide_element('show');
|
|
|
|
$textEl.text(i18n.t("Save changes"));
|
|
|
|
$saveBtn.attr("data-status", "failed");
|
|
|
|
} else if (state === 'succeeded') {
|
|
|
|
show_hide_element('hide');
|
|
|
|
$textEl.text(i18n.t("Saved"));
|
|
|
|
$saveBtn.attr("data-status", "saved");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-30 18:03:34 +02:00
|
|
|
exports.set_up = 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) {
|
2017-10-20 16:55:04 +02:00
|
|
|
var streams = stream_data.get_streams_for_settings_page();
|
|
|
|
exports.populate_notifications_stream_dropdown(streams);
|
|
|
|
exports.populate_signup_notifications_stream_dropdown(streams);
|
2017-06-10 07:03:53 +02:00
|
|
|
}
|
2018-03-31 03:08:33 +02:00
|
|
|
exports.render_notifications_stream_ui(page_params.realm_notifications_stream_id,
|
|
|
|
$('#realm_notifications_stream_name'));
|
2018-03-31 03:44:07 +02:00
|
|
|
exports.render_notifications_stream_ui(page_params.realm_signup_notifications_stream_id,
|
|
|
|
$('#realm_signup_notifications_stream_name'));
|
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);
|
|
|
|
|
2018-03-13 22:14:47 +01:00
|
|
|
function populate_data_for_request(data, changing_property_types) {
|
|
|
|
_.each(changing_property_types, function (v, k) {
|
|
|
|
var field = changing_property_types[k];
|
2017-05-25 00:50:07 +02:00
|
|
|
if (field.type === 'bool') {
|
2018-06-04 21:13:07 +02:00
|
|
|
data[k] = JSON.stringify($('#id_realm_' + k).prop('checked'));
|
2017-05-25 00:50:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-29 02:14:45 +02:00
|
|
|
if (field.type === 'text') {
|
2018-06-04 21:13:07 +02:00
|
|
|
data[k] = JSON.stringify($('#id_realm_' + k).val().trim());
|
2017-05-25 00:50:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-29 02:18:27 +02:00
|
|
|
if (field.type === 'integer') {
|
2018-06-04 21:13:07 +02:00
|
|
|
data[k] = JSON.stringify(parseInt($("#id_realm_" + k).val().trim(), 10));
|
2017-08-29 02:18:27 +02:00
|
|
|
}
|
2017-05-25 00:50:07 +02:00
|
|
|
});
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2018-04-01 08:49:10 +02:00
|
|
|
set_create_stream_permission_dropdown();
|
|
|
|
set_add_emoji_permission_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();
|
2018-04-30 18:26:59 +02:00
|
|
|
set_user_invite_restriction_dropdown();
|
2018-03-05 19:19:19 +01:00
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
function check_property_changed(elem) {
|
|
|
|
elem = $(elem);
|
|
|
|
var property_name = exports.extract_property_name(elem);
|
|
|
|
var changed_val;
|
2018-04-01 08:56:18 +02:00
|
|
|
var current_val = get_property_value(property_name);
|
2018-03-22 13:50:27 +01:00
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
if (typeof current_val === 'boolean') {
|
|
|
|
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
|
|
|
}
|
2018-03-22 13:50:27 +01:00
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
return current_val !== changed_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_subsection_property_elements(element) {
|
|
|
|
var subsection = $(element).closest('.org-subsection-parent');
|
2018-03-26 12:06:42 +02:00
|
|
|
return subsection.find("input[id^='id_realm_'], select[id^='id_realm_'], textarea[id^='id_realm_']");
|
2018-03-14 23:50:17 +01:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2018-04-30 15:27:35 +02:00
|
|
|
var subsection = $(e.target).closest('.org-subsection-parent');
|
|
|
|
subsection.find('.subsection-failed-status p').hide();
|
|
|
|
subsection.find('.save-button').show();
|
2018-03-14 23:50:17 +01:00
|
|
|
var properties_elements = get_subsection_property_elements(subsection);
|
|
|
|
var show_change_process_button = false;
|
|
|
|
_.each(properties_elements , function (elem) {
|
|
|
|
if (check_property_changed(elem)) {
|
|
|
|
show_change_process_button = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
var save_btn_controls = subsection.find('.subsection-header .save-button-controls');
|
2018-06-06 18:19:09 +02:00
|
|
|
var button_state = show_change_process_button ? "unsaved" : "saved";
|
2018-03-29 02:02:01 +02:00
|
|
|
exports.change_save_button_state(save_btn_controls, button_state);
|
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);
|
2018-03-29 02:02:01 +02:00
|
|
|
var save_btn_controls = $(e.target).closest('.save-button-controls');
|
|
|
|
exports.change_save_button_state(save_btn_controls, "discarded");
|
2018-03-14 23:52:36 +01:00
|
|
|
});
|
|
|
|
|
2018-03-14 23:45:42 +01:00
|
|
|
exports.save_organization_settings = function (data, save_button, success_continuation) {
|
2018-03-22 12:56:15 +01:00
|
|
|
var subsection_parent = save_button.closest('.org-subsection-parent');
|
2018-03-29 02:02:01 +02:00
|
|
|
var save_btn_container = subsection_parent.find('.save-button-controls');
|
2018-04-30 15:27:35 +02:00
|
|
|
var 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,
|
|
|
|
success: function (response_data) {
|
2018-03-14 23:45:42 +01:00
|
|
|
failed_alert_elem.hide();
|
2018-03-29 02:02:01 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
exports.change_save_button_state(save_btn_container, "succeeded");
|
|
|
|
}, 500);
|
2018-03-14 23:45:42 +01:00
|
|
|
if (success_continuation !== undefined) {
|
|
|
|
success_continuation(response_data);
|
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-04-28 15:35:14 +02:00
|
|
|
function parse_time_limit(elem) {
|
|
|
|
return Math.floor(parseFloat(elem.val(), 10).toFixed(1) * 60);
|
|
|
|
}
|
|
|
|
exports.parse_time_limit = parse_time_limit;
|
|
|
|
|
2018-03-21 00:50:00 +01:00
|
|
|
function get_complete_data_for_subsection(subsection) {
|
|
|
|
var opts = {};
|
2018-03-14 23:45:42 +01:00
|
|
|
if (subsection === 'msg_editing') {
|
2018-04-02 11:18:40 +02:00
|
|
|
var edit_limit_setting_value = $("#id_realm_msg_edit_limit_setting").val();
|
|
|
|
opts.data = {};
|
|
|
|
if (edit_limit_setting_value === 'never') {
|
|
|
|
opts.data.allow_message_editing = false;
|
|
|
|
} else if (edit_limit_setting_value === 'custom_limit') {
|
2018-04-28 15:35:14 +02:00
|
|
|
opts.data.message_content_edit_limit_seconds = parse_time_limit($('#id_realm_message_content_edit_limit_minutes'));
|
|
|
|
// Disable editing if the parsed time limit is 0 seconds
|
|
|
|
opts.data.allow_message_editing = !!opts.data.message_content_edit_limit_seconds;
|
2018-04-02 11:18:40 +02:00
|
|
|
} else {
|
|
|
|
opts.data.allow_message_editing = true;
|
|
|
|
opts.data.message_content_edit_limit_seconds =
|
|
|
|
exports.msg_edit_limit_dropdown_values[edit_limit_setting_value].seconds;
|
2018-03-14 23:45:42 +01:00
|
|
|
}
|
2017-11-26 09:12:10 +01:00
|
|
|
var delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val();
|
|
|
|
if (delete_limit_setting_value === 'never') {
|
|
|
|
opts.data.allow_message_deleting = false;
|
|
|
|
} else if (delete_limit_setting_value === 'custom_limit') {
|
2018-04-28 15:35:14 +02:00
|
|
|
opts.data.message_content_delete_limit_seconds = parse_time_limit($('#id_realm_message_content_delete_limit_minutes'));
|
|
|
|
// Disable deleting if the parsed time limit is 0 seconds
|
|
|
|
opts.data.allow_message_deleting = !!opts.data.message_content_delete_limit_seconds;
|
2017-11-26 09:12:10 +01:00
|
|
|
} else {
|
|
|
|
opts.data.allow_message_deleting = true;
|
|
|
|
opts.data.message_content_delete_limit_seconds =
|
|
|
|
exports.msg_delete_limit_dropdown_values[delete_limit_setting_value].seconds;
|
|
|
|
}
|
2018-03-22 14:07:52 +01:00
|
|
|
} else if (subsection === 'other_permissions') {
|
|
|
|
var create_stream_permission = $("#id_realm_create_stream_permission").val();
|
|
|
|
var add_emoji_permission = $("#id_realm_add_emoji_by_admins_only").val();
|
|
|
|
var new_message_retention_days = $("#id_realm_message_retention_days").val();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
message_retention_days: new_message_retention_days !== "" ?
|
|
|
|
JSON.stringify(parseInt(new_message_retention_days, 10)) : null,
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create_stream_permission === "by_admins_only") {
|
|
|
|
data.create_stream_by_admins_only = true;
|
|
|
|
} else if (create_stream_permission === "by_admin_user_with_three_days_old") {
|
|
|
|
data.create_stream_by_admins_only = false;
|
|
|
|
data.waiting_period_threshold = 3;
|
|
|
|
} else if (create_stream_permission === "by_admin_user_with_custom_time") {
|
|
|
|
data.create_stream_by_admins_only = false;
|
|
|
|
data.waiting_period_threshold = $("#id_realm_waiting_period_threshold").val();
|
|
|
|
} else if (create_stream_permission === "by_anyone") {
|
|
|
|
data.create_stream_by_admins_only = false;
|
|
|
|
data.waiting_period_threshold = 0;
|
|
|
|
}
|
|
|
|
opts.data = data;
|
2018-04-05 00:54:31 +02:00
|
|
|
} else if (subsection === 'org_join') {
|
|
|
|
opts.data = {};
|
|
|
|
|
2018-04-30 18:26:59 +02:00
|
|
|
var org_join_restrictions = $('#id_realm_org_join_restrictions').val();
|
2018-04-05 00:54:31 +02:00
|
|
|
if (org_join_restrictions === "only_selected_domain") {
|
2018-07-27 23:26:29 +02:00
|
|
|
opts.data.emails_restricted_to_domains = true;
|
2018-04-05 00:54:31 +02:00
|
|
|
opts.data.disallow_disposable_email_addresses = false;
|
|
|
|
} else if (org_join_restrictions === "no_disposable_email") {
|
2018-07-27 23:26:29 +02:00
|
|
|
opts.data.emails_restricted_to_domains = false;
|
2018-04-05 00:54:31 +02:00
|
|
|
opts.data.disallow_disposable_email_addresses = true;
|
|
|
|
} else if (org_join_restrictions === "no_restriction") {
|
|
|
|
opts.data.disallow_disposable_email_addresses = false;
|
2018-07-27 23:26:29 +02:00
|
|
|
opts.data.emails_restricted_to_domains = false;
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
2018-04-30 18:26:59 +02:00
|
|
|
|
|
|
|
var user_invite_restriction = $('#id_realm_user_invite_restriction').val();
|
|
|
|
if (user_invite_restriction === 'no_invite_required') {
|
|
|
|
opts.data.invite_required = false;
|
|
|
|
opts.data.invite_by_admins_only = false;
|
|
|
|
} else if (user_invite_restriction === 'by_admins_only') {
|
|
|
|
opts.data.invite_required = true;
|
|
|
|
opts.data.invite_by_admins_only = true;
|
|
|
|
} else {
|
|
|
|
opts.data.invite_required = true;
|
|
|
|
opts.data.invite_by_admins_only = false;
|
|
|
|
}
|
2018-03-14 23:45:42 +01:00
|
|
|
}
|
2018-03-22 14:07:52 +01:00
|
|
|
|
2018-03-21 00:50:00 +01:00
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
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();
|
2018-03-29 02:02:01 +02:00
|
|
|
var save_button = $(e.currentTarget);
|
2018-03-21 00:50:00 +01:00
|
|
|
var subsection_id = save_button.attr('id').replace("org-submit-", "");
|
|
|
|
var subsection = subsection_id.split('-').join('_');
|
|
|
|
|
2018-03-22 14:07:52 +01:00
|
|
|
var data = populate_data_for_request({}, get_subsection_property_types(subsection));
|
2018-03-21 00:50:00 +01:00
|
|
|
var opts = get_complete_data_for_subsection(subsection);
|
2018-03-22 14:07:52 +01:00
|
|
|
data = _.extend(data, opts.data);
|
2018-03-21 00:50:00 +01:00
|
|
|
var success_continuation = opts.success_continuation;
|
2018-01-11 17:47:37 +01:00
|
|
|
|
2018-03-14 23:45:42 +01:00
|
|
|
exports.save_organization_settings(data, save_button, success_continuation);
|
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) {
|
2018-04-27 09:29:20 +02:00
|
|
|
var msg_edit_limit_dropdown_value = e.target.value;
|
2018-04-02 11:18:40 +02:00
|
|
|
var node = $("#id_realm_message_content_edit_limit_minutes").parent();
|
2018-04-27 09:29:20 +02:00
|
|
|
if (msg_edit_limit_dropdown_value === 'custom_limit') {
|
2018-04-02 11:18:40 +02:00
|
|
|
node.show();
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-26 09:12:10 +01:00
|
|
|
$("#id_realm_msg_delete_limit_setting").change(function (e) {
|
|
|
|
var msg_delete_limit_dropdown_value = e.target.value;
|
|
|
|
var node = $("#id_realm_message_content_delete_limit_minutes").parent();
|
|
|
|
if (msg_delete_limit_dropdown_value === 'custom_limit') {
|
|
|
|
node.show();
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-01-05 15:34:10 +01:00
|
|
|
$("#id_realm_create_stream_permission").change(function () {
|
|
|
|
var create_stream_permission = this.value;
|
|
|
|
var node = $("#id_realm_waiting_period_threshold").parent();
|
|
|
|
if (create_stream_permission === 'by_admin_user_with_custom_time') {
|
|
|
|
node.show();
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-23 14:51:30 +02:00
|
|
|
$("#id_realm_video_chat_provider").change(function (e) {
|
|
|
|
var video_chat_provider = e.target.value;
|
|
|
|
var node = $("#google_hangouts_domain");
|
|
|
|
if (video_chat_provider === "Google Hangouts") {
|
|
|
|
node.show();
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-05 00:54:31 +02:00
|
|
|
$("#id_realm_org_join_restrictions").change(function (e) {
|
|
|
|
var org_join_restrictions = e.target.value;
|
|
|
|
var node = $("#allowed_domains_label").parent();
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2017-05-25 00:50:07 +02:00
|
|
|
|
2018-05-22 19:00:25 +02:00
|
|
|
$('#admin_auth_methods_table').change(function () {
|
2017-05-25 00:50:07 +02:00
|
|
|
var new_auth_methods = {};
|
|
|
|
_.each($("#admin_auth_methods_table").find('tr.method_row'), function (method_row) {
|
|
|
|
new_auth_methods[$(method_row).data('method')] = $(method_row).find('input').prop('checked');
|
|
|
|
});
|
|
|
|
|
2018-05-22 19:00:25 +02:00
|
|
|
settings_ui.do_settings_change(channel.patch, '/json/realm',
|
|
|
|
{authentication_methods: JSON.stringify(new_auth_methods)},
|
|
|
|
$('#admin-realm-authentication-methods-status').expectOne()
|
|
|
|
);
|
2017-04-08 18:13:39 +02:00
|
|
|
});
|
|
|
|
|
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 () {
|
|
|
|
var domain = $(this).parents("tr").find(".domain").text();
|
|
|
|
var url = "/json/realm/domains/" + domain;
|
2017-12-02 18:44:39 +01:00
|
|
|
var 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 () {
|
2017-12-02 18:44:39 +01:00
|
|
|
var realm_domains_info = $(".realm_domains_info");
|
2017-04-08 18:13:39 +02:00
|
|
|
var widget = $("#add-realm-domain-widget");
|
|
|
|
var domain = widget.find(".new-realm-domain").val();
|
|
|
|
var allow_subdomains = widget.find(".new-realm-domain-allow-subdomains").prop("checked");
|
|
|
|
var data = {
|
|
|
|
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();
|
2017-12-02 18:44:39 +01:00
|
|
|
var realm_domains_info = $(".realm_domains_info");
|
2017-04-08 18:13:39 +02:00
|
|
|
var domain = $(this).parents("tr").find(".domain").text();
|
|
|
|
var allow_subdomains = $(this).prop('checked');
|
|
|
|
var url = '/json/realm/domains/' + domain;
|
|
|
|
var data = {
|
|
|
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-10 07:03:53 +02:00
|
|
|
var notifications_stream_status = $("#admin-realm-notifications-stream-status").expectOne();
|
|
|
|
function update_notifications_stream(new_notifications_stream_id) {
|
2018-03-31 03:08:33 +02:00
|
|
|
exports.render_notifications_stream_ui(new_notifications_stream_id,
|
|
|
|
$('#realm_notifications_stream_name'));
|
2017-06-10 07:03:53 +02:00
|
|
|
notifications_stream_status.hide();
|
|
|
|
|
|
|
|
var url = "/json/realm";
|
|
|
|
var data = {
|
|
|
|
notifications_stream_id: JSON.stringify(parseInt(new_notifications_stream_id, 10)),
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
|
|
|
|
success: function (response_data) {
|
|
|
|
if (response_data.notifications_stream_id !== undefined) {
|
|
|
|
if (response_data.notifications_stream_id < 0) {
|
|
|
|
ui_report.success(i18n.t("Notifications stream disabled!"), notifications_stream_status);
|
|
|
|
} else {
|
|
|
|
ui_report.success(i18n.t("Notifications stream changed!"), notifications_stream_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(i18n.t("Failed to change notifications stream!"), xhr, notifications_stream_status);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var dropdown_menu = $("#id_realm_notifications_stream .dropdown-menu");
|
|
|
|
$("#id_realm_notifications_stream .dropdown-list-body").on("click keypress", ".stream_name", function (e) {
|
|
|
|
if (e.type === "keypress") {
|
|
|
|
if (e.which === 13) {
|
2018-05-06 21:43:17 +02:00
|
|
|
dropdown_menu.dropdown("toggle");
|
2017-06-10 07:03:53 +02:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update_notifications_stream($(this).attr("data-stream-id"));
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".notifications-stream-disable").click(function () {
|
|
|
|
update_notifications_stream(-1);
|
|
|
|
});
|
|
|
|
|
2017-10-20 16:55:04 +02:00
|
|
|
var signup_notifications_stream_status = $("#admin-realm-signup-notifications-stream-status").expectOne();
|
|
|
|
function update_signup_notifications_stream(new_signup_notifications_stream_id) {
|
2018-03-31 03:44:07 +02:00
|
|
|
exports.render_notifications_stream_ui(new_signup_notifications_stream_id,
|
|
|
|
$('#realm_signup_notifications_stream_name'));
|
2017-10-20 16:55:04 +02:00
|
|
|
signup_notifications_stream_status.hide();
|
|
|
|
var stringified_id = JSON.stringify(parseInt(new_signup_notifications_stream_id, 10));
|
|
|
|
var url = "/json/realm";
|
|
|
|
var data = {
|
|
|
|
signup_notifications_stream_id: stringified_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
|
|
|
|
success: function (response_data) {
|
|
|
|
if (response_data.signup_notifications_stream_id !== undefined) {
|
|
|
|
if (response_data.signup_notifications_stream_id < 0) {
|
|
|
|
ui_report.success(i18n.t("Signup notifications stream disabled!"), signup_notifications_stream_status);
|
|
|
|
} else {
|
|
|
|
ui_report.success(i18n.t("Signup notifications stream changed!"), signup_notifications_stream_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(i18n.t("Failed to change signup notifications stream!"), xhr, signup_notifications_stream_status);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dropdown_menu = $("#id_realm_signup_notifications_stream .dropdown-menu");
|
|
|
|
$("#id_realm_signup_notifications_stream .dropdown-list-body").on("click keypress", ".stream_name", function (e) {
|
|
|
|
if (e.type === "keypress") {
|
|
|
|
if (e.which === 13) {
|
2018-05-06 21:43:17 +02:00
|
|
|
dropdown_menu.dropdown("toggle");
|
2017-10-20 16:55:04 +02:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update_signup_notifications_stream($(this).attr("data-stream-id"));
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".signup-notifications-stream-disable").click(function () {
|
|
|
|
update_signup_notifications_stream(-1);
|
|
|
|
});
|
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
function upload_realm_icon(file_input) {
|
|
|
|
var form_data = new FormData();
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
var spinner = $("#upload_icon_spinner").expectOne();
|
|
|
|
loading.make_indicator(spinner, {text: i18n.t("Uploading icon.")});
|
|
|
|
|
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"));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
realm_icon.build_realm_icon_widget(upload_realm_icon);
|
|
|
|
|
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({
|
|
|
|
url:'/json/realm/deactivate',
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(
|
|
|
|
i18n.t("Failed"), xhr, $('#admin-realm-deactivation-status').expectOne()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2017-04-08 18:13:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_org;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.settings_org = settings_org;
|