diff --git a/zephyr/static/js/compose.js b/zephyr/static/js/compose.js index b2ce4ae97c..db47d4b835 100644 --- a/zephyr/static/js/compose.js +++ b/zephyr/static/js/compose.js @@ -1,3 +1,5 @@ +var status_classes = 'alert-error alert-success alert-info'; + function clear_compose_box() { $("#zephyr_compose").find('input[type=text], textarea').val(''); } @@ -66,6 +68,37 @@ function compose_error(error_text, bad_input) { bad_input.focus().select(); } +// *Synchronously* check if a class exists. +// If not, displays an error and returns false. +function check_class_for_send(class_name) { + var okay = true; + $.ajax({ + url: "subscriptions/exists/" + class_name, + async: false, + success: function (data) { + if (data === "False") { + // The class doesn't exist + okay = false; + send_status.removeClass(status_classes); + send_status.show(); + $('#class-dne-name').text(class_name); + $('#class-dne').show(); + $('#create-it').focus(); + buttons.removeAttr('disabled'); + hide_compose(); + } + $("#home-error").hide(); + }, + error: function (xhr) { + okay = false; + report_error("Error checking subscription", xhr, $("#home-error")); + $("#class").focus(); + buttons.removeAttr('disabled'); + } + }); + return okay; +} + function validate_class_message() { if (compose_class_name() === "") { compose_error("Please specify a class", $("#class")); diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 5ed0025fc7..a5631260ca 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -10,7 +10,6 @@ var zephyr_array = []; var zephyr_dict = {}; var instance_list = []; -var status_classes = 'alert-error alert-success alert-info'; $(function () { var send_status = $('#send-status'); @@ -40,34 +39,11 @@ $(function () { } var zephyr_class = compose_class_name(); - var okay = true; - $.ajax({ - url: "subscriptions/exists/" + zephyr_class, - async: false, - success: function (data) { - if (data === "False") { - // The class doesn't exist - okay = false; - send_status.removeClass(status_classes); - send_status.show(); - $('#class-dne-name').text(zephyr_class); - $('#class-dne').show(); - $('#create-it').focus(); - buttons.removeAttr('disabled'); - hide_compose(); - } - $("#home-error").hide(); - }, - error: function (xhr) { - okay = false; - report_error("Error checking subscription", xhr, $("#home-error")); - $("#class").focus(); - buttons.removeAttr('disabled'); - } - }); - if (okay && class_list.indexOf(zephyr_class.toLowerCase()) === -1) { + if (!check_class_for_send(zephyr_class)) + return false; + + if (class_list.indexOf(zephyr_class.toLowerCase()) === -1) { // You're not subbed to the class - okay = false; send_status.removeClass(status_classes); send_status.show(); $('#class-nosub-name').text(zephyr_class); @@ -75,8 +51,10 @@ $(function () { $('#sub-it').focus(); buttons.removeAttr('disabled'); hide_compose(); + return false; } - return okay; + + return true; }, success: function (resp, statusText, xhr, form) { form.find('textarea').val('');