settings_user: Move "Make admin" button to user-info-form modal.

This commit is contained in:
Shubham Dhama 2018-08-01 19:57:13 +05:30 committed by Tim Abbott
parent 4206314184
commit 7776fa0d05
4 changed files with 24 additions and 27 deletions

View File

@ -375,11 +375,8 @@ run_test('admin_user_list', () => {
assert.equal($(buttons[0]).text().trim(), "translated: Deactivate");
assert($(buttons[0]).hasClass("deactivate"));
assert.equal($(buttons[1]).text().trim(), "translated: Make admin");
assert($(buttons[1]).hasClass("make-admin"));
assert.equal($(buttons[2]).attr('title').trim(), "translated: Edit user");
assert($(buttons[2]).hasClass("open-user-form"));
assert.equal($(buttons[1]).attr('title').trim(), "translated: Edit user");
assert($(buttons[1]).hasClass("open-user-form"));
// When the logged in user is not admin
html = '<table>';

View File

@ -304,13 +304,14 @@ exports.on_load_success = function (realm_people_data) {
});
});
$(".admin_user_table").on("click", ".make-admin", function (e) {
var user_info_form_modal_container = $("#user-info-form-modal-container");
user_info_form_modal_container.on("click", ".make-admin", function (e) {
e.preventDefault();
e.stopPropagation();
// Go up the tree until we find the user row, then grab the user_id data
var row = $(e.target).closest(".user_row");
var user_id = row.attr("data-user-id");
var user_id = user_info_form_modal_container.find('#user-name-form').attr("data-user-id");
var url = "/json/users/" + encodeURIComponent(user_id);
var data = {
@ -321,7 +322,7 @@ exports.on_load_success = function (realm_people_data) {
url: url,
data: data,
success: function () {
var button = row.find("button.make-admin");
var button = user_info_form_modal_container.find("button.make-admin");
button.addClass("btn-danger");
button.removeClass("btn-warning");
button.addClass("remove-admin");
@ -335,13 +336,12 @@ exports.on_load_success = function (realm_people_data) {
});
});
$(".admin_user_table").on("click", ".remove-admin", function (e) {
user_info_form_modal_container.on("click", ".remove-admin", function (e) {
e.preventDefault();
e.stopPropagation();
// Go up the tree until we find the user row, then grab the user_id data
var row = $(e.target).closest(".user_row");
var user_id = row.attr("data-user-id");
var user_id = user_info_form_modal_container.find('#user-name-form').attr("data-user-id");
var url = "/json/users/" + encodeURIComponent(user_id);
var data = {
@ -352,7 +352,7 @@ exports.on_load_success = function (realm_people_data) {
url: url,
data: data,
success: function () {
var button = row.find("button.remove-admin");
var button = user_info_form_modal_container.find("button.remove-admin");
button.addClass("btn-warning");
button.removeClass("btn-danger");
button.addClass("make-admin");
@ -370,6 +370,7 @@ exports.on_load_success = function (realm_people_data) {
var html = templates.render('user-info-form-modal', {
user_id: person.user_id,
full_name: people.get_full_name(person.user_id),
is_admin: person.is_admin,
is_bot: person.is_bot,
});
var user_info_form_modal = $(html);

View File

@ -33,19 +33,6 @@
</button>
{{/if}}
</span>
<span class="user-admin-settings">
{{#if is_active_human}}
{{#if is_admin}}
<button class="button rounded small remove-admin btn-danger">
{{t "Remove admin" }}
</button>
{{else}}
<button class="button rounded small make-admin btn-warning">
{{t "Make admin" }}
</button>
{{/if}}
{{/if}}
</span>
<button class="button rounded small btn-warning open-user-form{{#unless is_active}} display-none{{/unless}}" title="{{t 'Edit user' }}" data-user-id="{{user_id}}">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>

View File

@ -4,7 +4,7 @@
<h3 id="user-info-form-modal-label">{{t "Change user info and roles" }}</h3>
</div>
<div class="modal-body">
<div class="user-name-form" data-user-id="{{user_id}}">
<div id="user-name-form" data-user-id="{{user_id}}">
<form class="form-horizontal name-setting">
<input type="hidden" name="is_full_name" value="true" />
<div class="input-group name_change_container">
@ -15,6 +15,18 @@
<div class="input-group edit_bot_owner_container">
<label for="bot_owner_select">{{t "Owner" }}</label>
</div>
{{else if is_admin}}
<div class="user-admin-settings">
<button class="button rounded small remove-admin btn-danger">
{{t "Remove admin" }}
</button>
</div>
{{else}}
<div class="user-admin-settings">
<button class="button rounded small make-admin btn-warning">
{{t "Make admin" }}
</button>
</div>
{{/if}}
</form>
</div>