2013-08-12 23:31:23 +02:00
|
|
|
var admin = (function () {
|
|
|
|
|
2017-01-31 02:12:11 +01:00
|
|
|
var meta = {
|
|
|
|
loaded: false,
|
|
|
|
};
|
2013-08-12 23:31:23 +02:00
|
|
|
var exports = {};
|
2016-05-20 22:08:42 +02:00
|
|
|
var all_streams = [];
|
2013-08-12 23:31:23 +02:00
|
|
|
|
2014-01-22 01:43:11 +01:00
|
|
|
exports.show_or_hide_menu_item = function () {
|
|
|
|
var item = $('.admin-menu-item').expectOne();
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
item.show();
|
|
|
|
} else {
|
|
|
|
item.hide();
|
2017-02-21 21:34:13 +01:00
|
|
|
$(".administration-box [data-name='organization-settings']")
|
|
|
|
.find("input, button, select").attr("disabled", true);
|
2014-01-22 01:43:11 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-15 00:45:38 +01:00
|
|
|
function get_user_info(user_id) {
|
2016-11-15 04:27:32 +01:00
|
|
|
var self = {};
|
2017-02-15 00:45:38 +01:00
|
|
|
self.user_row = $("tr.user_row[data-user-id='" + user_id + "']");
|
|
|
|
self.form_row = $("tr.user-name-form[data-user-id='" + user_id + "']");
|
2016-11-15 04:27:32 +01:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-11-15 12:37:02 +01:00
|
|
|
function get_email_for_user_row(row) {
|
|
|
|
var email = row.find('.email').text();
|
|
|
|
return email;
|
|
|
|
}
|
|
|
|
|
2017-03-16 12:31:03 +01:00
|
|
|
function update_view_on_deactivate(row) {
|
|
|
|
var button = row.find("button.deactivate");
|
|
|
|
row.find('button.open-user-form').hide();
|
|
|
|
button.addClass("btn-warning");
|
|
|
|
button.removeClass("btn-danger");
|
|
|
|
button.addClass("reactivate");
|
|
|
|
button.removeClass("deactivate");
|
|
|
|
button.text(i18n.t("Reactivate"));
|
|
|
|
row.addClass("deactivated_user");
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_view_on_reactivate(row) {
|
|
|
|
row.find(".user-admin-settings").show();
|
|
|
|
var button = row.find("button.reactivate");
|
|
|
|
row.find("button.open-user-form").show();
|
|
|
|
button.addClass("btn-danger");
|
|
|
|
button.removeClass("btn-warning");
|
|
|
|
button.addClass("deactivate");
|
|
|
|
button.removeClass("reactivate");
|
|
|
|
button.text(i18n.t("Deactivate"));
|
|
|
|
row.removeClass("deactivated_user");
|
|
|
|
}
|
|
|
|
|
2017-02-25 08:49:12 +01:00
|
|
|
exports.update_user_data = function (user_id, new_data) {
|
2017-01-31 02:12:11 +01:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-15 00:45:38 +01:00
|
|
|
var user_info = get_user_info(user_id);
|
2016-11-15 04:27:32 +01:00
|
|
|
var user_row = user_info.user_row;
|
|
|
|
var form_row = user_info.form_row;
|
2016-09-27 14:25:52 +02:00
|
|
|
|
2017-02-25 08:49:12 +01:00
|
|
|
if (new_data.full_name !== undefined) {
|
|
|
|
// Update the full name in the table
|
|
|
|
user_row.find(".user_name").text(new_data.full_name);
|
|
|
|
form_row.find("input[name='full_name']").val(new_data.full_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_data.owner !== undefined) {
|
|
|
|
// Update the bot owner in the table
|
|
|
|
user_row.find(".owner").text(new_data.owner);
|
|
|
|
}
|
|
|
|
|
2017-03-10 09:23:59 +01:00
|
|
|
if (new_data.is_active !== undefined) {
|
|
|
|
if (new_data.is_active === false) {
|
|
|
|
// Deactivate the bot in the table
|
|
|
|
update_view_on_deactivate(user_row);
|
|
|
|
} else {
|
|
|
|
// Reactivate the bot in the table
|
|
|
|
update_view_on_reactivate(user_row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-25 08:49:12 +01:00
|
|
|
// Remove the bot owner select control.
|
|
|
|
form_row.find(".edit_bot_owner_container select").remove();
|
2016-09-27 14:25:52 +02:00
|
|
|
|
|
|
|
// Hide name change form
|
|
|
|
form_row.hide();
|
|
|
|
user_row.show();
|
|
|
|
};
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
function failed_listing_users(xhr) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($('#subs_page_loading_indicator'));
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Error listing users or bots"), xhr, $("#administration-status"));
|
2013-11-22 01:12:53 +01:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
function failed_listing_streams(xhr) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Error listing streams"), xhr, $("#administration-status"));
|
2013-11-22 01:12:53 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 07:02:18 +01:00
|
|
|
function populate_users(realm_people_data) {
|
2013-11-16 16:36:45 +01:00
|
|
|
var users_table = $("#admin_users_table");
|
2013-11-16 17:07:55 +01:00
|
|
|
var deactivated_users_table = $("#admin_deactivated_users_table");
|
2013-11-16 16:36:45 +01:00
|
|
|
var bots_table = $("#admin_bots_table");
|
2013-11-16 17:04:50 +01:00
|
|
|
// Clear table rows, but not the table headers
|
|
|
|
users_table.find("tr.user_row").remove();
|
|
|
|
deactivated_users_table.find("tr.user_row").remove();
|
|
|
|
bots_table.find("tr.user_row").remove();
|
2013-08-12 23:31:23 +02:00
|
|
|
|
2013-11-16 17:07:55 +01:00
|
|
|
var active_users = [];
|
|
|
|
var deactivated_users = [];
|
2013-11-15 20:34:23 +01:00
|
|
|
var bots = [];
|
2013-11-16 17:07:55 +01:00
|
|
|
_.each(realm_people_data.members, function (user) {
|
2014-01-14 21:51:09 +01:00
|
|
|
user.is_active_human = user.is_active && !user.is_bot;
|
2013-11-15 20:34:23 +01:00
|
|
|
if (user.is_bot) {
|
|
|
|
bots.push(user);
|
2013-11-16 17:07:55 +01:00
|
|
|
} else if (user.is_active) {
|
|
|
|
active_users.push(user);
|
2013-11-15 20:34:23 +01:00
|
|
|
} else {
|
2013-11-16 17:07:55 +01:00
|
|
|
deactivated_users.push(user);
|
2013-08-12 23:31:23 +02:00
|
|
|
}
|
|
|
|
});
|
2013-11-15 20:34:23 +01:00
|
|
|
|
2013-11-16 17:07:55 +01:00
|
|
|
active_users = _.sortBy(active_users, 'full_name');
|
|
|
|
deactivated_users = _.sortBy(deactivated_users, 'full_name');
|
2013-11-15 20:34:23 +01:00
|
|
|
bots = _.sortBy(bots, 'full_name');
|
|
|
|
|
2017-03-09 01:14:20 +01:00
|
|
|
var bots_table_html = "";
|
2013-11-16 16:36:45 +01:00
|
|
|
_.each(bots, function (user) {
|
2017-03-09 01:14:20 +01:00
|
|
|
var bot_html = templates.render("admin_user_list", {user: user});
|
|
|
|
bots_table_html = bots_table_html.concat(bot_html);
|
2013-11-16 16:36:45 +01:00
|
|
|
});
|
2017-03-09 01:14:20 +01:00
|
|
|
bots_table.append(bots_table_html);
|
|
|
|
|
2013-11-16 17:07:55 +01:00
|
|
|
_.each(active_users, function (user) {
|
2017-03-26 15:39:12 +02:00
|
|
|
var activity_rendered;
|
|
|
|
var row = $(templates.render("admin_user_list", {user: user}));
|
|
|
|
if (people.is_current_user(user.email)) {
|
|
|
|
activity_rendered = timerender.render_date(new XDate());
|
|
|
|
} else {
|
2017-03-30 20:04:01 +02:00
|
|
|
var last_active_date = presence.last_active_date(user.user_id);
|
|
|
|
if (last_active_date) {
|
|
|
|
activity_rendered = timerender.render_date(last_active_date);
|
|
|
|
} else {
|
2017-03-31 03:11:38 +02:00
|
|
|
activity_rendered = $("<span></span>").text(i18n.t("Unknown"));
|
2017-03-30 20:04:01 +02:00
|
|
|
}
|
2017-03-26 15:39:12 +02:00
|
|
|
}
|
|
|
|
row.find(".last_active").append(activity_rendered);
|
|
|
|
users_table.append(row);
|
2013-11-15 20:34:23 +01:00
|
|
|
});
|
2017-03-09 01:14:20 +01:00
|
|
|
|
|
|
|
var deactivated_table_html = "";
|
2013-11-16 17:07:55 +01:00
|
|
|
_.each(deactivated_users, function (user) {
|
2017-03-09 01:14:20 +01:00
|
|
|
var user_html = templates.render("admin_user_list", {user: user});
|
|
|
|
deactivated_table_html = deactivated_table_html.concat(user_html);
|
2013-11-16 17:07:55 +01:00
|
|
|
});
|
2017-03-09 01:14:20 +01:00
|
|
|
deactivated_users_table.append(deactivated_table_html);
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($('#admin_page_users_loading_indicator'));
|
|
|
|
loading.destroy_indicator($('#admin_page_bots_loading_indicator'));
|
|
|
|
loading.destroy_indicator($('#admin_page_deactivated_users_loading_indicator'));
|
2013-08-12 23:31:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 06:17:31 +02:00
|
|
|
function populate_streams(streams_data) {
|
2013-12-10 23:12:16 +01:00
|
|
|
var streams_table = $("#admin_streams_table").expectOne();
|
2016-05-20 22:08:42 +02:00
|
|
|
all_streams = streams_data;
|
2013-12-10 23:12:16 +01:00
|
|
|
streams_table.find("tr.stream_row").remove();
|
2013-11-22 01:12:53 +01:00
|
|
|
_.each(streams_data.streams, function (stream) {
|
|
|
|
streams_table.append(templates.render("admin_streams_list", {stream: stream}));
|
|
|
|
});
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($('#admin_page_streams_loading_indicator'));
|
2013-11-22 01:12:53 +01:00
|
|
|
}
|
2013-11-16 17:07:55 +01:00
|
|
|
|
2017-03-13 18:33:49 +01:00
|
|
|
exports.toggle_name_change_display = function () {
|
|
|
|
if ($('#full_name').attr('disabled')) {
|
|
|
|
$('#full_name').removeAttr('disabled');
|
|
|
|
} else {
|
|
|
|
$('#full_name').attr('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
$(".change_name_tooltip").toggle();
|
|
|
|
};
|
|
|
|
|
2017-03-04 06:39:45 +01:00
|
|
|
exports.toggle_email_change_display = function () {
|
|
|
|
$("#change_email").toggle();
|
|
|
|
$(".change_email_tooltip").toggle();
|
|
|
|
};
|
|
|
|
|
2017-03-18 20:19:44 +01:00
|
|
|
exports.update_realm_description = function (description) {
|
|
|
|
$('#id_realm_description').val(description);
|
|
|
|
};
|
|
|
|
|
2017-02-18 19:21:50 +01:00
|
|
|
exports.build_default_stream_table = function (streams_data) {
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.row_dict = new Dict();
|
|
|
|
|
|
|
|
function set_up_remove_click_hander(row, stream_name) {
|
|
|
|
row.on("click", ".remove-default-stream", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
channel.del({
|
|
|
|
url: '/json/default_streams'+ '?' + $.param({stream_name: stream_name}),
|
|
|
|
error: function (xhr) {
|
|
|
|
var button = row.find("button");
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
button.closest("td").html(
|
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
button.text(i18n.t("Failed!"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
row.remove();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
var table = $("#admin_default_streams_table").expectOne();
|
|
|
|
_.each(streams_data, function (stream) {
|
|
|
|
var row = $(templates.render("admin_default_streams_list", {stream: stream}));
|
|
|
|
set_up_remove_click_hander(row, stream.name);
|
|
|
|
self.row_dict.set(stream.stream_id, row);
|
|
|
|
table.append(row);
|
|
|
|
});
|
|
|
|
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
|
|
|
|
}());
|
|
|
|
|
2017-02-18 20:38:19 +01:00
|
|
|
self.remove = function (stream_id) {
|
|
|
|
if (self.row_dict.has(stream_id)) {
|
|
|
|
var row = self.row_dict.get(stream_id);
|
|
|
|
row.remove();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-18 19:21:50 +01:00
|
|
|
return self;
|
|
|
|
};
|
2017-02-18 20:38:19 +01:00
|
|
|
var default_stream_table;
|
|
|
|
|
|
|
|
exports.remove_default_stream = function (stream_id) {
|
|
|
|
if (default_stream_table) {
|
|
|
|
default_stream_table.remove(stream_id);
|
|
|
|
}
|
|
|
|
};
|
2016-05-20 22:08:42 +02:00
|
|
|
|
|
|
|
function get_non_default_streams_names(streams_data) {
|
|
|
|
var non_default_streams_names = [];
|
|
|
|
var default_streams_names = [];
|
|
|
|
|
|
|
|
_.each(page_params.realm_default_streams, function (default_stream) {
|
|
|
|
default_streams_names.push(default_stream.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(streams_data.streams, function (stream) {
|
|
|
|
if (default_streams_names.indexOf(stream.name) < 0) {
|
2016-07-28 06:17:31 +02:00
|
|
|
non_default_streams_names.push(stream.name);
|
2016-05-20 22:08:42 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return non_default_streams_names;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.update_default_streams_table = function () {
|
2016-12-03 01:12:52 +01:00
|
|
|
if (/#*administration/.test(window.location.hash) ||
|
|
|
|
/#*settings/.test(window.location.hash)) {
|
2016-08-09 20:36:29 +02:00
|
|
|
$("#admin_default_streams_table").expectOne().find("tr.default_stream_row").remove();
|
2017-02-18 20:38:19 +01:00
|
|
|
default_stream_table = exports.build_default_stream_table(
|
2017-02-18 19:21:50 +01:00
|
|
|
page_params.realm_default_streams);
|
2016-08-09 20:36:29 +02:00
|
|
|
}
|
2016-05-20 22:08:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function make_stream_default(stream_name) {
|
|
|
|
var data = {
|
2017-01-12 00:17:43 +01:00
|
|
|
stream_name: stream_name,
|
2016-05-20 22:08:42 +02:00
|
|
|
};
|
|
|
|
|
2016-12-31 08:31:34 +01:00
|
|
|
channel.post({
|
2016-05-20 22:08:42 +02:00
|
|
|
url: '/json/default_streams',
|
|
|
|
data: data,
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2016-05-20 22:08:42 +02:00
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
$(".active_stream_row button").closest("td").html(
|
2016-08-24 23:56:23 +02:00
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg));
|
2016-05-20 22:08:42 +02:00
|
|
|
} else {
|
2017-03-01 05:36:51 +01:00
|
|
|
$(".active_stream_row button").text(i18n.t("Failed!"));
|
2016-05-20 22:08:42 +02:00
|
|
|
}
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-05-20 22:08:42 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:03:48 +02:00
|
|
|
exports.populate_emoji = function (emoji_data) {
|
2017-01-31 02:12:11 +01:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-12 21:08:56 +01:00
|
|
|
var emoji_table = $('#admin_emoji_table').expectOne();
|
|
|
|
emoji_table.find('tr.emoji_row').remove();
|
2016-04-28 06:43:40 +02:00
|
|
|
_.each(emoji_data, function (data, name) {
|
2016-07-28 06:17:31 +02:00
|
|
|
emoji_table.append(templates.render('admin_emoji_list', {
|
|
|
|
emoji: {
|
|
|
|
name: name, source_url: data.source_url,
|
2016-12-20 13:18:26 +01:00
|
|
|
display_url: data.display_url,
|
2017-01-12 00:17:43 +01:00
|
|
|
author: data.author,
|
2017-02-21 21:34:13 +01:00
|
|
|
is_admin: page_params.is_admin,
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-07-28 06:17:31 +02:00
|
|
|
}));
|
2016-02-12 21:08:56 +01:00
|
|
|
});
|
|
|
|
loading.destroy_indicator($('#admin_page_emoji_loading_indicator'));
|
2016-05-03 00:03:48 +02:00
|
|
|
};
|
2016-02-12 21:08:56 +01:00
|
|
|
|
2016-02-13 19:17:15 +01:00
|
|
|
exports.populate_filters = function (filters_data) {
|
2017-01-31 02:12:11 +01:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-13 19:17:15 +01:00
|
|
|
var filters_table = $("#admin_filters_table").expectOne();
|
|
|
|
filters_table.find("tr.filter_row").remove();
|
|
|
|
_.each(filters_data, function (filter) {
|
|
|
|
filters_table.append(
|
|
|
|
templates.render(
|
|
|
|
"admin_filter_list", {
|
|
|
|
filter: {
|
|
|
|
pattern: filter[0],
|
|
|
|
url_format_string: filter[1],
|
2017-01-12 00:17:43 +01:00
|
|
|
id: filter[2],
|
|
|
|
},
|
2016-02-13 19:17:15 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
loading.destroy_indicator($('#admin_page_filters_loading_indicator'));
|
|
|
|
};
|
|
|
|
|
2017-03-31 22:40:48 +02:00
|
|
|
exports.populate_realm_domains = function (realm_domains) {
|
2017-01-31 02:12:11 +01:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-31 22:40:48 +02:00
|
|
|
var domains_list = _.map(realm_domains, function (realm_domain) {
|
|
|
|
return (realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain);
|
2016-12-26 19:19:02 +01:00
|
|
|
});
|
2017-01-17 01:19:05 +01:00
|
|
|
var domains = domains_list.join(', ');
|
2017-01-26 11:00:22 +01:00
|
|
|
|
|
|
|
$("#id_realm_restricted_to_domain").prop("checked", page_params.realm_restricted_to_domain);
|
2017-01-17 01:19:05 +01:00
|
|
|
if (domains.length === 0) {
|
|
|
|
domains = i18n.t("None");
|
2017-01-26 11:00:22 +01:00
|
|
|
$("#id_realm_restricted_to_domain").prop("disabled", true);
|
2017-01-17 01:19:05 +01:00
|
|
|
}
|
|
|
|
$("#realm_restricted_to_domains_label").text(i18n.t("New users restricted to the following domains: __domains__", {domains: domains}));
|
2016-12-26 19:19:02 +01:00
|
|
|
|
2017-03-31 22:40:48 +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) {
|
2017-03-31 23:38:16 +02:00
|
|
|
realm_domains_table_body.append(templates.render("admin-realm-domains-list", {realm_domain: realm_domain}));
|
2016-12-26 19:19:02 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-04 17:32:41 +02:00
|
|
|
exports.reset_realm_default_language = function () {
|
2017-01-31 02:12:11 +01:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-04 17:32:41 +02:00
|
|
|
$("#id_realm_default_language").val(page_params.realm_default_language);
|
|
|
|
};
|
|
|
|
|
2016-11-02 21:51:56 +01:00
|
|
|
exports.populate_auth_methods = function (auth_methods) {
|
2017-01-31 02:12:11 +01:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 21:51:56 +01:00
|
|
|
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,
|
2017-01-12 00:17:43 +01:00
|
|
|
enabled: auth_methods[key],
|
|
|
|
},
|
2016-11-02 21:51:56 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
loading.destroy_indicator($('#admin_page_auth_methods_loading_indicator'));
|
|
|
|
};
|
|
|
|
|
2016-11-30 10:42:58 +01:00
|
|
|
exports.update_message_retention_days = function () {
|
|
|
|
$("#id_realm_message_retention_days").val(page_params.message_retention_days);
|
|
|
|
};
|
|
|
|
|
2016-06-10 09:03:36 +02:00
|
|
|
function _setup_page() {
|
2015-08-20 02:38:32 +02:00
|
|
|
var options = {
|
2016-07-28 06:17:31 +02:00
|
|
|
realm_name: page_params.realm_name,
|
2017-03-18 20:19:44 +01:00
|
|
|
realm_description: page_params.realm_description,
|
2015-08-20 02:38:32 +02:00
|
|
|
realm_restricted_to_domain: page_params.realm_restricted_to_domain,
|
2016-07-28 06:17:31 +02:00
|
|
|
realm_invite_required: page_params.realm_invite_required,
|
2016-05-12 10:28:00 +02:00
|
|
|
realm_invite_by_admins_only: page_params.realm_invite_by_admins_only,
|
2017-03-13 14:42:03 +01:00
|
|
|
realm_inline_image_preview: page_params.realm_inline_image_preview,
|
|
|
|
server_inline_image_preview: page_params.server_inline_image_preview,
|
|
|
|
realm_inline_url_embed_preview: page_params.realm_inline_url_embed_preview,
|
|
|
|
server_inline_url_embed_preview: page_params.server_inline_url_embed_preview,
|
2016-11-02 21:51:56 +01:00
|
|
|
realm_authentication_methods: page_params.realm_authentication_methods,
|
2016-06-21 21:34:41 +02:00
|
|
|
realm_create_stream_by_admins_only: page_params.realm_create_stream_by_admins_only,
|
2017-03-13 18:33:49 +01:00
|
|
|
realm_name_changes_disabled: page_params.realm_name_changes_disabled,
|
2017-03-04 06:39:45 +01:00
|
|
|
realm_email_changes_disabled: page_params.realm_email_changes_disabled,
|
2016-12-20 15:41:30 +01:00
|
|
|
realm_add_emoji_by_admins_only: page_params.realm_add_emoji_by_admins_only,
|
2016-07-08 02:25:55 +02:00
|
|
|
realm_allow_message_editing: page_params.realm_allow_message_editing,
|
2016-12-02 15:16:33 +01:00
|
|
|
realm_message_content_edit_limit_minutes:
|
|
|
|
Math.ceil(page_params.realm_message_content_edit_limit_seconds / 60),
|
2016-11-30 10:42:58 +01:00
|
|
|
realm_message_retention_days: page_params.realm_message_retention_days,
|
2016-08-04 17:32:41 +02:00
|
|
|
language_list: page_params.language_list,
|
2016-11-29 08:57:35 +01:00
|
|
|
realm_default_language: page_params.realm_default_language,
|
2017-01-12 00:17:43 +01:00
|
|
|
realm_waiting_period_threshold: page_params.realm_waiting_period_threshold,
|
2017-02-21 21:34:13 +01:00
|
|
|
is_admin: page_params.is_admin,
|
2017-02-21 03:41:20 +01:00
|
|
|
realm_icon_source: page_params.realm_icon_source,
|
2017-02-26 20:35:23 +01:00
|
|
|
realm_icon_url: page_params.realm_icon_url,
|
2015-08-20 02:38:32 +02:00
|
|
|
};
|
2016-12-03 01:12:52 +01:00
|
|
|
|
2015-08-20 02:38:32 +02:00
|
|
|
var admin_tab = templates.render('admin_tab', options);
|
2016-12-03 01:12:52 +01:00
|
|
|
$("#settings_content .administration-box").html(admin_tab);
|
2017-03-23 20:37:08 +01:00
|
|
|
$("#settings_content .alert").removeClass("show");
|
2014-01-27 21:48:23 +01:00
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
var tab = (function () {
|
|
|
|
var tab = false;
|
|
|
|
var hash_sequence = window.location.hash.split(/\//);
|
|
|
|
if (/#*(administration)/.test(hash_sequence[0])) {
|
|
|
|
tab = hash_sequence[1];
|
|
|
|
return tab || "organization-settings";
|
|
|
|
}
|
|
|
|
return tab;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (tab) {
|
|
|
|
exports.launch_page(tab);
|
|
|
|
}
|
|
|
|
|
2017-02-21 19:10:50 +01:00
|
|
|
exports.show_or_hide_menu_item();
|
|
|
|
|
2016-08-04 17:32:41 +02:00
|
|
|
$("#id_realm_default_language").val(page_params.realm_default_language);
|
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
// create loading indicators
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.make_indicator($('#admin_page_users_loading_indicator'));
|
|
|
|
loading.make_indicator($('#admin_page_bots_loading_indicator'));
|
|
|
|
loading.make_indicator($('#admin_page_streams_loading_indicator'));
|
|
|
|
loading.make_indicator($('#admin_page_deactivated_users_loading_indicator'));
|
2016-02-12 21:08:56 +01:00
|
|
|
loading.make_indicator($('#admin_page_emoji_loading_indicator'));
|
2016-11-02 21:51:56 +01:00
|
|
|
loading.make_indicator($('#admin_page_auth_methods_loading_indicator'));
|
2016-02-13 19:17:15 +01:00
|
|
|
loading.make_indicator($('#admin_page_filters_loading_indicator'));
|
2013-11-22 01:12:53 +01:00
|
|
|
|
|
|
|
// Populate users and bots tables
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.get({
|
2013-11-16 17:07:55 +01:00
|
|
|
url: '/json/users',
|
2014-01-07 23:40:31 +01:00
|
|
|
idempotent: true,
|
2013-11-16 17:07:55 +01:00
|
|
|
timeout: 10*1000,
|
|
|
|
success: populate_users,
|
2017-01-12 00:17:43 +01:00
|
|
|
error: failed_listing_users,
|
2013-11-22 01:12:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Populate streams table
|
2014-01-24 19:47:18 +01:00
|
|
|
channel.get({
|
2016-05-20 22:08:42 +02:00
|
|
|
url: '/json/streams?include_public=true&include_subscribed=true&include_default=true',
|
2013-11-22 01:12:53 +01:00
|
|
|
timeout: 10*1000,
|
2014-01-07 23:40:31 +01:00
|
|
|
idempotent: true,
|
2013-11-22 01:12:53 +01:00
|
|
|
success: populate_streams,
|
2017-01-12 00:17:43 +01:00
|
|
|
error: failed_listing_streams,
|
2013-11-16 17:07:55 +01:00
|
|
|
});
|
2013-08-12 23:31:23 +02:00
|
|
|
|
2017-01-31 02:12:11 +01:00
|
|
|
// We set this flag before we're fully loaded so that the populate
|
|
|
|
// methods don't short-circuit.
|
|
|
|
meta.loaded = true;
|
|
|
|
|
2016-11-02 21:51:56 +01:00
|
|
|
// Populate authentication methods table
|
|
|
|
exports.populate_auth_methods(page_params.realm_authentication_methods);
|
|
|
|
|
2016-02-12 21:08:56 +01:00
|
|
|
// Populate emoji table
|
2016-05-03 00:03:48 +02:00
|
|
|
exports.populate_emoji(page_params.realm_emoji);
|
2016-05-20 22:08:42 +02:00
|
|
|
exports.update_default_streams_table();
|
2016-02-12 21:08:56 +01:00
|
|
|
|
2016-02-13 19:17:15 +01:00
|
|
|
// Populate filters table
|
|
|
|
exports.populate_filters(page_params.realm_filters);
|
|
|
|
|
2017-03-31 22:40:48 +02:00
|
|
|
// Populate realm domains
|
|
|
|
exports.populate_realm_domains(page_params.domains);
|
2016-12-26 19:19:02 +01:00
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
// Setup click handlers
|
2013-11-16 16:36:45 +01:00
|
|
|
$(".admin_user_table").on("click", ".deactivate", function (e) {
|
2013-08-12 23:31:23 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
2013-08-12 23:31:23 +02:00
|
|
|
|
2015-11-04 17:15:55 +01:00
|
|
|
var user_name = row.find('.user_name').text();
|
2016-11-15 12:37:02 +01:00
|
|
|
var email = get_email_for_user_row(row);
|
2013-08-12 23:31:23 +02:00
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
$("#deactivation_user_modal .email").text(email);
|
|
|
|
$("#deactivation_user_modal .user_name").text(user_name);
|
|
|
|
$("#deactivation_user_modal").modal("show");
|
2016-11-15 12:08:31 +01:00
|
|
|
|
2016-12-16 03:18:26 +01:00
|
|
|
meta.current_deactivate_user_modal_row = row;
|
2013-11-22 01:12:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(".admin_stream_table").on("click", ".deactivate", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
$(".active_stream_row").removeClass("active_stream_row");
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".stream_row");
|
|
|
|
row.addClass("active_stream_row");
|
2013-11-22 01:12:53 +01:00
|
|
|
|
2015-11-04 17:15:55 +01:00
|
|
|
var stream_name = row.find('.stream_name').text();
|
2013-11-22 01:12:53 +01:00
|
|
|
|
|
|
|
$("#deactivation_stream_modal .stream_name").text(stream_name);
|
|
|
|
$("#deactivation_stream_modal").modal("show");
|
2013-08-12 23:31:23 +02:00
|
|
|
});
|
|
|
|
|
2016-05-20 22:08:42 +02:00
|
|
|
$('.create_default_stream').keypress(function (e) {
|
|
|
|
if (e.which === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.create_default_stream').typeahead({
|
|
|
|
items: 5,
|
|
|
|
fixed: true,
|
2016-12-02 14:06:06 +01:00
|
|
|
source: function () {
|
2016-05-20 22:08:42 +02:00
|
|
|
return get_non_default_streams_names(all_streams);
|
|
|
|
},
|
|
|
|
highlight: true,
|
|
|
|
updater: function (stream_name) {
|
|
|
|
make_stream_default(stream_name);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-05-20 22:08:42 +02:00
|
|
|
});
|
|
|
|
|
2016-12-14 21:30:21 +01:00
|
|
|
$("#do_deactivate_user_button").expectOne().click(function () {
|
|
|
|
var email = meta.current_deactivate_user_modal_row.find(".email").text();
|
|
|
|
|
|
|
|
if ($("#deactivation_user_modal .email").html() !== email) {
|
|
|
|
blueslip.error("User deactivation canceled due to non-matching fields.");
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.message("Deactivation encountered an error. Please reload and try again.",
|
2016-12-14 21:30:21 +01:00
|
|
|
$("#home-error"), 'alert-error');
|
|
|
|
}
|
|
|
|
$("#deactivation_user_modal").modal("hide");
|
2017-03-01 05:36:51 +01:00
|
|
|
meta.current_deactivate_user_modal_row.find("button").eq(0).prop("disabled", true).text(i18n.t("Working…"));
|
2016-12-14 21:30:21 +01:00
|
|
|
channel.del({
|
2016-12-27 05:04:54 +01:00
|
|
|
url: '/json/users/' + encodeURIComponent(email),
|
2016-12-14 21:30:21 +01:00
|
|
|
error: function (xhr) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
meta.current_deactivate_user_modal_row.find("button").closest("td").html(
|
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
2017-03-01 05:36:51 +01:00
|
|
|
meta.current_deactivate_user_modal_row.find("button").text(i18n.t("Failed!"));
|
2016-12-14 21:30:21 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var button = meta.current_deactivate_user_modal_row.find("button.deactivate");
|
|
|
|
button.prop("disabled", false);
|
|
|
|
button.addClass("btn-warning reactivate").removeClass("btn-danger deactivate");
|
|
|
|
button.text(i18n.t("Reactivate"));
|
|
|
|
meta.current_deactivate_user_modal_row.addClass("deactivated_user");
|
2017-03-16 12:31:03 +01:00
|
|
|
meta.current_deactivate_user_modal_row.find('button.open-user-form').hide();
|
2016-12-14 21:30:21 +01:00
|
|
|
meta.current_deactivate_user_modal_row.find(".user-admin-settings").hide();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-12-14 21:30:21 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-28 17:40:30 +01:00
|
|
|
$(".admin_bot_table").on("click", ".deactivate", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
2015-10-28 17:40:30 +01:00
|
|
|
|
2016-11-15 12:37:02 +01:00
|
|
|
var email = get_email_for_user_row(row);
|
|
|
|
|
2015-10-28 17:40:30 +01:00
|
|
|
channel.del({
|
2016-12-27 05:04:54 +01:00
|
|
|
url: '/json/bots/' + encodeURIComponent(email),
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2015-10-28 17:40:30 +01:00
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
2015-11-04 17:15:55 +01:00
|
|
|
row.find("button").closest("td").html(
|
2016-08-24 23:56:23 +02:00
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
2015-10-28 17:40:30 +01:00
|
|
|
);
|
|
|
|
} else {
|
2017-03-01 05:36:51 +01:00
|
|
|
row.find("button").text(i18n.t("Failed!"));
|
2015-10-28 17:40:30 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
2017-03-16 12:31:03 +01:00
|
|
|
update_view_on_deactivate(row);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2015-10-28 17:40:30 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".admin_user_table, .admin_bot_table").on("click", ".reactivate", function (e) {
|
2013-11-16 16:26:40 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// Go up the tree until we find the user row, then grab the email element
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
2016-11-15 12:37:02 +01:00
|
|
|
var email = get_email_for_user_row(row);
|
2013-11-16 16:26:40 +01:00
|
|
|
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.post({
|
2016-12-27 05:04:54 +01:00
|
|
|
url: '/json/users/' + encodeURIComponent(email) + "/reactivate",
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2015-11-04 17:15:55 +01:00
|
|
|
var button = row.find("button");
|
2013-11-16 16:26:40 +01:00
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
2015-11-04 17:15:55 +01:00
|
|
|
button.closest("td").html(
|
2016-08-24 23:56:23 +02:00
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
2013-11-16 16:26:40 +01:00
|
|
|
);
|
|
|
|
} else {
|
2016-06-13 08:40:35 +02:00
|
|
|
button.text(i18n.t("Failed!"));
|
2013-11-16 16:26:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
2017-03-16 12:31:03 +01:00
|
|
|
update_view_on_reactivate(row);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2013-11-16 16:26:40 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-08-20 21:25:30 +02:00
|
|
|
$("#id_realm_invite_required").change(function () {
|
2016-06-09 22:47:12 +02:00
|
|
|
if (this.checked) {
|
2015-09-20 08:01:55 +02:00
|
|
|
$("#id_realm_invite_by_admins_only").removeAttr("disabled");
|
2016-09-14 02:20:13 +02:00
|
|
|
$("#id_realm_invite_by_admins_only_label").parent().removeClass("control-label-disabled");
|
2015-09-20 08:01:55 +02:00
|
|
|
} else {
|
|
|
|
$("#id_realm_invite_by_admins_only").attr("disabled", true);
|
2016-09-14 02:20:13 +02:00
|
|
|
$("#id_realm_invite_by_admins_only_label").parent().addClass("control-label-disabled");
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
2015-08-20 21:25:30 +02:00
|
|
|
});
|
|
|
|
|
2016-07-08 02:25:55 +02:00
|
|
|
$("#id_realm_allow_message_editing").change(function () {
|
|
|
|
if (this.checked) {
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes").removeAttr("disabled");
|
2016-09-14 02:20:13 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_minutes_label").parent().removeClass("control-label-disabled");
|
2016-07-08 02:25:55 +02:00
|
|
|
} else {
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes").attr("disabled", true);
|
2016-09-14 02:20:13 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_minutes_label").parent().addClass("control-label-disabled");
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-03-17 23:36:35 +01:00
|
|
|
$(".administration").on("submit", "form.admin-realm-form", function (e) {
|
2015-08-20 02:38:32 +02:00
|
|
|
var name_status = $("#admin-realm-name-status").expectOne();
|
2017-03-18 20:19:44 +01:00
|
|
|
var description_status = $("#admin-realm-description-status").expectOne();
|
2015-08-20 02:38:32 +02:00
|
|
|
var restricted_to_domain_status = $("#admin-realm-restricted-to-domain-status").expectOne();
|
|
|
|
var invite_required_status = $("#admin-realm-invite-required-status").expectOne();
|
2015-09-20 08:01:55 +02:00
|
|
|
var invite_by_admins_only_status = $("#admin-realm-invite-by-admins-only-status").expectOne();
|
2017-03-13 14:42:03 +01:00
|
|
|
var inline_image_preview_status = $("#admin-realm-inline-image-preview-status").expectOne();
|
|
|
|
var inline_url_embed_preview_status = $("#admin-realm-inline-url-embed-preview-status").expectOne();
|
2016-11-02 21:51:56 +01:00
|
|
|
var authentication_methods_status = $("#admin-realm-authentication-methods-status").expectOne();
|
2016-05-12 10:28:00 +02:00
|
|
|
var create_stream_by_admins_only_status = $("#admin-realm-create-stream-by-admins-only-status").expectOne();
|
2017-03-13 18:33:49 +01:00
|
|
|
var name_changes_disabled_status = $("#admin-realm-name-changes-disabled-status").expectOne();
|
2017-03-04 06:39:45 +01:00
|
|
|
var email_changes_disabled_status = $("#admin-realm-email-changes-disabled-status").expectOne();
|
2016-12-20 15:41:30 +01:00
|
|
|
var add_emoji_by_admins_only_status = $("#admin-realm-add-emoji-by-admins-only-status").expectOne();
|
2016-06-21 21:34:41 +02:00
|
|
|
var message_editing_status = $("#admin-realm-message-editing-status").expectOne();
|
2016-08-04 17:32:41 +02:00
|
|
|
var default_language_status = $("#admin-realm-default-language-status").expectOne();
|
2016-11-29 08:57:35 +01:00
|
|
|
var waiting_period_threshold_status = $("#admin-realm-waiting_period_threshold_status").expectOne();
|
2015-08-20 02:38:32 +02:00
|
|
|
name_status.hide();
|
2017-03-18 20:19:44 +01:00
|
|
|
description_status.hide();
|
2015-08-20 02:38:32 +02:00
|
|
|
restricted_to_domain_status.hide();
|
|
|
|
invite_required_status.hide();
|
2015-09-20 08:01:55 +02:00
|
|
|
invite_by_admins_only_status.hide();
|
2017-03-13 14:42:03 +01:00
|
|
|
inline_image_preview_status.hide();
|
|
|
|
inline_url_embed_preview_status.hide();
|
2016-11-02 21:51:56 +01:00
|
|
|
authentication_methods_status.hide();
|
2016-05-12 10:28:00 +02:00
|
|
|
create_stream_by_admins_only_status.hide();
|
2017-03-13 18:33:49 +01:00
|
|
|
name_changes_disabled_status.hide();
|
2017-03-04 06:39:45 +01:00
|
|
|
email_changes_disabled_status.hide();
|
2016-12-20 15:41:30 +01:00
|
|
|
add_emoji_by_admins_only_status.hide();
|
2016-06-21 21:34:41 +02:00
|
|
|
message_editing_status.hide();
|
2016-08-04 17:32:41 +02:00
|
|
|
default_language_status.hide();
|
2016-12-21 22:19:05 +01:00
|
|
|
waiting_period_threshold_status.hide();
|
2015-08-20 02:38:32 +02:00
|
|
|
|
2015-08-20 21:25:30 +02:00
|
|
|
e.preventDefault();
|
2014-02-03 20:14:18 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2015-08-20 02:38:32 +02:00
|
|
|
var new_name = $("#id_realm_name").val();
|
2017-03-18 20:19:44 +01:00
|
|
|
var new_description = $("#id_realm_description").val();
|
2015-08-20 02:38:32 +02:00
|
|
|
var new_restricted = $("#id_realm_restricted_to_domain").prop("checked");
|
|
|
|
var new_invite = $("#id_realm_invite_required").prop("checked");
|
2015-09-20 08:01:55 +02:00
|
|
|
var new_invite_by_admins_only = $("#id_realm_invite_by_admins_only").prop("checked");
|
2017-03-13 14:42:03 +01:00
|
|
|
var new_inline_image_preview = $("#id_realm_inline_image_preview").prop("checked");
|
|
|
|
var new_inline_url_embed_preview = $("#id_realm_inline_url_embed_preview").prop("checked");
|
2016-05-12 10:28:00 +02:00
|
|
|
var new_create_stream_by_admins_only = $("#id_realm_create_stream_by_admins_only").prop("checked");
|
2017-03-13 18:33:49 +01:00
|
|
|
var new_name_changes_disabled = $("#id_realm_name_changes_disabled").prop("checked");
|
2017-03-04 06:39:45 +01:00
|
|
|
var new_email_changes_disabled = $("#id_realm_email_changes_disabled").prop("checked");
|
2016-12-20 15:41:30 +01:00
|
|
|
var new_add_emoji_by_admins_only = $("#id_realm_add_emoji_by_admins_only").prop("checked");
|
2016-06-21 21:34:41 +02:00
|
|
|
var new_allow_message_editing = $("#id_realm_allow_message_editing").prop("checked");
|
2016-07-08 02:25:55 +02:00
|
|
|
var new_message_content_edit_limit_minutes = $("#id_realm_message_content_edit_limit_minutes").val();
|
2016-11-30 10:42:58 +01:00
|
|
|
var new_message_retention_days = $("#id_realm_message_retention_days").val();
|
2016-08-04 17:32:41 +02:00
|
|
|
var new_default_language = $("#id_realm_default_language").val();
|
2016-11-29 08:57:35 +01:00
|
|
|
var new_waiting_period_threshold = $("#id_realm_waiting_period_threshold").val();
|
2016-11-02 21:51:56 +01: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');
|
|
|
|
});
|
2016-07-08 02:25:55 +02:00
|
|
|
// If allow_message_editing is unchecked, message_content_edit_limit_minutes
|
|
|
|
// is irrelevant. Hence if allow_message_editing is unchecked, and
|
|
|
|
// message_content_edit_limit_minutes is poorly formed, we set the latter to
|
|
|
|
// a default value to prevent the server from returning an error.
|
|
|
|
if (!new_allow_message_editing) {
|
|
|
|
if ((parseInt(new_message_content_edit_limit_minutes, 10).toString() !==
|
|
|
|
new_message_content_edit_limit_minutes) ||
|
|
|
|
new_message_content_edit_limit_minutes < 0) {
|
2016-12-02 15:16:33 +01:00
|
|
|
// Realm.DEFAULT_MESSAGE_CONTENT_EDIT_LIMIT_SECONDS / 60
|
|
|
|
new_message_content_edit_limit_minutes = 10;
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-30 10:42:58 +01:00
|
|
|
if (parseInt(new_message_retention_days, 10).toString() !==
|
|
|
|
new_message_retention_days && new_message_retention_days !== "") {
|
|
|
|
new_message_retention_days = "";
|
|
|
|
}
|
2014-02-03 20:14:18 +01:00
|
|
|
|
|
|
|
var url = "/json/realm";
|
|
|
|
var data = {
|
2015-08-20 02:38:32 +02:00
|
|
|
name: JSON.stringify(new_name),
|
2017-03-18 20:19:44 +01:00
|
|
|
description: JSON.stringify(new_description),
|
2015-08-20 02:38:32 +02:00
|
|
|
restricted_to_domain: JSON.stringify(new_restricted),
|
2015-08-20 21:25:30 +02:00
|
|
|
invite_required: JSON.stringify(new_invite),
|
2016-05-12 10:28:00 +02:00
|
|
|
invite_by_admins_only: JSON.stringify(new_invite_by_admins_only),
|
2017-03-13 14:42:03 +01:00
|
|
|
inline_image_preview: JSON.stringify(new_inline_image_preview),
|
|
|
|
inline_url_embed_preview: JSON.stringify(new_inline_url_embed_preview),
|
2016-11-02 21:51:56 +01:00
|
|
|
authentication_methods: JSON.stringify(new_auth_methods),
|
2016-06-21 21:34:41 +02:00
|
|
|
create_stream_by_admins_only: JSON.stringify(new_create_stream_by_admins_only),
|
2017-03-13 18:33:49 +01:00
|
|
|
name_changes_disabled: JSON.stringify(new_name_changes_disabled),
|
2017-03-04 06:39:45 +01:00
|
|
|
email_changes_disabled: JSON.stringify(new_email_changes_disabled),
|
2016-12-20 15:41:30 +01:00
|
|
|
add_emoji_by_admins_only: JSON.stringify(new_add_emoji_by_admins_only),
|
2016-07-08 02:25:55 +02:00
|
|
|
allow_message_editing: JSON.stringify(new_allow_message_editing),
|
2016-12-02 15:16:33 +01:00
|
|
|
message_content_edit_limit_seconds:
|
|
|
|
JSON.stringify(parseInt(new_message_content_edit_limit_minutes, 10) * 60),
|
2016-11-30 10:42:58 +01:00
|
|
|
message_retention_days: new_message_retention_days !== "" ? JSON.stringify(parseInt(new_message_retention_days, 10)) : null,
|
2016-11-29 08:57:35 +01:00
|
|
|
default_language: JSON.stringify(new_default_language),
|
2017-01-12 00:17:43 +01:00
|
|
|
waiting_period_threshold: JSON.stringify(parseInt(new_waiting_period_threshold, 10)),
|
2014-02-03 20:14:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
2016-07-12 21:16:54 +02:00
|
|
|
success: function (response_data) {
|
|
|
|
if (response_data.name !== undefined) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Name changed!"), name_status);
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
2017-03-18 20:19:44 +01:00
|
|
|
if (response_data.description !== undefined) {
|
2017-03-20 15:39:28 +01:00
|
|
|
ui_report.success(i18n.t("Description changed!"), description_status);
|
2017-03-18 20:19:44 +01:00
|
|
|
}
|
2016-07-12 21:16:54 +02:00
|
|
|
if (response_data.restricted_to_domain !== undefined) {
|
|
|
|
if (response_data.restricted_to_domain) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("New user e-mails now restricted to certain domains!"), restricted_to_domain_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("New users may have arbitrary e-mails!"), restricted_to_domain_status);
|
2015-08-20 02:38:32 +02:00
|
|
|
}
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
2016-07-12 21:16:54 +02:00
|
|
|
if (response_data.invite_required !== undefined) {
|
|
|
|
if (response_data.invite_required) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("New users must be invited by e-mail!"), invite_required_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("New users may sign up online!"), invite_required_status);
|
2015-08-20 02:38:32 +02:00
|
|
|
}
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
2016-07-12 21:16:54 +02:00
|
|
|
if (response_data.invite_by_admins_only !== undefined) {
|
|
|
|
if (response_data.invite_by_admins_only) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("New users must be invited by an admin!"), invite_by_admins_only_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Any user may now invite new users!"), invite_by_admins_only_status);
|
2015-08-20 21:25:30 +02:00
|
|
|
}
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
2017-03-13 14:42:03 +01:00
|
|
|
if (response_data.inline_image_preview !== undefined) {
|
|
|
|
if (response_data.inline_image_preview) {
|
2017-03-22 14:53:19 +01:00
|
|
|
ui_report.success(i18n.t("Previews of uploaded and linked images will be shown!"), inline_image_preview_status);
|
2017-03-13 14:42:03 +01:00
|
|
|
} else {
|
2017-03-22 14:53:19 +01:00
|
|
|
ui_report.success(i18n.t("Previews of uploaded and linked images will not be shown!"), inline_image_preview_status);
|
2017-03-13 14:42:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (response_data.inline_url_embed_preview !== undefined) {
|
|
|
|
if (response_data.inline_url_embed_preview) {
|
2017-03-22 14:53:19 +01:00
|
|
|
ui_report.success(i18n.t("Previews for linked websites will be shown!"), inline_url_embed_preview_status);
|
2017-03-13 14:42:03 +01:00
|
|
|
} else {
|
2017-03-22 14:53:19 +01:00
|
|
|
ui_report.success(i18n.t("Previews for linked websites will not be shown!"), inline_url_embed_preview_status);
|
2017-03-13 14:42:03 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 21:16:54 +02:00
|
|
|
if (response_data.create_stream_by_admins_only !== undefined) {
|
|
|
|
if (response_data.create_stream_by_admins_only) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Only administrators may now create new streams!"), create_stream_by_admins_only_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Any user may now create new streams!"), create_stream_by_admins_only_status);
|
2016-05-12 10:28:00 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-13 18:33:49 +01:00
|
|
|
if (response_data.name_changes_disabled !== undefined) {
|
|
|
|
if (response_data.name_changes_disabled) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users cannot change their name!"), name_changes_disabled_status);
|
2017-03-13 18:33:49 +01:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users may now change their name!"), name_changes_disabled_status);
|
2017-03-13 18:33:49 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-04 06:39:45 +01:00
|
|
|
if (response_data.email_changes_disabled !== undefined) {
|
|
|
|
if (response_data.email_changes_disabled) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users cannot change their email!"), email_changes_disabled_status);
|
2017-03-04 06:39:45 +01:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users may now change their email!"), email_changes_disabled_status);
|
2017-03-04 06:39:45 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-20 15:41:30 +01:00
|
|
|
if (response_data.add_emoji_by_admins_only !== undefined) {
|
|
|
|
if (response_data.add_emoji_by_admins_only) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Only administrators may now add new emoji!"), add_emoji_by_admins_only_status);
|
2016-12-20 15:41:30 +01:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Any user may now add new emoji!"), add_emoji_by_admins_only_status);
|
2016-12-20 15:41:30 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 21:51:56 +01:00
|
|
|
if (response_data.authentication_methods !== undefined) {
|
|
|
|
if (response_data.authentication_methods) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Authentication methods saved!"), authentication_methods_status);
|
2016-11-02 21:51:56 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 21:16:54 +02:00
|
|
|
if (response_data.allow_message_editing !== undefined) {
|
2016-07-08 02:25:55 +02:00
|
|
|
// We expect message_content_edit_limit_seconds was sent in the
|
|
|
|
// response as well
|
2016-12-02 15:16:33 +01:00
|
|
|
var data_message_content_edit_limit_minutes =
|
|
|
|
Math.ceil(response_data.message_content_edit_limit_seconds / 60);
|
2016-07-12 21:16:54 +02:00
|
|
|
if (response_data.allow_message_editing) {
|
2016-07-08 02:25:55 +02:00
|
|
|
if (response_data.message_content_edit_limit_seconds > 0) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users can now edit topics for all their messages,"
|
2016-12-03 03:08:47 +01:00
|
|
|
+" and the content of messages which are less than __num_minutes__ minutes old.",
|
|
|
|
{num_minutes :
|
|
|
|
data_message_content_edit_limit_minutes}),
|
2016-07-08 02:25:55 +02:00
|
|
|
message_editing_status);
|
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users can now edit the content and topics of all their past messages!"), message_editing_status);
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
2016-06-21 21:34:41 +02:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Users can no longer edit their past messages!"), message_editing_status);
|
2016-06-21 21:34:41 +02:00
|
|
|
}
|
2016-07-08 02:25:55 +02:00
|
|
|
// message_content_edit_limit_seconds could have been changed earlier
|
|
|
|
// in this function, so update the field just in case
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes").val(data_message_content_edit_limit_minutes);
|
2016-06-21 21:34:41 +02:00
|
|
|
}
|
2016-08-04 17:32:41 +02:00
|
|
|
if (response_data.default_language !== undefined) {
|
|
|
|
if (response_data.default_language) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Default language changed!"), default_language_status);
|
2016-08-04 17:32:41 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-29 08:57:35 +01:00
|
|
|
if (response_data.waiting_period_threshold !== undefined) {
|
|
|
|
if (response_data.waiting_period_threshold > 0) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Waiting period threshold changed!"), waiting_period_threshold_status);
|
2016-11-29 08:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-23 08:34:11 +01:00
|
|
|
// Check if no changes made
|
|
|
|
var no_changes_made = true;
|
|
|
|
for (var key in response_data) {
|
|
|
|
if (['msg', 'result'].indexOf(key) < 0) {
|
|
|
|
no_changes_made = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (no_changes_made) {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("No changes to save!"), name_status);
|
2017-01-23 08:34:11 +01:00
|
|
|
}
|
2014-02-03 20:14:18 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2016-11-02 21:51:56 +01:00
|
|
|
var reason = $.parseJSON(xhr.responseText).reason;
|
|
|
|
if (reason === "no authentication") {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed!"), xhr, authentication_methods_status);
|
2016-11-02 21:51:56 +01:00
|
|
|
} else {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed!"), xhr, name_status);
|
2016-11-02 21:51:56 +01:00
|
|
|
}
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2014-02-03 20:14:18 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-14 21:51:09 +01:00
|
|
|
$(".admin_user_table").on("click", ".make-admin", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// Go up the tree until we find the user row, then grab the email element
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
2016-11-15 12:37:02 +01:00
|
|
|
var email = get_email_for_user_row(row);
|
2014-01-14 21:51:09 +01:00
|
|
|
|
2016-12-27 05:04:54 +01:00
|
|
|
var url = "/json/users/" + encodeURIComponent(email);
|
2014-01-14 21:51:09 +01:00
|
|
|
var data = {
|
2017-01-12 00:17:43 +01:00
|
|
|
is_admin: JSON.stringify(true),
|
2014-01-14 21:51:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
2015-11-04 17:15:55 +01:00
|
|
|
var button = row.find("button.make-admin");
|
2014-01-14 21:51:09 +01:00
|
|
|
button.addClass("btn-danger");
|
|
|
|
button.removeClass("btn-warning");
|
|
|
|
button.addClass("remove-admin");
|
|
|
|
button.removeClass("make-admin");
|
2016-06-13 08:40:35 +02:00
|
|
|
button.text(i18n.t("Remove admin"));
|
2014-01-14 21:51:09 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2015-11-04 17:15:55 +01:00
|
|
|
var status = row.find(".admin-user-status");
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed!"), xhr, status);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2014-01-14 21:51:09 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".admin_user_table").on("click", ".remove-admin", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// Go up the tree until we find the user row, then grab the email element
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
2016-11-15 12:37:02 +01:00
|
|
|
var email = get_email_for_user_row(row);
|
2014-01-14 21:51:09 +01:00
|
|
|
|
2016-12-27 05:04:54 +01:00
|
|
|
var url = "/json/users/" + encodeURIComponent(email);
|
2014-01-14 21:51:09 +01:00
|
|
|
var data = {
|
2017-01-12 00:17:43 +01:00
|
|
|
is_admin: JSON.stringify(false),
|
2014-01-14 21:51:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
2015-11-04 17:15:55 +01:00
|
|
|
var button = row.find("button.remove-admin");
|
2014-01-14 21:51:09 +01:00
|
|
|
button.addClass("btn-warning");
|
|
|
|
button.removeClass("btn-danger");
|
|
|
|
button.addClass("make-admin");
|
|
|
|
button.removeClass("remove-admin");
|
2016-06-13 08:40:35 +02:00
|
|
|
button.text(i18n.t("Make admin"));
|
2014-01-14 21:51:09 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2015-11-04 17:15:55 +01:00
|
|
|
var status = row.find(".admin-user-status");
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed!"), xhr, status);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2014-01-14 21:51:09 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-09-27 14:25:52 +02:00
|
|
|
$(".admin_user_table, .admin_bot_table").on("click", ".open-user-form", function (e) {
|
2017-02-25 08:49:12 +01:00
|
|
|
var users_list = people.get_realm_persons().filter(function (person) {
|
|
|
|
return !person.is_bot;
|
|
|
|
});
|
2017-02-15 00:45:38 +01:00
|
|
|
var user_id = $(e.currentTarget).attr("data-user-id");
|
|
|
|
var user_info = get_user_info(user_id);
|
2016-11-15 12:48:33 +01:00
|
|
|
var user_row = user_info.user_row;
|
|
|
|
var form_row = user_info.form_row;
|
2016-09-27 14:25:52 +02:00
|
|
|
var reset_button = form_row.find(".reset_edit_user");
|
|
|
|
var submit_button = form_row.find(".submit_name_changes");
|
|
|
|
var full_name = form_row.find("input[name='full_name']");
|
2017-02-25 08:49:12 +01:00
|
|
|
var owner_select = $(templates.render("bot_owner_select", {users_list: users_list}));
|
2016-09-27 14:25:52 +02:00
|
|
|
var admin_status = $('#administration-status').expectOne();
|
2017-02-15 00:45:38 +01:00
|
|
|
var person = people.get_person_from_user_id(user_id);
|
|
|
|
if (!person) {
|
|
|
|
return;
|
2017-03-21 13:34:45 +01:00
|
|
|
} else if (person.is_bot) {
|
|
|
|
// Dynamically add the owner select control in order to
|
|
|
|
// avoid performance issues in case of large number of users.
|
|
|
|
owner_select.val(bot_data.get(person.email).owner || "");
|
|
|
|
form_row.find(".edit_bot_owner_container").append(owner_select);
|
2017-02-15 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:25:52 +02:00
|
|
|
// Show user form.
|
|
|
|
user_row.hide();
|
|
|
|
form_row.show();
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
reset_button.on("click", function () {
|
2017-02-25 08:49:12 +01:00
|
|
|
owner_select.remove();
|
2016-09-27 14:25:52 +02:00
|
|
|
form_row.hide();
|
|
|
|
user_row.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
submit_button.on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2017-02-25 08:49:12 +01:00
|
|
|
var url = "/json/bots/" + encodeURIComponent(person.email);
|
2016-09-27 14:25:52 +02:00
|
|
|
var data = {
|
2017-02-25 08:49:12 +01:00
|
|
|
full_name: full_name.val(),
|
2016-09-27 14:25:52 +02:00
|
|
|
};
|
|
|
|
|
2017-02-25 08:49:12 +01:00
|
|
|
if (owner_select.val() !== undefined && owner_select.val() !== "") {
|
|
|
|
data.bot_owner = owner_select.val();
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:25:52 +02:00
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t('Updated successfully!'), admin_status);
|
2017-02-25 08:49:12 +01:00
|
|
|
},
|
|
|
|
error: function () {
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t('Update failed!'), admin_status);
|
2016-09-27 14:25:52 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$("#do_deactivate_stream_button").click(function () {
|
2013-11-22 01:12:53 +01:00
|
|
|
if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) {
|
|
|
|
blueslip.error("Stream deactivation canceled due to non-matching fields.");
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.message("Deactivation encountered an error. Please reload and try again.",
|
2013-11-22 01:12:53 +01:00
|
|
|
$("#home-error"), 'alert-error');
|
|
|
|
}
|
|
|
|
$("#deactivation_stream_modal").modal("hide");
|
2017-03-01 05:36:51 +01:00
|
|
|
$(".active_stream_row button").prop("disabled", true).text(i18n.t("Working…"));
|
2016-12-30 11:42:59 +01:00
|
|
|
var stream_name = $(".active_stream_row").find('.stream_name').text();
|
|
|
|
var stream_id = stream_data.get_sub(stream_name).stream_id;
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.del({
|
2016-12-30 11:42:59 +01:00
|
|
|
url: '/json/streams/' + stream_id,
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2013-11-22 01:12:53 +01:00
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
$(".active_stream_row button").closest("td").html(
|
2016-08-24 23:56:23 +02:00
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
2013-11-22 01:12:53 +01:00
|
|
|
);
|
|
|
|
} else {
|
2017-03-01 05:36:51 +01:00
|
|
|
$(".active_stream_row button").text(i18n.t("Failed!"));
|
2013-11-22 01:12:53 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var row = $(".active_stream_row");
|
|
|
|
row.remove();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2013-11-22 01:12:53 +01:00
|
|
|
});
|
|
|
|
});
|
2016-02-12 21:08:56 +01:00
|
|
|
|
|
|
|
$('.admin_emoji_table').on('click', '.delete', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var btn = $(this);
|
|
|
|
|
|
|
|
channel.del({
|
|
|
|
url: '/json/realm/emoji/' + encodeURIComponent(btn.attr('data-emoji-name')),
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2016-02-12 21:08:56 +01:00
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
btn.closest("td").html(
|
2016-08-24 23:56:23 +02:00
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
2016-02-12 21:08:56 +01:00
|
|
|
);
|
|
|
|
} else {
|
2017-03-01 05:36:51 +01:00
|
|
|
btn.text(i18n.t("Failed!"));
|
2016-02-12 21:08:56 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var row = btn.parents('tr');
|
|
|
|
row.remove();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-02-12 21:08:56 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".administration").on("submit", "form.admin-emoji-form", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var emoji_status = $('#admin-emoji-status');
|
|
|
|
var emoji = {};
|
2016-12-05 07:53:36 +01:00
|
|
|
_.each($(this).serializeArray(), function (obj) {
|
|
|
|
emoji[obj.name] = obj.value;
|
|
|
|
});
|
2016-02-12 21:08:56 +01:00
|
|
|
|
|
|
|
channel.put({
|
2017-01-17 09:20:37 +01:00
|
|
|
url: "/json/realm/emoji/" + encodeURIComponent(emoji.name),
|
2016-02-12 21:08:56 +01:00
|
|
|
data: $(this).serialize(),
|
|
|
|
success: function () {
|
2016-09-14 00:56:36 +02:00
|
|
|
$('#admin-emoji-status').hide();
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Custom emoji added!"), emoji_status);
|
2016-10-25 21:12:54 +02:00
|
|
|
$("form.admin-emoji-form input[type='text']").val("");
|
2016-02-12 21:08:56 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2016-09-14 00:56:36 +02:00
|
|
|
$('#admin-emoji-status').hide();
|
2016-08-24 23:56:23 +02:00
|
|
|
var errors = JSON.parse(xhr.responseText).msg;
|
2016-09-14 00:56:36 +02:00
|
|
|
xhr.responseText = JSON.stringify({msg: errors});
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed!"), xhr, emoji_status);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-02-12 21:08:56 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-13 19:17:15 +01:00
|
|
|
$('.admin_filters_table').on('click', '.delete', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var btn = $(this);
|
|
|
|
|
|
|
|
channel.del({
|
|
|
|
url: '/json/realm/filters/' + encodeURIComponent(btn.attr('data-filter-id')),
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2016-02-13 19:17:15 +01:00
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
btn.closest("td").html(
|
|
|
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
2017-03-01 05:36:51 +01:00
|
|
|
btn.text(i18n.t("Failed!"));
|
2016-02-13 19:17:15 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var row = btn.parents('tr');
|
|
|
|
row.remove();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-02-13 19:17:15 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".administration").on("submit", "form.admin-filter-form", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var filter_status = $('#admin-filter-status');
|
|
|
|
var pattern_status = $('#admin-filter-pattern-status');
|
|
|
|
var format_status = $('#admin-filter-format-status');
|
|
|
|
filter_status.hide();
|
|
|
|
pattern_status.hide();
|
|
|
|
format_status.hide();
|
|
|
|
var filter = {};
|
2016-12-05 07:53:36 +01:00
|
|
|
_.each($(this).serializeArray(), function (obj) {
|
|
|
|
filter[obj.name] = obj.value;
|
|
|
|
});
|
2016-02-13 19:17:15 +01:00
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: "/json/realm/filters",
|
|
|
|
data: $(this).serialize(),
|
|
|
|
success: function (data) {
|
|
|
|
filter.id = data.id;
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.success(i18n.t("Custom filter added!"), filter_status);
|
2016-02-13 19:17:15 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function (xhr) {
|
2016-02-13 19:17:15 +01:00
|
|
|
var errors = $.parseJSON(xhr.responseText).errors;
|
|
|
|
if (errors.pattern !== undefined) {
|
|
|
|
xhr.responseText = JSON.stringify({msg: errors.pattern});
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, pattern_status);
|
2016-02-13 19:17:15 +01:00
|
|
|
}
|
|
|
|
if (errors.url_format_string !== undefined) {
|
|
|
|
xhr.responseText = JSON.stringify({msg: errors.url_format_string});
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, format_status);
|
2016-02-13 19:17:15 +01:00
|
|
|
}
|
|
|
|
if (errors.__all__ !== undefined) {
|
|
|
|
xhr.responseText = JSON.stringify({msg: errors.__all__});
|
2017-03-18 21:17:41 +01:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, filter_status);
|
2016-02-13 19:17:15 +01:00
|
|
|
}
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-02-13 19:17:15 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-31 22:40:48 +02:00
|
|
|
$("#realm_domains_table").on("click", ".delete_realm_domain", function () {
|
2017-01-21 09:09:27 +01:00
|
|
|
var domain = $(this).parents("tr").find(".domain").text();
|
|
|
|
var url = "/json/realm/domains/" + domain;
|
2017-03-31 22:40:48 +02:00
|
|
|
var realm_domains_info = $("#realm_domains_modal").find(".realm_domains_info");
|
2016-12-26 19:19:02 +01:00
|
|
|
|
|
|
|
channel.del({
|
|
|
|
url: url,
|
|
|
|
success: function () {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.removeClass("text-error");
|
|
|
|
realm_domains_info.addClass("text-success");
|
|
|
|
realm_domains_info.text(i18n.t("Deleted successfully!"));
|
2016-12-26 19:19:02 +01:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.removeClass("text-success");
|
|
|
|
realm_domains_info.addClass("text-error");
|
|
|
|
realm_domains_info.text(JSON.parse(xhr.responseText).msg);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-12-26 19:19:02 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-31 22:40:48 +02:00
|
|
|
$("#submit-add-realm-domain").click(function () {
|
|
|
|
var realm_domains_info = $("#realm_domains_modal").find(".realm_domains_info");
|
|
|
|
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");
|
2016-12-26 19:19:02 +01:00
|
|
|
var data = {
|
2017-03-31 22:40:48 +02:00
|
|
|
domain: JSON.stringify(domain),
|
|
|
|
allow_subdomains: JSON.stringify(allow_subdomains),
|
2016-12-26 19:19:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: "/json/realm/domains",
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
2017-03-31 22:40:48 +02:00
|
|
|
$("#add-realm-domain-widget .new-realm-domain").val("");
|
|
|
|
$("#add-realm-domain-widget .new-realm-domain-allow-subdomains").prop("checked", false);
|
2017-01-26 11:00:22 +01:00
|
|
|
$("#id_realm_restricted_to_domain").prop("disabled", false);
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.removeClass("text-error");
|
|
|
|
realm_domains_info.addClass("text-success");
|
|
|
|
realm_domains_info.text(i18n.t("Added successfully!"));
|
2016-12-26 19:19:02 +01:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.removeClass("text-success");
|
|
|
|
realm_domains_info.addClass("text-error");
|
|
|
|
realm_domains_info.text(JSON.parse(xhr.responseText).msg);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-12-26 19:19:02 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-31 22:40:48 +02:00
|
|
|
$("#realm_domains_table").on("change", ".allow-subdomains", function (e) {
|
2017-01-21 08:19:03 +01:00
|
|
|
e.stopPropagation();
|
2017-03-31 22:40:48 +02:00
|
|
|
var realm_domains_info = $("#realm_domains_modal").find(".realm_domains_info");
|
2017-01-21 08:19:03 +01: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 () {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.removeClass("text-error");
|
|
|
|
realm_domains_info.addClass("text-success");
|
2017-01-21 08:19:03 +01:00
|
|
|
if (allow_subdomains) {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.text(i18n.t("Update successful: Subdomains allowed for __domain__",
|
2017-01-21 08:19:03 +01:00
|
|
|
{domain: domain}));
|
|
|
|
} else {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.text(i18n.t("Update successful: Subdomains no longer allowed for __domain__",
|
2017-01-21 08:19:03 +01:00
|
|
|
{domain: domain}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-03-31 22:40:48 +02:00
|
|
|
realm_domains_info.removeClass("text-success");
|
|
|
|
realm_domains_info.addClass("text-error");
|
|
|
|
realm_domains_info.text(JSON.parse(xhr.responseText).msg);
|
2017-01-21 08:19:03 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-21 03:41:20 +01: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) {
|
|
|
|
form_data.append('file-'+i, file);
|
|
|
|
});
|
|
|
|
|
|
|
|
var spinner = $("#upload_icon_spinner").expectOne();
|
|
|
|
loading.make_indicator(spinner, {text: i18n.t("Uploading icon.")});
|
|
|
|
|
|
|
|
channel.put({
|
|
|
|
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);
|
|
|
|
|
2016-06-10 09:03:36 +02:00
|
|
|
}
|
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
exports.launch_page = function (tab) {
|
|
|
|
var $active_tab = $("#settings_overlay_container li[data-section='" + tab + "']");
|
|
|
|
|
|
|
|
if ($active_tab.hasClass("admin")) {
|
2017-02-21 19:10:50 +01:00
|
|
|
$(".sidebar .ind-tab[data-tab-key='administration']").click();
|
2016-12-03 01:12:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#settings_overlay_container").addClass("show");
|
|
|
|
$active_tab.click();
|
|
|
|
};
|
|
|
|
|
2016-06-10 09:03:36 +02:00
|
|
|
exports.setup_page = function () {
|
|
|
|
i18n.ensure_i18n(_setup_page);
|
2013-08-12 23:31:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = admin;
|
|
|
|
}
|