mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
settings_users: Make update_view_on_reactivate function generic.
This also remove: - meta.current_bot_element: As usage of meta has been wrongly exploited, we should refrain us from using meta this way i.e. to share variable between function using the global variable, as they reduce code readability. - update_view_on_deactivate_reactivate_failure: Again to deduplicate the the code we're compromising with readability which isn't worth it here, also we need to this because we have removed above meta key.
This commit is contained in:
committed by
Tim Abbott
parent
53abbd9408
commit
f0c069a316
@@ -25,8 +25,7 @@ function update_view_on_deactivate(row) {
|
|||||||
row.addClass("deactivated_user");
|
row.addClass("deactivated_user");
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_view_on_reactivate() {
|
function update_view_on_reactivate(row) {
|
||||||
var row = meta.current_bot_element.closest(".user_row");
|
|
||||||
var button = row.find("button.reactivate");
|
var button = row.find("button.reactivate");
|
||||||
row.find("button.open-user-form").show();
|
row.find("button.open-user-form").show();
|
||||||
button.addClass("btn-danger");
|
button.addClass("btn-danger");
|
||||||
@@ -37,11 +36,6 @@ function update_view_on_reactivate() {
|
|||||||
row.removeClass("deactivated_user");
|
row.removeClass("deactivated_user");
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_view_on_deactivate_reactivate_failure(xhr) {
|
|
||||||
ui_report.generic_row_button_error(xhr, meta.current_bot_element);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_status_field() {
|
function get_status_field() {
|
||||||
var current_tab = settings_panel_menu.org_settings.current_tab();
|
var current_tab = settings_panel_menu.org_settings.current_tab();
|
||||||
switch (current_tab) {
|
switch (current_tab) {
|
||||||
@@ -303,15 +297,18 @@ exports.on_load_success = function (realm_people_data) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
var row = $(e.target).closest(".user_row");
|
var button_elem = $(e.target);
|
||||||
meta.current_bot_element = $(e.target);
|
var row = button_elem.closest(".user_row");
|
||||||
var bot_id = row.attr("data-user-id");
|
var bot_id = row.attr("data-user-id");
|
||||||
var url = '/json/bots/' + encodeURIComponent(bot_id);
|
var url = '/json/bots/' + encodeURIComponent(bot_id);
|
||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
success_continuation: function () {
|
success_continuation: function () {
|
||||||
update_view_on_deactivate(row);
|
update_view_on_deactivate(row);
|
||||||
},
|
},
|
||||||
error_continuation: update_view_on_deactivate_reactivate_failure,
|
error_continuation: function (xhr) {
|
||||||
|
ui_report.generic_row_button_error(xhr, button_elem);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
var status = get_status_field();
|
var status = get_status_field();
|
||||||
settings_ui.do_settings_change(channel.del, url, {}, status, opts);
|
settings_ui.do_settings_change(channel.del, url, {}, status, opts);
|
||||||
@@ -321,18 +318,23 @@ exports.on_load_success = function (realm_people_data) {
|
|||||||
$(".admin_user_table, .admin_bot_table").on("click", ".reactivate", function (e) {
|
$(".admin_user_table, .admin_bot_table").on("click", ".reactivate", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
meta.current_bot_element = $(e.target);
|
|
||||||
// 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
|
||||||
var row = $(e.target).closest(".user_row");
|
var button_elem = $(e.target);
|
||||||
|
var row = button_elem.closest(".user_row");
|
||||||
var user_id = row.attr("data-user-id");
|
var user_id = row.attr("data-user-id");
|
||||||
var url = '/json/users/' + encodeURIComponent(user_id) + "/reactivate";
|
var url = '/json/users/' + encodeURIComponent(user_id) + "/reactivate";
|
||||||
var data = {};
|
var data = {};
|
||||||
var status = get_status_field();
|
var status = get_status_field();
|
||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
success_continuation: update_view_on_reactivate,
|
success_continuation: function () {
|
||||||
error_continuation: update_view_on_deactivate_reactivate_failure,
|
update_view_on_reactivate(row);
|
||||||
|
},
|
||||||
|
error_continuation: function (xhr) {
|
||||||
|
ui_report.generic_row_button_error(xhr, button_elem);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
settings_ui.do_settings_change(channel.post, url, data, status, opts);
|
settings_ui.do_settings_change(channel.post, url, data, status, opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user