mirror of https://github.com/zulip/zulip.git
Add error handling for subscription AJAX requests.
(imported from commit 9ed019da01aaa85302000ad62441b85786c2c528)
This commit is contained in:
parent
f3aefde0df
commit
703a1cd6d9
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
{% icanhazjs "subscription" %}
|
{% icanhazjs "subscription" %}
|
||||||
|
|
||||||
|
<div class="alert" id="subscriptions-status"></div>
|
||||||
|
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<h1>Subscriptions</h1>
|
<h1>Subscriptions</h1>
|
||||||
<form id="add_new_subscription" action="/json/subscriptions/add" method="post" class="form-inline">{% csrf_token %}
|
<form id="add_new_subscription" action="/json/subscriptions/add" method="post" class="form-inline">{% csrf_token %}
|
||||||
|
|
|
@ -15,6 +15,18 @@ function register_huddle_onclick(zephyr_row, sender) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var zephyr_dict = {};
|
var zephyr_dict = {};
|
||||||
|
var status_classes = 'alert-error alert-success alert-info';
|
||||||
|
|
||||||
|
function report_error(response, xhr, status_box) {
|
||||||
|
if (xhr.status.toString().charAt(0) === "4") {
|
||||||
|
// Only display the error response for 4XX, where we've crafted
|
||||||
|
// a nice response.
|
||||||
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_box.removeClass(status_classes).addClass('alert-error')
|
||||||
|
.text(response).stop(true).fadeTo(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#zephyr-type-tabs a[href="#class-message"]').on('shown', function (e) {
|
$('#zephyr-type-tabs a[href="#class-message"]').on('shown', function (e) {
|
||||||
|
@ -53,8 +65,11 @@ $(function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$('#new_subscriptions').focus().select();
|
$('#new_subscriptions').focus().select();
|
||||||
|
$("#subscriptions-status").fadeOut(0);
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
report_error("Error listing subscriptions", xhr, $("#subscriptions-status"));
|
||||||
},
|
},
|
||||||
// TODO: error handling
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -110,7 +125,6 @@ function compose_class_name() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var status_classes = 'alert-error alert-success alert-info';
|
|
||||||
var send_status = $('#send-status');
|
var send_status = $('#send-status');
|
||||||
var buttons = $('#class-message, #personal-message').find('input[type="submit"]');
|
var buttons = $('#class-message, #personal-message').find('input[type="submit"]');
|
||||||
|
|
||||||
|
@ -210,8 +224,11 @@ $(function () {
|
||||||
success: function (resp, statusText, xhr, form) {
|
success: function (resp, statusText, xhr, form) {
|
||||||
var name = $.parseJSON(xhr.responseText).data;
|
var name = $.parseJSON(xhr.responseText).data;
|
||||||
$('#subscriptions_table').find('button[value="' + name + '"]').parents('tr').remove();
|
$('#subscriptions_table').find('button[value="' + name + '"]').parents('tr').remove();
|
||||||
|
$("#subscriptions-status").fadeOut(0);
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
report_error("Error removing subscription", xhr, $("#subscriptions-status"));
|
||||||
},
|
},
|
||||||
// TODO: error handling
|
|
||||||
};
|
};
|
||||||
$("#current_subscriptions").ajaxForm(options);
|
$("#current_subscriptions").ajaxForm(options);
|
||||||
});
|
});
|
||||||
|
@ -224,14 +241,16 @@ $(function () {
|
||||||
var name = $.parseJSON(xhr.responseText).data;
|
var name = $.parseJSON(xhr.responseText).data;
|
||||||
$('#subscriptions_table').prepend(ich.subscription({subscription: name}));
|
$('#subscriptions_table').prepend(ich.subscription({subscription: name}));
|
||||||
class_list.push(name);
|
class_list.push(name);
|
||||||
|
$("#subscriptions-status").fadeOut(0);
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
report_error("Error adding subscription", xhr, $("#subscriptions-status"));
|
||||||
},
|
},
|
||||||
// TODO: error handling
|
|
||||||
};
|
};
|
||||||
$("#add_new_subscription").ajaxForm(options);
|
$("#add_new_subscription").ajaxForm(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var status_classes = 'alert-error alert-success alert-info';
|
|
||||||
var settings_status = $('#settings-status');
|
var settings_status = $('#settings-status');
|
||||||
settings_status.hide();
|
settings_status.hide();
|
||||||
var options = {
|
var options = {
|
||||||
|
|
|
@ -297,4 +297,9 @@ input.send_zephyr {
|
||||||
|
|
||||||
.subscription_entry {
|
.subscription_entry {
|
||||||
width: 85%;
|
width: 85%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#subscriptions-status {
|
||||||
|
float: right;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue