From ce0c43329b475ee4057911fbc2520d715d812ab0 Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Thu, 31 Jan 2013 15:03:45 -0500 Subject: [PATCH] compose: split check_stream_for_send into into request and UI response functions. In preparation for re-using the /json/subscriptions/exists request on the subscriptions page. (imported from commit 76eca95b952c4b60e583a050be711023ee5fedac) --- zephyr/static/js/compose.js | 42 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/zephyr/static/js/compose.js b/zephyr/static/js/compose.js index 3b2ff1f578..049c2b7e8d 100644 --- a/zephyr/static/js/compose.js +++ b/zephyr/static/js/compose.js @@ -248,9 +248,9 @@ function compose_error(error_text, bad_input) { } // *Synchronously* check if a stream exists. -// If not, displays an error and returns false. -function check_stream_for_send(stream_name) { +exports.check_stream_existence = function (stream_name) { var result = "error"; + var error_xhr = ""; $.ajax({ type: "POST", url: "/json/subscriptions/exists", @@ -260,26 +260,44 @@ function check_stream_for_send(stream_name) { if (!data.exists) { // The stream doesn't exist result = "does-not-exist"; - $('#send-status').removeClass(status_classes); - $('#stream-dne-name').text(stream_name); - $('#stream-dne').show(); - $("#compose-send-button").removeAttr('disabled'); - exports.hide(); - $('#create-it').focus(); } else if (data.subscribed) { result = "subscribed"; } else { result = "not-subscribed"; } - $("#home-error").hide(); }, error: function (xhr) { result = "error"; - ui.report_error("Error checking subscription", xhr, $("#home-error")); - $("#stream").focus(); - $("#compose-send-button").removeAttr('disabled'); + error_xhr = xhr; } }); + return [result, error_xhr]; +}; + + +// Checks if a stream exists. If not, displays an error and returns +// false. +function check_stream_for_send(stream_name) { + var stream_check = exports.check_stream_existence(stream_name); + var result = stream_check[0]; + var xhr = stream_check[1]; + + if (result === "error") { + ui.report_error("Error checking subscription", xhr, $("#home-error")); + $("#stream").focus(); + $("#compose-send-button").removeAttr('disabled'); + } else { + if (result === "does-not-exist") { + $('#send-status').removeClass(status_classes); + $('#stream-dne-name').text(stream_name); + $('#stream-dne').show(); + $("#compose-send-button").removeAttr('disabled'); + exports.hide(); + $('#create-it').focus(); + } + $("#home-error").hide(); + } + return result; }