org settings: Disable "Add filter" button when a request is in transit.

This prevents accidental multiple click requests due to which we get
some errors like "This field cannot be blank" (though we have successfully
added the desired filter).
Fixes: #8699.
This commit is contained in:
Shubham Dhama 2018-03-16 01:59:32 +05:30 committed by Tim Abbott
parent 233e1b4b1b
commit 95067ddb08
1 changed files with 4 additions and 0 deletions

View File

@ -72,6 +72,8 @@ exports.set_up = function () {
var filter_status = $('#admin-filter-status'); var filter_status = $('#admin-filter-status');
var pattern_status = $('#admin-filter-pattern-status'); var pattern_status = $('#admin-filter-pattern-status');
var format_status = $('#admin-filter-format-status'); var format_status = $('#admin-filter-format-status');
var add_filter_button = $('.new-filter-form button');
add_filter_button.attr("disabled", "disabled");
filter_status.hide(); filter_status.hide();
pattern_status.hide(); pattern_status.hide();
format_status.hide(); format_status.hide();
@ -86,11 +88,13 @@ exports.set_up = function () {
success: function (data) { success: function (data) {
$('#filter_pattern').val(''); $('#filter_pattern').val('');
$('#filter_format_string').val(''); $('#filter_format_string').val('');
add_filter_button.removeAttr("disabled");
filter.id = data.id; filter.id = data.id;
ui_report.success(i18n.t("Custom filter added!"), filter_status); ui_report.success(i18n.t("Custom filter added!"), filter_status);
}, },
error: function (xhr) { error: function (xhr) {
var errors = JSON.parse(xhr.responseText).errors; var errors = JSON.parse(xhr.responseText).errors;
add_filter_button.removeAttr("disabled");
if (errors.pattern !== undefined) { if (errors.pattern !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.pattern}); xhr.responseText = JSON.stringify({msg: errors.pattern});
ui_report.error(i18n.t("Failed"), xhr, pattern_status); ui_report.error(i18n.t("Failed"), xhr, pattern_status);