2019-07-09 21:24:00 +02:00
|
|
|
var render_admin_user_list = require("../templates/admin_user_list.hbs");
|
|
|
|
var render_bot_owner_select = require("../templates/bot_owner_select.hbs");
|
|
|
|
var render_user_info_form_modal = require('../templates/user_info_form_modal.hbs');
|
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
var settings_users = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var meta = {
|
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2017-04-17 16:51:27 +02:00
|
|
|
exports.reset = function () {
|
|
|
|
meta.loaded = false;
|
|
|
|
};
|
|
|
|
|
2019-08-16 06:02:53 +02:00
|
|
|
function compare_a_b(a, b) {
|
|
|
|
if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else if (a === b) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-07-14 12:43:04 +02:00
|
|
|
function get_user_info_row(user_id) {
|
|
|
|
return $("tr.user_row[data-user-id='" + user_id + "']");
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-18 11:07:51 +01:00
|
|
|
function update_view_on_deactivate(row) {
|
2017-04-08 20:08:35 +02:00
|
|
|
var button = row.find("button.deactivate");
|
2019-05-16 10:36:20 +02:00
|
|
|
var user_role = row.find(".user_role");
|
2019-03-18 12:16:06 +01:00
|
|
|
button.prop("disabled", false);
|
2017-04-08 20:08:35 +02:00
|
|
|
row.find('button.open-user-form').hide();
|
2019-05-16 10:36:20 +02:00
|
|
|
row.find('i.deactivated-user-icon').show();
|
|
|
|
button.addClass("btn-warning reactivate");
|
|
|
|
button.removeClass("deactivate btn-danger");
|
2017-04-08 20:08:35 +02:00
|
|
|
button.text(i18n.t("Reactivate"));
|
|
|
|
row.addClass("deactivated_user");
|
2019-05-16 10:36:20 +02:00
|
|
|
|
|
|
|
if (user_role) {
|
|
|
|
var user_id = row.data('user-id');
|
|
|
|
user_role.text("%state (%role)".replace("%state", i18n.t("Deactivated")).
|
|
|
|
replace("%role", people.get_user_type(user_id)));
|
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
2019-03-18 11:04:03 +01:00
|
|
|
|
2019-03-18 12:05:52 +01:00
|
|
|
function update_view_on_reactivate(row) {
|
2019-03-18 11:04:03 +01:00
|
|
|
var button = row.find("button.reactivate");
|
2019-05-16 10:36:20 +02:00
|
|
|
var user_role = row.find(".user_role");
|
2019-03-18 11:04:03 +01:00
|
|
|
row.find("button.open-user-form").show();
|
2019-05-16 10:36:20 +02:00
|
|
|
row.find('i.deactivated-user-icon').hide();
|
|
|
|
button.addClass("btn-danger deactivate");
|
|
|
|
button.removeClass("btn-warning reactivate");
|
2019-03-18 11:04:03 +01:00
|
|
|
button.text(i18n.t("Deactivate"));
|
|
|
|
row.removeClass("deactivated_user");
|
2019-05-16 10:36:20 +02:00
|
|
|
|
|
|
|
if (user_role) {
|
|
|
|
var user_id = row.data('user-id');
|
|
|
|
user_role.text(people.get_user_type(user_id));
|
|
|
|
}
|
2019-03-18 11:04:03 +01:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
function get_status_field() {
|
|
|
|
var current_tab = settings_panel_menu.org_settings.current_tab();
|
|
|
|
switch (current_tab) {
|
|
|
|
case 'deactivated-users-admin':
|
|
|
|
return $("#deactivated-user-field-status").expectOne();
|
|
|
|
case 'user-list-admin':
|
|
|
|
return $("#user-field-status").expectOne();
|
|
|
|
case 'bot-list-admin':
|
|
|
|
return $("#bot-field-status").expectOne();
|
|
|
|
default:
|
|
|
|
blueslip.fatal("Invalid admin settings page");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
|
|
|
|
exports.update_user_data = function (user_id, new_data) {
|
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-14 12:43:04 +02:00
|
|
|
var user_row = get_user_info_row(user_id);
|
2017-04-08 20:08:35 +02:00
|
|
|
|
|
|
|
if (new_data.full_name !== undefined) {
|
|
|
|
// Update the full name in the table
|
|
|
|
user_row.find(".user_name").text(new_data.full_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_data.owner !== undefined) {
|
|
|
|
// Update the bot owner in the table
|
|
|
|
user_row.find(".owner").text(new_data.owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_data.is_active !== undefined) {
|
|
|
|
if (new_data.is_active === false) {
|
2019-03-18 11:05:04 +01:00
|
|
|
// Deactivate the user/bot in the table
|
2017-04-08 20:08:35 +02:00
|
|
|
update_view_on_deactivate(user_row);
|
|
|
|
} else {
|
2019-03-18 11:05:04 +01:00
|
|
|
// Reactivate the user/bot in the table
|
2017-04-08 20:08:35 +02:00
|
|
|
update_view_on_reactivate(user_row);
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 16:09:12 +02:00
|
|
|
|
2018-10-19 12:29:46 +02:00
|
|
|
if (new_data.is_admin !== undefined || new_data.is_guest !== undefined) {
|
2019-07-08 09:04:38 +02:00
|
|
|
user_row.find(".user_role").text(people.get_user_type(user_id));
|
2018-08-02 16:09:12 +02:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function failed_listing_users(xhr) {
|
|
|
|
loading.destroy_indicator($('#subs_page_loading_indicator'));
|
2019-01-14 14:04:27 +01:00
|
|
|
var status = get_status_field();
|
|
|
|
ui_report.error(i18n.t("Error listing users or bots"), xhr, status);
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 12:15:58 +02:00
|
|
|
var LAST_ACTIVE_NEVER = -1;
|
|
|
|
var LAST_ACTIVE_UNKNOWN = -2;
|
|
|
|
|
|
|
|
function get_last_active(user) {
|
|
|
|
var presence_info = presence.presence_info[user.user_id];
|
|
|
|
if (!presence_info) {
|
|
|
|
return LAST_ACTIVE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (!isNaN(presence_info.last_active)) {
|
|
|
|
return presence_info.last_active;
|
|
|
|
}
|
|
|
|
return LAST_ACTIVE_NEVER;
|
|
|
|
}
|
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
function populate_users(realm_people_data) {
|
|
|
|
var active_users = [];
|
|
|
|
var deactivated_users = [];
|
|
|
|
var bots = [];
|
|
|
|
_.each(realm_people_data.members, function (user) {
|
|
|
|
user.is_active_human = user.is_active && !user.is_bot;
|
|
|
|
if (user.is_bot) {
|
2017-06-10 15:29:01 +02:00
|
|
|
// Convert bot type id to string for viewing to the users.
|
|
|
|
user.bot_type = settings_bots.type_id_to_string(user.bot_type);
|
2017-04-08 20:08:35 +02:00
|
|
|
bots.push(user);
|
|
|
|
} else if (user.is_active) {
|
2019-08-15 12:15:58 +02:00
|
|
|
user.last_active = get_last_active(user);
|
2017-04-08 20:08:35 +02:00
|
|
|
active_users.push(user);
|
|
|
|
} else {
|
|
|
|
deactivated_users.push(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
active_users = _.sortBy(active_users, 'full_name');
|
|
|
|
deactivated_users = _.sortBy(deactivated_users, 'full_name');
|
|
|
|
bots = _.sortBy(bots, 'full_name');
|
|
|
|
|
2019-01-09 14:30:35 +01:00
|
|
|
var reset_scrollbar = function ($sel) {
|
2017-09-26 22:16:52 +02:00
|
|
|
return function () {
|
2019-01-09 14:30:35 +01:00
|
|
|
ui.reset_scrollbar($sel);
|
2017-09-26 22:16:52 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-04-20 21:58:12 +02:00
|
|
|
var $bots_table = $("#admin_bots_table");
|
2019-08-15 07:33:31 +02:00
|
|
|
var bot_list = list_render.create($bots_table, bots, {
|
2017-04-20 21:58:12 +02:00
|
|
|
name: "admin_bot_list",
|
|
|
|
modifier: function (item) {
|
2019-06-20 14:58:28 +02:00
|
|
|
return render_admin_user_list({
|
|
|
|
can_modify: page_params.is_admin,
|
|
|
|
// It's always safe to show the fake email addresses for bot users
|
|
|
|
show_email: true,
|
|
|
|
user: item,
|
|
|
|
});
|
2017-04-20 21:58:12 +02:00
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: $bots_table.closest(".settings-section").find(".search"),
|
|
|
|
callback: function (item, value) {
|
|
|
|
return (
|
2017-08-25 03:30:54 +02:00
|
|
|
item.full_name.toLowerCase().indexOf(value) >= 0 ||
|
|
|
|
item.email.toLowerCase().indexOf(value) >= 0
|
2017-04-20 21:58:12 +02:00
|
|
|
);
|
|
|
|
},
|
2019-01-09 14:30:35 +01:00
|
|
|
onupdate: reset_scrollbar($bots_table),
|
2017-04-20 21:58:12 +02:00
|
|
|
},
|
2019-08-15 07:33:31 +02:00
|
|
|
parent_container: $("#admin-bot-list").expectOne(),
|
2017-04-20 21:58:12 +02:00
|
|
|
}).init();
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2019-08-15 07:33:31 +02:00
|
|
|
bot_list.sort("alphabetic", "full_name");
|
|
|
|
|
|
|
|
bot_list.add_sort_function("bot_owner", function (a, b) {
|
|
|
|
if (!a.bot_owner) { return 1; }
|
|
|
|
if (!b.bot_owner) { return -1; }
|
|
|
|
|
2019-08-16 06:02:53 +02:00
|
|
|
return compare_a_b(a.bot_owner, b.bot_owner);
|
2019-08-15 07:33:31 +02:00
|
|
|
});
|
|
|
|
|
2019-08-15 12:57:43 +02:00
|
|
|
function get_rendered_last_activity(item) {
|
|
|
|
var today = new XDate();
|
|
|
|
if (item.last_active === LAST_ACTIVE_UNKNOWN) {
|
|
|
|
return $("<span></span>").text(i18n.t("Unknown"));
|
|
|
|
}
|
|
|
|
if (item.last_active === LAST_ACTIVE_NEVER) {
|
|
|
|
return $("<span></span>").text(i18n.t("Never"));
|
|
|
|
}
|
|
|
|
return timerender.render_date(
|
|
|
|
new XDate(item.last_active * 1000), undefined, today);
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:58:46 +02:00
|
|
|
var $users_table = $("#admin_users_table");
|
2019-08-16 06:02:53 +02:00
|
|
|
var users_list = list_render.create($users_table, active_users, {
|
2017-04-20 21:58:46 +02:00
|
|
|
name: "users_table_list",
|
|
|
|
modifier: function (item) {
|
2019-07-09 21:24:00 +02:00
|
|
|
var $row = $(render_admin_user_list({
|
2019-03-18 07:26:12 +01:00
|
|
|
can_modify: page_params.is_admin,
|
|
|
|
is_current_user: people.is_my_user_id(item.user_id),
|
2019-06-20 14:58:28 +02:00
|
|
|
show_email: settings_org.show_email(),
|
|
|
|
user: item,
|
2019-03-18 07:26:12 +01:00
|
|
|
}));
|
2019-08-15 12:57:43 +02:00
|
|
|
$row.find(".last_active").append(get_rendered_last_activity(item));
|
2017-04-20 21:58:46 +02:00
|
|
|
return $row;
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: $users_table.closest(".settings-section").find(".search"),
|
|
|
|
callback: function (item, value) {
|
2018-08-08 23:21:14 +02:00
|
|
|
var email = item.email;
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
email = item.delivery_email;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:58:46 +02:00
|
|
|
return (
|
2017-08-25 03:30:54 +02:00
|
|
|
item.full_name.toLowerCase().indexOf(value) >= 0 ||
|
2018-08-08 23:21:14 +02:00
|
|
|
email.toLowerCase().indexOf(value) >= 0
|
2017-04-20 21:58:46 +02:00
|
|
|
);
|
|
|
|
},
|
2019-01-09 14:30:35 +01:00
|
|
|
onupdate: reset_scrollbar($users_table),
|
2017-04-20 21:58:46 +02:00
|
|
|
},
|
2019-08-16 06:02:53 +02:00
|
|
|
parent_container: $("#admin-user-list").expectOne(),
|
2017-04-20 21:58:46 +02:00
|
|
|
}).init();
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2019-08-16 06:02:53 +02:00
|
|
|
users_list.sort("alphabetic", "full_name");
|
|
|
|
|
|
|
|
users_list.add_sort_function("role", function (a, b) {
|
|
|
|
function role(user) {
|
|
|
|
if (user.is_admin) { return 0; }
|
|
|
|
if (user.is_guest) { return 2; }
|
|
|
|
return 1; // member
|
|
|
|
}
|
|
|
|
return compare_a_b(role(a), role(b));
|
|
|
|
});
|
|
|
|
|
|
|
|
users_list.add_sort_function("last_active", function (a, b) {
|
|
|
|
return compare_a_b(b.last_active, a.last_active);
|
|
|
|
});
|
|
|
|
|
2017-04-20 21:47:14 +02:00
|
|
|
var $deactivated_users_table = $("#admin_deactivated_users_table");
|
2018-06-20 18:32:39 +02:00
|
|
|
list_render.create($deactivated_users_table, deactivated_users, {
|
2017-04-20 21:47:14 +02:00
|
|
|
name: "deactivated_users_table_list",
|
|
|
|
modifier: function (item) {
|
2019-06-20 14:58:28 +02:00
|
|
|
return render_admin_user_list({
|
|
|
|
user: item,
|
|
|
|
show_email: settings_org.show_email(),
|
|
|
|
can_modify: page_params.is_admin,
|
|
|
|
});
|
2017-04-20 21:47:14 +02:00
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: $deactivated_users_table.closest(".settings-section").find(".search"),
|
|
|
|
callback: function (item, value) {
|
2018-08-08 23:21:14 +02:00
|
|
|
var email = item.email;
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
email = item.delivery_email;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:47:14 +02:00
|
|
|
return (
|
2017-08-25 03:30:54 +02:00
|
|
|
item.full_name.toLowerCase().indexOf(value) >= 0 ||
|
2018-08-08 23:21:14 +02:00
|
|
|
email.toLowerCase().indexOf(value) >= 0
|
2017-04-20 21:47:14 +02:00
|
|
|
);
|
|
|
|
},
|
2019-01-09 14:30:35 +01:00
|
|
|
onupdate: reset_scrollbar($deactivated_users_table),
|
2017-04-20 21:47:14 +02:00
|
|
|
},
|
|
|
|
}).init();
|
2017-09-26 22:16:52 +02:00
|
|
|
|
2017-04-08 20:08:35 +02: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'));
|
2018-03-03 08:33:30 +01:00
|
|
|
$("#admin_deactivated_users_table").show();
|
|
|
|
$("#admin_users_table").show();
|
|
|
|
$("#admin_bots_table").show();
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.set_up = function () {
|
2018-02-28 19:29:34 +01:00
|
|
|
loading.make_indicator($('#admin_page_users_loading_indicator'), {text: 'Loading...'});
|
|
|
|
loading.make_indicator($('#admin_page_bots_loading_indicator'), {text: 'Loading...'});
|
|
|
|
loading.make_indicator($('#admin_page_deactivated_users_loading_indicator'), {text: 'Loading...'});
|
2018-03-03 08:33:30 +01:00
|
|
|
$("#admin_deactivated_users_table").hide();
|
|
|
|
$("#admin_users_table").hide();
|
|
|
|
$("#admin_bots_table").hide();
|
2017-04-08 20:08:35 +02:00
|
|
|
|
|
|
|
// Populate users and bots tables
|
|
|
|
channel.get({
|
2018-12-18 19:34:45 +01:00
|
|
|
url: '/json/users',
|
2017-04-08 20:08:35 +02:00
|
|
|
idempotent: true,
|
2018-12-18 19:34:45 +01:00
|
|
|
timeout: 10 * 1000,
|
2017-04-08 20:08:35 +02:00
|
|
|
success: exports.on_load_success,
|
|
|
|
error: failed_listing_users,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-07-08 09:17:59 +02:00
|
|
|
function open_user_info_form_modal(person) {
|
2019-07-09 21:24:00 +02:00
|
|
|
var html = render_user_info_form_modal({
|
2019-07-08 09:17:59 +02:00
|
|
|
user_id: person.user_id,
|
|
|
|
email: person.email,
|
|
|
|
full_name: people.get_full_name(person.user_id),
|
|
|
|
is_admin: person.is_admin,
|
|
|
|
is_guest: person.is_guest,
|
|
|
|
is_member: !person.is_admin && !person.is_guest,
|
|
|
|
is_bot: person.is_bot,
|
|
|
|
});
|
|
|
|
var user_info_form_modal = $(html);
|
|
|
|
var modal_container = $('#user-info-form-modal-container');
|
|
|
|
modal_container.empty().append(user_info_form_modal);
|
|
|
|
overlays.open_modal('user-info-form-modal');
|
|
|
|
|
|
|
|
if (person.is_bot) {
|
|
|
|
// Dynamically add the owner select control in order to
|
|
|
|
// avoid performance issues in case of large number of users.
|
|
|
|
var users_list = people.get_active_human_persons();
|
2019-07-09 21:24:00 +02:00
|
|
|
var owner_select = $(render_bot_owner_select({users_list: users_list}));
|
2019-07-08 09:17:59 +02:00
|
|
|
owner_select.val(bot_data.get(person.user_id).owner || "");
|
|
|
|
modal_container.find(".edit_bot_owner_container").append(owner_select);
|
|
|
|
}
|
|
|
|
|
|
|
|
return user_info_form_modal;
|
|
|
|
}
|
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
exports.on_load_success = function (realm_people_data) {
|
|
|
|
meta.loaded = true;
|
|
|
|
|
|
|
|
populate_users(realm_people_data);
|
|
|
|
|
2019-03-19 12:39:06 +01:00
|
|
|
var modal_elem = $("#deactivation_user_modal").expectOne();
|
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
$(".admin_user_table").on("click", ".deactivate", function (e) {
|
2018-05-23 22:29:00 +02:00
|
|
|
// This click event must not get propagated to parent container otherwise the modal
|
|
|
|
// will not show up because of a call to `close_active_modal` in `settings.js`.
|
2017-04-08 20:08:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var row = $(e.target).closest(".user_row");
|
2019-03-19 12:39:06 +01:00
|
|
|
var user_id = row.data('user-id');
|
|
|
|
var user = people.get_person_from_user_id(user_id);
|
|
|
|
modal_elem.find(".email").text(user.email);
|
|
|
|
modal_elem.find(".user_name").text(user.full_name);
|
|
|
|
modal_elem.modal("show");
|
2019-03-19 12:57:15 +01:00
|
|
|
modal_elem.data('user-id', user_id);
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
|
|
|
|
2019-03-19 12:39:06 +01:00
|
|
|
modal_elem.find('.do_deactivate_button').click(function () {
|
2019-03-19 12:57:15 +01:00
|
|
|
var user_id = modal_elem.data('user-id');
|
|
|
|
var row = get_user_info_row(user_id);
|
|
|
|
var email = row.attr("data-email");
|
2017-04-08 20:08:35 +02:00
|
|
|
|
|
|
|
if ($("#deactivation_user_modal .email").html() !== email) {
|
|
|
|
blueslip.error("User deactivation canceled due to non-matching fields.");
|
2017-11-04 15:42:38 +01:00
|
|
|
ui_report.message(i18n.t("Deactivation encountered an error. Please reload and try again."),
|
2018-05-06 21:43:17 +02:00
|
|
|
$("#home-error"), 'alert-error');
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
2019-03-19 12:39:06 +01:00
|
|
|
modal_elem.modal("hide");
|
2019-03-19 12:57:15 +01:00
|
|
|
var row_deactivate_button = row.find("button.deactivate");
|
2019-03-18 12:16:06 +01:00
|
|
|
row_deactivate_button.prop("disabled", true).text(i18n.t("Working…"));
|
2019-01-14 14:04:27 +01:00
|
|
|
var opts = {
|
2019-03-18 12:16:06 +01:00
|
|
|
success_continuation: function () {
|
2019-03-19 12:57:15 +01:00
|
|
|
update_view_on_deactivate(row);
|
2019-03-18 12:16:06 +01:00
|
|
|
},
|
|
|
|
error_continuation: function () {
|
|
|
|
row_deactivate_button.text(i18n.t("Deactivate"));
|
|
|
|
},
|
2019-01-14 14:04:27 +01:00
|
|
|
};
|
|
|
|
var status = get_status_field();
|
|
|
|
var url = '/json/users/' + encodeURIComponent(user_id);
|
2019-03-18 12:16:06 +01:00
|
|
|
settings_ui.do_settings_change(channel.del, url, {}, status, opts);
|
2019-01-14 14:04:27 +01:00
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(".admin_bot_table").on("click", ".deactivate", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-03-18 12:05:52 +01:00
|
|
|
var button_elem = $(e.target);
|
|
|
|
var row = button_elem.closest(".user_row");
|
2018-05-15 15:26:04 +02:00
|
|
|
var bot_id = row.attr("data-user-id");
|
2019-01-14 14:04:27 +01:00
|
|
|
var url = '/json/bots/' + encodeURIComponent(bot_id);
|
2019-03-18 12:05:52 +01:00
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
var opts = {
|
2019-03-18 11:07:51 +01:00
|
|
|
success_continuation: function () {
|
|
|
|
update_view_on_deactivate(row);
|
|
|
|
},
|
2019-03-18 12:05:52 +01:00
|
|
|
error_continuation: function (xhr) {
|
|
|
|
ui_report.generic_row_button_error(xhr, button_elem);
|
|
|
|
},
|
2019-01-14 14:04:27 +01:00
|
|
|
};
|
|
|
|
var status = get_status_field();
|
2019-03-18 11:07:51 +01:00
|
|
|
settings_ui.do_settings_change(channel.del, url, {}, status, opts);
|
2017-04-08 20:08:35 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".admin_user_table, .admin_bot_table").on("click", ".reactivate", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
// Go up the tree until we find the user row, then grab the email element
|
2019-03-18 12:05:52 +01:00
|
|
|
var button_elem = $(e.target);
|
|
|
|
var row = button_elem.closest(".user_row");
|
2018-05-17 19:45:13 +02:00
|
|
|
var user_id = row.attr("data-user-id");
|
2019-01-14 14:04:27 +01:00
|
|
|
var url = '/json/users/' + encodeURIComponent(user_id) + "/reactivate";
|
|
|
|
var data = {};
|
|
|
|
var status = get_status_field();
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
var opts = {
|
2019-03-18 12:05:52 +01:00
|
|
|
success_continuation: function () {
|
|
|
|
update_view_on_reactivate(row);
|
|
|
|
},
|
|
|
|
error_continuation: function (xhr) {
|
|
|
|
ui_report.generic_row_button_error(xhr, button_elem);
|
|
|
|
},
|
2019-01-14 14:04:27 +01:00
|
|
|
};
|
2019-03-18 12:05:52 +01:00
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
settings_ui.do_settings_change(channel.post, url, data, status, opts);
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
|
|
|
|
2018-07-30 09:22:57 +02:00
|
|
|
$(".admin_user_table, .admin_bot_table").on("click", ".open-user-form", function (e) {
|
|
|
|
var user_id = $(e.currentTarget).attr("data-user-id");
|
|
|
|
var person = people.get_person_from_user_id(user_id);
|
|
|
|
|
|
|
|
if (!person) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:30:15 +02:00
|
|
|
var user_info_form_modal = open_user_info_form_modal(person);
|
2018-09-05 21:25:05 +02:00
|
|
|
var element = "#user-info-form-modal .custom-profile-field-form";
|
|
|
|
$(element).html("");
|
|
|
|
settings_account.append_custom_profile_fields(element, user_id);
|
|
|
|
settings_account.initialize_custom_date_type_fields(element);
|
2019-04-12 15:19:23 +02:00
|
|
|
var fields_user_pills = settings_account.initialize_custom_user_type_fields(element,
|
|
|
|
user_id,
|
|
|
|
true, false);
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2018-07-14 12:43:04 +02:00
|
|
|
var url;
|
|
|
|
var data;
|
|
|
|
var full_name = user_info_form_modal.find("input[name='full_name']");
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2018-08-02 17:33:49 +02:00
|
|
|
user_info_form_modal.find('.submit_user_info_change').on("click", function (e) {
|
2017-04-08 20:08:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2018-08-02 17:34:20 +02:00
|
|
|
var user_role_select_value = user_info_form_modal.find('#user-role-select').val();
|
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
var admin_status = get_status_field();
|
2018-04-03 03:46:53 +02:00
|
|
|
if (person.is_bot) {
|
2018-07-30 09:22:57 +02:00
|
|
|
url = "/json/bots/" + encodeURIComponent(user_id);
|
2018-04-03 03:46:53 +02:00
|
|
|
data = {
|
|
|
|
full_name: full_name.val(),
|
|
|
|
};
|
2018-07-30 09:22:57 +02:00
|
|
|
var owner_select_value = user_info_form_modal.find('.bot_owner_select').val();
|
|
|
|
if (owner_select_value) {
|
|
|
|
data.bot_owner_id = people.get_by_email(owner_select_value).user_id;
|
2018-04-03 03:46:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-09-05 21:25:05 +02:00
|
|
|
var new_profile_data = [];
|
|
|
|
$("#user-info-form-modal .custom_user_field_value").each(function () {
|
|
|
|
// Remove duplicate datepicker input element genearted flatpicker library
|
|
|
|
if (!$(this).hasClass("form-control")) {
|
|
|
|
new_profile_data.push({
|
|
|
|
id: parseInt($(this).closest(".custom_user_field").attr("data-field-id"), 10),
|
|
|
|
value: $(this).val(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Append user type field values also
|
|
|
|
_.each(fields_user_pills, function (field_pills, field_id) {
|
|
|
|
if (field_pills) {
|
|
|
|
var user_ids = user_pill.get_user_ids(field_pills);
|
|
|
|
new_profile_data.push({
|
|
|
|
id: parseInt(field_id, 10),
|
|
|
|
value: user_ids,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 09:22:57 +02:00
|
|
|
url = "/json/users/" + encodeURIComponent(user_id);
|
2018-04-03 03:46:53 +02:00
|
|
|
data = {
|
|
|
|
full_name: JSON.stringify(full_name.val()),
|
2018-08-02 17:34:20 +02:00
|
|
|
is_admin: JSON.stringify(user_role_select_value === 'admin'),
|
2018-10-19 12:29:46 +02:00
|
|
|
is_guest: JSON.stringify(user_role_select_value === 'guest'),
|
2018-09-05 21:25:05 +02:00
|
|
|
profile_data: JSON.stringify(new_profile_data),
|
2018-04-03 03:46:53 +02:00
|
|
|
};
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
settings_ui.do_settings_change(channel.patch, url, data, admin_status);
|
2019-01-06 19:22:32 +01:00
|
|
|
overlays.close_modal('user-info-form-modal');
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_users;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.settings_users = settings_users;
|