2013-08-12 23:31:23 +02:00
|
|
|
var admin = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
function failed_listing_users(xhr, error) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($('#subs_page_loading_indicator'));
|
2013-11-22 01:12:53 +01:00
|
|
|
ui.report_error("Error listing users or bots", xhr, $("#administration-status"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function failed_listing_streams(xhr, error) {
|
|
|
|
ui.report_error("Error listing streams", xhr, $("#administration-status"));
|
|
|
|
}
|
|
|
|
|
2016-02-12 21:08:56 +01:00
|
|
|
function failed_listing_emoji(xhr, error) {
|
|
|
|
ui.report_error("Error listing emoji", xhr, $("#administration-status"));
|
|
|
|
}
|
|
|
|
|
2013-11-16 17:07:55 +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');
|
|
|
|
|
2013-11-16 16:36:45 +01:00
|
|
|
_.each(bots, function (user) {
|
|
|
|
bots_table.append(templates.render("admin_user_list", {user: user}));
|
|
|
|
});
|
2013-11-16 17:07:55 +01:00
|
|
|
_.each(active_users, function (user) {
|
2013-11-16 16:36:45 +01:00
|
|
|
users_table.append(templates.render("admin_user_list", {user: user}));
|
2013-11-15 20:34:23 +01:00
|
|
|
});
|
2013-11-16 17:07:55 +01:00
|
|
|
_.each(deactivated_users, function (user) {
|
|
|
|
deactivated_users_table.append(templates.render("admin_user_list", {user: user}));
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
function populate_streams (streams_data) {
|
2013-12-10 23:12:16 +01:00
|
|
|
var streams_table = $("#admin_streams_table").expectOne();
|
|
|
|
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
|
|
|
|
2016-05-03 00:03:48 +02:00
|
|
|
exports.populate_emoji = function (emoji_data) {
|
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) {
|
|
|
|
emoji_table.append(templates.render('admin_emoji_list', {emoji: {name: name, source_url: data.source_url,
|
|
|
|
display_url: data.display_url}}));
|
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
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
exports.setup_page = function () {
|
2015-08-20 02:38:32 +02:00
|
|
|
var options = {
|
|
|
|
realm_name: page_params.realm_name,
|
|
|
|
domain: page_params.domain,
|
|
|
|
realm_restricted_to_domain: page_params.realm_restricted_to_domain,
|
2015-08-20 21:25:30 +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,
|
|
|
|
realm_create_stream_by_admins_only: page_params.realm_create_stream_by_admins_only
|
2015-08-20 02:38:32 +02:00
|
|
|
};
|
|
|
|
var admin_tab = templates.render('admin_tab', options);
|
2014-01-27 21:48:23 +01:00
|
|
|
$("#administration").html(admin_tab);
|
2015-09-20 07:54:03 +02:00
|
|
|
$("#administration-status").expectOne().hide();
|
|
|
|
$("#admin-realm-name-status").expectOne().hide();
|
|
|
|
$("#admin-realm-restricted-to-domain-status").expectOne().hide();
|
|
|
|
$("#admin-realm-invite-required-status").expectOne().hide();
|
|
|
|
$("#admin-realm-invite-by-admins-only-status").expectOne().hide();
|
2016-05-12 10:28:00 +02:00
|
|
|
$("#admin-realm-create-stream-by-admins-only-status").expectOne().hide();
|
2016-02-12 21:08:56 +01:00
|
|
|
$("#admin-emoji-status").expectOne().hide();
|
|
|
|
$("#admin-emoji-name-status").expectOne().hide();
|
|
|
|
$("#admin-emoji-url-status").expectOne().hide();
|
2014-01-27 21:48:23 +01:00
|
|
|
|
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'));
|
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,
|
2013-11-22 01:12:53 +01:00
|
|
|
error: failed_listing_users
|
|
|
|
});
|
|
|
|
|
|
|
|
// Populate streams table
|
2014-01-24 19:47:18 +01:00
|
|
|
channel.get({
|
|
|
|
url: '/json/streams?include_public=true&include_subscribed=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,
|
|
|
|
error: failed_listing_streams
|
2013-11-16 17:07:55 +01:00
|
|
|
});
|
2013-08-12 23:31:23 +02:00
|
|
|
|
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-02-12 21:08:56 +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();
|
|
|
|
|
|
|
|
$(".active_user_row").removeClass("active_user_row");
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
|
|
|
row.addClass("active_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();
|
|
|
|
var email = row.find('.email').text();
|
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");
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".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
|
|
|
});
|
|
|
|
|
2015-10-28 17:40:30 +01:00
|
|
|
$(".admin_bot_table").on("click", ".deactivate", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
$(".active_user_row").removeClass("active_user_row");
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
|
|
|
row.addClass("active_user_row");
|
2015-10-28 17:40:30 +01:00
|
|
|
|
2015-11-04 17:15:55 +01:00
|
|
|
var user_name = row.find('.user_name').text();
|
|
|
|
var email = row.find('.email').text();
|
2015-10-28 17:40:30 +01:00
|
|
|
channel.del({
|
|
|
|
url: '/json/bots/' + email,
|
|
|
|
error: function (xhr, error_type) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
2015-11-04 17:15:55 +01:00
|
|
|
row.find("button").closest("td").html(
|
2015-10-28 17:40:30 +01:00
|
|
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
2015-11-04 17:15:55 +01:00
|
|
|
row.find("button").text("Failed!");
|
2015-10-28 17:40:30 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
2015-11-04 17:15:55 +01:00
|
|
|
var button = row.find("button.deactivate");
|
2015-10-28 17:40:30 +01:00
|
|
|
button.addClass("btn-warning");
|
|
|
|
button.removeClass("btn-danger");
|
|
|
|
button.addClass("reactivate");
|
|
|
|
button.removeClass("deactivate");
|
|
|
|
button.text("Reactivate");
|
|
|
|
row.addClass("deactivated_user");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".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
|
2014-01-17 21:13:52 +01:00
|
|
|
$(".active_user_row").removeClass("active_user_row");
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
|
|
|
row.addClass("active_user_row");
|
2013-11-16 16:26:40 +01:00
|
|
|
|
2015-11-04 17:15:55 +01:00
|
|
|
var email = row.find('.email').text();
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.post({
|
2015-10-28 17:40:30 +01:00
|
|
|
url: '/json/users/' + email + "/reactivate",
|
2013-11-16 16:26:40 +01:00
|
|
|
error: function (xhr, error_type) {
|
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(
|
2013-11-16 16:26:40 +01:00
|
|
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
2015-11-04 17:15:55 +01:00
|
|
|
button.text("Failed!");
|
2013-11-16 16:26:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
2015-11-04 17:15:55 +01:00
|
|
|
var button = row.find("button.reactivate");
|
2013-11-16 16:26:40 +01:00
|
|
|
button.addClass("btn-danger");
|
|
|
|
button.removeClass("btn-warning");
|
|
|
|
button.addClass("deactivate");
|
|
|
|
button.removeClass("reactivate");
|
|
|
|
button.text("Deactivate");
|
2014-01-17 21:07:54 +01:00
|
|
|
row.removeClass("deactivated_user");
|
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");
|
|
|
|
$("#id_realm_invite_by_admins_only_label").removeClass("control-label-disabled");
|
|
|
|
} else {
|
|
|
|
$("#id_realm_invite_by_admins_only").attr("disabled", true);
|
|
|
|
$("#id_realm_invite_by_admins_only_label").addClass("control-label-disabled");
|
|
|
|
}
|
2015-08-20 21:25:30 +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();
|
|
|
|
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();
|
2016-05-12 10:28:00 +02:00
|
|
|
var create_stream_by_admins_only_status = $("#admin-realm-create-stream-by-admins-only-status").expectOne();
|
2015-08-20 02:38:32 +02:00
|
|
|
name_status.hide();
|
|
|
|
restricted_to_domain_status.hide();
|
|
|
|
invite_required_status.hide();
|
2015-09-20 08:01:55 +02:00
|
|
|
invite_by_admins_only_status.hide();
|
2016-05-12 10:28:00 +02:00
|
|
|
create_stream_by_admins_only_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();
|
|
|
|
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");
|
2016-05-12 10:28:00 +02:00
|
|
|
var new_create_stream_by_admins_only = $("#id_realm_create_stream_by_admins_only").prop("checked");
|
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),
|
|
|
|
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),
|
|
|
|
create_stream_by_admins_only: JSON.stringify(new_create_stream_by_admins_only)
|
2014-02-03 20:14:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
2015-08-20 02:38:32 +02:00
|
|
|
success: function (data) {
|
2015-09-20 08:01:55 +02:00
|
|
|
if (data.name !== undefined) {
|
|
|
|
ui.report_success("Name changed!", name_status);
|
|
|
|
}
|
2015-08-20 02:38:32 +02:00
|
|
|
if (data.restricted_to_domain !== undefined) {
|
|
|
|
if (data.restricted_to_domain) {
|
|
|
|
ui.report_success("New users must have @" + page_params.domain + " e-mails!", restricted_to_domain_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2015-08-20 02:38:32 +02:00
|
|
|
ui.report_success("New users may have arbitrary e-mails!", restricted_to_domain_status);
|
|
|
|
}
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
|
|
|
if (data.invite_required !== undefined) {
|
2015-08-20 02:38:32 +02:00
|
|
|
if (data.invite_required) {
|
2015-08-20 21:25:30 +02:00
|
|
|
ui.report_success("New users must be invited by e-mail!", invite_required_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2015-08-20 02:38:32 +02:00
|
|
|
ui.report_success("New users may sign up online!", invite_required_status);
|
|
|
|
}
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
|
|
|
if (data.invite_by_admins_only !== undefined) {
|
2015-08-20 21:25:30 +02:00
|
|
|
if (data.invite_by_admins_only) {
|
|
|
|
ui.report_success("New users must be invited by an admin!", invite_by_admins_only_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2015-08-20 21:25:30 +02:00
|
|
|
ui.report_success("Any user may now invite new users!", invite_by_admins_only_status);
|
|
|
|
}
|
2015-09-20 08:01:55 +02:00
|
|
|
}
|
2016-05-12 10:28:00 +02:00
|
|
|
if (data.create_stream_by_admins_only !== undefined) {
|
|
|
|
if (data.create_stream_by_admins_only) {
|
|
|
|
ui.report_success("Only Admins may now create new streams!", create_stream_by_admins_only_status);
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2016-05-12 10:28:00 +02:00
|
|
|
ui.report_success("Any user may now create new streams!", create_stream_by_admins_only_status);
|
|
|
|
}
|
|
|
|
}
|
2014-02-03 20:14:18 +01:00
|
|
|
},
|
|
|
|
error: function (xhr, error) {
|
2015-08-20 02:38:32 +02:00
|
|
|
ui.report_error("Failed!", xhr, name_status);
|
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
|
|
|
|
$(".active_user_row").removeClass("active_user_row");
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
|
|
|
row.addClass("active_user_row");
|
|
|
|
var email = row.find('.email').text();
|
2014-01-14 21:51:09 +01:00
|
|
|
|
|
|
|
var url = "/json/users/" + email;
|
|
|
|
var data = {
|
|
|
|
is_admin: JSON.stringify(true)
|
|
|
|
};
|
|
|
|
|
|
|
|
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");
|
|
|
|
button.text("Remove admin");
|
|
|
|
},
|
|
|
|
error: function (xhr, error) {
|
2015-11-04 17:15:55 +01:00
|
|
|
var status = row.find(".admin-user-status");
|
2014-01-14 21:51:09 +01:00
|
|
|
ui.report_error("Failed!", xhr, status);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".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
|
|
|
|
$(".active_user_row").removeClass("active_user_row");
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(e.target).closest(".user_row");
|
|
|
|
row.addClass("active_user_row");
|
|
|
|
var email = row.find('.email').text();
|
2014-01-14 21:51:09 +01:00
|
|
|
|
|
|
|
var url = "/json/users/" + email;
|
|
|
|
var data = {
|
|
|
|
is_admin: JSON.stringify(false)
|
|
|
|
};
|
|
|
|
|
|
|
|
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");
|
|
|
|
button.text("Make admin");
|
|
|
|
},
|
|
|
|
error: function (xhr, error) {
|
2015-11-04 17:15:55 +01:00
|
|
|
var status = row.find(".admin-user-status");
|
2014-01-14 21:51:09 +01:00
|
|
|
ui.report_error("Failed!", xhr, status);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
$("#do_deactivate_user_button").click(function (e) {
|
2015-11-04 17:15:55 +01:00
|
|
|
var row = $(".active_user_row");
|
|
|
|
var email = row.find(".email").text();
|
|
|
|
if ($("#deactivation_user_modal .email").html() !== email) {
|
2013-08-12 23:31:23 +02:00
|
|
|
blueslip.error("User deactivation canceled due to non-matching fields.");
|
|
|
|
ui.report_message("Deactivation encountered an error. Please reload and try again.",
|
|
|
|
$("#home-error"), 'alert-error');
|
|
|
|
}
|
2013-11-22 01:12:53 +01:00
|
|
|
$("#deactivation_user_modal").modal("hide");
|
2015-11-04 17:15:55 +01:00
|
|
|
row.find("button").prop("disabled", true).text("Working…");
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.del({
|
2015-11-04 17:15:55 +01:00
|
|
|
url: '/json/users/' + email,
|
2013-08-12 23:31:23 +02:00
|
|
|
error: function (xhr, error_type) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
2015-11-04 17:15:55 +01:00
|
|
|
row.find("button").closest("td").html(
|
2013-08-12 23:31:23 +02:00
|
|
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
2015-11-04 17:15:55 +01:00
|
|
|
row.find("button").text("Failed!");
|
2013-08-12 23:31:23 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
2015-11-04 17:15:55 +01:00
|
|
|
var button = row.find("button.deactivate");
|
2013-11-16 16:26:40 +01:00
|
|
|
button.prop("disabled", false);
|
|
|
|
button.addClass("btn-warning");
|
|
|
|
button.removeClass("btn-danger");
|
|
|
|
button.addClass("reactivate");
|
|
|
|
button.removeClass("deactivate");
|
|
|
|
button.text("Reactivate");
|
2014-01-17 21:07:54 +01:00
|
|
|
row.addClass("deactivated_user");
|
2014-01-17 20:53:14 +01:00
|
|
|
row.find(".user-admin-settings").hide();
|
2013-08-12 23:31:23 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-11-22 01:12:53 +01:00
|
|
|
$("#do_deactivate_stream_button").click(function (e) {
|
|
|
|
if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) {
|
|
|
|
blueslip.error("Stream deactivation canceled due to non-matching fields.");
|
|
|
|
ui.report_message("Deactivation encountered an error. Please reload and try again.",
|
|
|
|
$("#home-error"), 'alert-error');
|
|
|
|
}
|
|
|
|
$("#deactivation_stream_modal").modal("hide");
|
|
|
|
$(".active_stream_row button").prop("disabled", true).text("Working…");
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.del({
|
2013-11-22 01:12:53 +01:00
|
|
|
url: '/json/streams/' + encodeURIComponent($(".active_stream_row").find('.stream_name').text()),
|
|
|
|
error: function (xhr, error_type) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
$(".active_stream_row button").closest("td").html(
|
|
|
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$(".active_stream_row button").text("Failed!");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var row = $(".active_stream_row");
|
|
|
|
row.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
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')),
|
|
|
|
error: function (xhr, error_type) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
btn.closest("td").html(
|
|
|
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
btn.text("Failed!");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var row = btn.parents('tr');
|
|
|
|
row.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".administration").on("submit", "form.admin-emoji-form", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var emoji_status = $('#admin-emoji-status');
|
|
|
|
var emoji_name_status = $('#admin-emoji-name-status');
|
|
|
|
var emoji_url_status = $('#admin-emoji-url-status');
|
|
|
|
var emoji_table = $('.admin_emoji_table');
|
|
|
|
var emoji = {};
|
|
|
|
$(this).serializeArray().map(function (x){emoji[x.name] = x.value;});
|
|
|
|
|
|
|
|
channel.put({
|
|
|
|
url: "/json/realm/emoji",
|
|
|
|
data: $(this).serialize(),
|
|
|
|
success: function () {
|
|
|
|
$('#admin-emoji-status, #admin-emoji-name-status, #admin-emoji-url-status').hide();
|
|
|
|
ui.report_success("Custom emoji added!", emoji_status);
|
|
|
|
},
|
|
|
|
error: function (xhr, error) {
|
|
|
|
$('#admin-emoji-status, #admin-emoji-name-status, #admin-emoji-url-status').hide();
|
|
|
|
var errors = $.parseJSON(xhr.responseText).msg;
|
|
|
|
if (errors.name !== undefined) {
|
|
|
|
xhr.responseText = JSON.stringify({msg: errors.name});
|
|
|
|
ui.report_error("Failed!", xhr, emoji_name_status);
|
|
|
|
}
|
|
|
|
if (errors.img_url !== undefined) {
|
|
|
|
xhr.responseText = JSON.stringify({msg: errors.img_url});
|
|
|
|
ui.report_error("Failed!", xhr, emoji_url_status);
|
|
|
|
}
|
|
|
|
if (errors.__all__ !== undefined) {
|
|
|
|
xhr.responseText = JSON.stringify({msg: errors.__all__});
|
|
|
|
ui.report_error("Failed!", xhr, emoji_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-12 23:31:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|