mirror of https://github.com/zulip/zulip.git
admin: Refactor to remove unnecessary selections of active_user_row.
This commit is contained in:
parent
958ada9f44
commit
ae04744606
|
@ -116,11 +116,11 @@ exports.setup_page = function () {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
$(".active_user_row").removeClass("active_user_row");
|
$(".active_user_row").removeClass("active_user_row");
|
||||||
|
var row = $(e.target).closest(".user_row");
|
||||||
|
row.addClass("active_user_row");
|
||||||
|
|
||||||
$(e.target).closest(".user_row").addClass("active_user_row");
|
var user_name = row.find('.user_name').text();
|
||||||
|
var email = row.find('.email').text();
|
||||||
var user_name = $(".active_user_row").find('.user_name').text();
|
|
||||||
var email = $(".active_user_row").find('.email').text();
|
|
||||||
|
|
||||||
$("#deactivation_user_modal .email").text(email);
|
$("#deactivation_user_modal .email").text(email);
|
||||||
$("#deactivation_user_modal .user_name").text(user_name);
|
$("#deactivation_user_modal .user_name").text(user_name);
|
||||||
|
@ -132,10 +132,10 @@ exports.setup_page = function () {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
$(".active_stream_row").removeClass("active_stream_row");
|
$(".active_stream_row").removeClass("active_stream_row");
|
||||||
|
var row = $(e.target).closest(".stream_row");
|
||||||
|
row.addClass("active_stream_row");
|
||||||
|
|
||||||
$(e.target).closest(".stream_row").addClass("active_stream_row");
|
var stream_name = row.find('.stream_name').text();
|
||||||
|
|
||||||
var stream_name = $(".active_stream_row").find('.stream_name').text();
|
|
||||||
|
|
||||||
$("#deactivation_stream_modal .stream_name").text(stream_name);
|
$("#deactivation_stream_modal .stream_name").text(stream_name);
|
||||||
$("#deactivation_stream_modal").modal("show");
|
$("#deactivation_stream_modal").modal("show");
|
||||||
|
@ -146,25 +146,24 @@ exports.setup_page = function () {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
$(".active_user_row").removeClass("active_user_row");
|
$(".active_user_row").removeClass("active_user_row");
|
||||||
|
var row = $(e.target).closest(".user_row");
|
||||||
|
row.addClass("active_user_row");
|
||||||
|
|
||||||
$(e.target).closest(".user_row").addClass("active_user_row");
|
var user_name = row.find('.user_name').text();
|
||||||
|
var email = row.find('.email').text();
|
||||||
var user_name = $(".active_user_row").find('.user_name').text();
|
|
||||||
var email = $(".active_user_row").find('.email').text();
|
|
||||||
channel.del({
|
channel.del({
|
||||||
url: '/json/bots/' + email,
|
url: '/json/bots/' + email,
|
||||||
error: function (xhr, error_type) {
|
error: function (xhr, error_type) {
|
||||||
if (xhr.status.toString().charAt(0) === "4") {
|
if (xhr.status.toString().charAt(0) === "4") {
|
||||||
$(".active_user_row button").closest("td").html(
|
row.find("button").closest("td").html(
|
||||||
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$(".active_user_row button").text("Failed!");
|
row.find("button").text("Failed!");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function () {
|
success: function () {
|
||||||
var row = $(".active_user_row");
|
var button = row.find("button.deactivate");
|
||||||
var button = $(".active_user_row button.deactivate");
|
|
||||||
button.addClass("btn-warning");
|
button.addClass("btn-warning");
|
||||||
button.removeClass("btn-danger");
|
button.removeClass("btn-danger");
|
||||||
button.addClass("reactivate");
|
button.addClass("reactivate");
|
||||||
|
@ -181,23 +180,24 @@ exports.setup_page = function () {
|
||||||
|
|
||||||
// Go up the tree until we find the user row, then grab the email element
|
// Go up the tree until we find the user row, then grab the email element
|
||||||
$(".active_user_row").removeClass("active_user_row");
|
$(".active_user_row").removeClass("active_user_row");
|
||||||
$(e.target).closest(".user_row").addClass("active_user_row");
|
var row = $(e.target).closest(".user_row");
|
||||||
|
row.addClass("active_user_row");
|
||||||
|
|
||||||
var email = $(".active_user_row").find('.email').text();
|
var email = row.find('.email').text();
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/users/' + email + "/reactivate",
|
url: '/json/users/' + email + "/reactivate",
|
||||||
error: function (xhr, error_type) {
|
error: function (xhr, error_type) {
|
||||||
|
var button = row.find("button");
|
||||||
if (xhr.status.toString().charAt(0) === "4") {
|
if (xhr.status.toString().charAt(0) === "4") {
|
||||||
$(".active_user_row button").closest("td").html(
|
button.closest("td").html(
|
||||||
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$(".active_user_row button").text("Failed!");
|
button.text("Failed!");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function () {
|
success: function () {
|
||||||
var row = $(".active_user_row");
|
var button = row.find("button.reactivate");
|
||||||
var button = $(".active_user_row button.reactivate");
|
|
||||||
button.addClass("btn-danger");
|
button.addClass("btn-danger");
|
||||||
button.removeClass("btn-warning");
|
button.removeClass("btn-warning");
|
||||||
button.addClass("deactivate");
|
button.addClass("deactivate");
|
||||||
|
@ -288,8 +288,9 @@ exports.setup_page = function () {
|
||||||
|
|
||||||
// Go up the tree until we find the user row, then grab the email element
|
// Go up the tree until we find the user row, then grab the email element
|
||||||
$(".active_user_row").removeClass("active_user_row");
|
$(".active_user_row").removeClass("active_user_row");
|
||||||
$(e.target).closest(".user_row").addClass("active_user_row");
|
var row = $(e.target).closest(".user_row");
|
||||||
var email = $(".active_user_row").find('.email').text();
|
row.addClass("active_user_row");
|
||||||
|
var email = row.find('.email').text();
|
||||||
|
|
||||||
var url = "/json/users/" + email;
|
var url = "/json/users/" + email;
|
||||||
var data = {
|
var data = {
|
||||||
|
@ -300,8 +301,7 @@ exports.setup_page = function () {
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
success: function () {
|
success: function () {
|
||||||
var row = $(".active_user_row");
|
var button = row.find("button.make-admin");
|
||||||
var button = $(".active_user_row button.make-admin");
|
|
||||||
button.addClass("btn-danger");
|
button.addClass("btn-danger");
|
||||||
button.removeClass("btn-warning");
|
button.removeClass("btn-warning");
|
||||||
button.addClass("remove-admin");
|
button.addClass("remove-admin");
|
||||||
|
@ -309,7 +309,7 @@ exports.setup_page = function () {
|
||||||
button.text("Remove admin");
|
button.text("Remove admin");
|
||||||
},
|
},
|
||||||
error: function (xhr, error) {
|
error: function (xhr, error) {
|
||||||
var status = $(".active_user_row .admin-user-status");
|
var status = row.find(".admin-user-status");
|
||||||
ui.report_error("Failed!", xhr, status);
|
ui.report_error("Failed!", xhr, status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -321,8 +321,9 @@ exports.setup_page = function () {
|
||||||
|
|
||||||
// Go up the tree until we find the user row, then grab the email element
|
// Go up the tree until we find the user row, then grab the email element
|
||||||
$(".active_user_row").removeClass("active_user_row");
|
$(".active_user_row").removeClass("active_user_row");
|
||||||
$(e.target).closest(".user_row").addClass("active_user_row");
|
var row = $(e.target).closest(".user_row");
|
||||||
var email = $(".active_user_row").find('.email').text();
|
row.addClass("active_user_row");
|
||||||
|
var email = row.find('.email').text();
|
||||||
|
|
||||||
var url = "/json/users/" + email;
|
var url = "/json/users/" + email;
|
||||||
var data = {
|
var data = {
|
||||||
|
@ -333,8 +334,7 @@ exports.setup_page = function () {
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
success: function () {
|
success: function () {
|
||||||
var row = $(".active_user_row");
|
var button = row.find("button.remove-admin");
|
||||||
var button = $(".active_user_row button.remove-admin");
|
|
||||||
button.addClass("btn-warning");
|
button.addClass("btn-warning");
|
||||||
button.removeClass("btn-danger");
|
button.removeClass("btn-danger");
|
||||||
button.addClass("make-admin");
|
button.addClass("make-admin");
|
||||||
|
@ -342,34 +342,35 @@ exports.setup_page = function () {
|
||||||
button.text("Make admin");
|
button.text("Make admin");
|
||||||
},
|
},
|
||||||
error: function (xhr, error) {
|
error: function (xhr, error) {
|
||||||
var status = $(".active_user_row .admin-user-status");
|
var status = row.find(".admin-user-status");
|
||||||
ui.report_error("Failed!", xhr, status);
|
ui.report_error("Failed!", xhr, status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#do_deactivate_user_button").click(function (e) {
|
$("#do_deactivate_user_button").click(function (e) {
|
||||||
if ($("#deactivation_user_modal .email").html() !== $(".active_user_row").find('.email').text()) {
|
var row = $(".active_user_row");
|
||||||
|
var email = row.find(".email").text();
|
||||||
|
if ($("#deactivation_user_modal .email").html() !== email) {
|
||||||
blueslip.error("User deactivation canceled due to non-matching fields.");
|
blueslip.error("User deactivation canceled due to non-matching fields.");
|
||||||
ui.report_message("Deactivation encountered an error. Please reload and try again.",
|
ui.report_message("Deactivation encountered an error. Please reload and try again.",
|
||||||
$("#home-error"), 'alert-error');
|
$("#home-error"), 'alert-error');
|
||||||
}
|
}
|
||||||
$("#deactivation_user_modal").modal("hide");
|
$("#deactivation_user_modal").modal("hide");
|
||||||
$(".active_user_row button").prop("disabled", true).text("Working…");
|
row.find("button").prop("disabled", true).text("Working…");
|
||||||
channel.del({
|
channel.del({
|
||||||
url: '/json/users/' + $(".active_user_row").find('.email').text(),
|
url: '/json/users/' + email,
|
||||||
error: function (xhr, error_type) {
|
error: function (xhr, error_type) {
|
||||||
if (xhr.status.toString().charAt(0) === "4") {
|
if (xhr.status.toString().charAt(0) === "4") {
|
||||||
$(".active_user_row button").closest("td").html(
|
row.find("button").closest("td").html(
|
||||||
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$(".active_user_row button").text("Failed!");
|
row.find("button").text("Failed!");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function () {
|
success: function () {
|
||||||
var row = $(".active_user_row");
|
var button = row.find("button.deactivate");
|
||||||
var button = $(".active_user_row button.deactivate");
|
|
||||||
button.prop("disabled", false);
|
button.prop("disabled", false);
|
||||||
button.addClass("btn-warning");
|
button.addClass("btn-warning");
|
||||||
button.removeClass("btn-danger");
|
button.removeClass("btn-danger");
|
||||||
|
|
Loading…
Reference in New Issue