Handle home view subscriptions error cases.

(imported from commit 7f31b5c4837c524c3ad5a0538ca1f01ad73141a3)
This commit is contained in:
Jessica McKellar 2012-10-01 15:32:09 -04:00
parent 8727b1667c
commit 28e668bb46
3 changed files with 32 additions and 9 deletions

View File

@ -99,6 +99,8 @@ var have_initial_messages = {{ have_initial_messages }};
</div>
</div>
</div>
<div class="alert alert_sidebar" id="home-error"></div>
<div class="alert alert_sidebar" id="class-dne">
<p>The class <span class="classname" id="class-dne-name"></span> does not exist.</p>
<a id="create-it" class="btn btn-primary" href="#">Create and send</a>

View File

@ -60,6 +60,7 @@ function report_error(response, xhr, status_box) {
status_box.removeClass(status_classes).addClass('alert-error')
.text(response).stop(true).fadeTo(0, 1);
status_box.show();
}
$(function () {
@ -73,16 +74,12 @@ $(function () {
// Prepare the click handler for subbing to a new class to which
// you have composed a zephyr.
$('#create-it').click(function () {
sub(compose_class_name());
$("#class-message form").ajaxSubmit();
$('#class-dne').stop(true).fadeOut(500);
sub_from_home(compose_class_name(), $('#class-dne'));
});
// Prepare the click handler for subbing to an existing class.
$('#sub-it').click(function () {
sub(compose_class_name());
$("#class-message form").ajaxSubmit();
$('#class-nosub').stop(true).fadeOut(500);
sub_from_home(compose_class_name(), $('#class-nosub'));
});
$('#sidebar a[href="#subscriptions"]').click(function () {
@ -141,9 +138,22 @@ $.ajaxSetup({
}
});
function sub(zephyr_class) {
// TODO: check the return value and handle an error condition
$.post('/json/subscriptions/add', {new_subscription: zephyr_class});
function sub_from_home(zephyr_class, prompt_button) {
$.ajax({
type: 'POST',
url: '/json/subscriptions/add',
data: {new_subscription: zephyr_class},
dataType: 'json',
timeout: 10*60*1000, // 10 minutes in ms
success: function (data) {
$("#class-message form").ajaxSubmit();
prompt_button.stop(true).fadeOut(500);
$("#subscriptions-status").fadeOut(0);
},
error: function (xhr, error_type, exn) {
report_error("Unable to subscribe", xhr, $("#home-error"));
}
});
}
function compose_button() {
@ -223,6 +233,13 @@ $(function () {
buttons.removeAttr('disabled');
hide_compose();
}
$("#home-error").hide();
},
error: function (xhr) {
okay = false;
report_error("Error listing subscriptions", xhr, $("#home-error"));
$("#class").focus();
buttons.removeAttr('disabled');
}
});
if (okay && class_list.indexOf(zephyr_class) === -1) {

View File

@ -340,6 +340,10 @@ input.send_zephyr {
margin: 0;
}
#home-error {
display: none;
}
#bottom-nav {
position: absolute;
bottom: 0;