mirror of https://github.com/zulip/zulip.git
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)
This commit is contained in:
parent
018f45d151
commit
ce0c43329b
|
@ -248,9 +248,9 @@ function compose_error(error_text, bad_input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// *Synchronously* check if a stream exists.
|
// *Synchronously* check if a stream exists.
|
||||||
// If not, displays an error and returns false.
|
exports.check_stream_existence = function (stream_name) {
|
||||||
function check_stream_for_send(stream_name) {
|
|
||||||
var result = "error";
|
var result = "error";
|
||||||
|
var error_xhr = "";
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/json/subscriptions/exists",
|
url: "/json/subscriptions/exists",
|
||||||
|
@ -260,26 +260,44 @@ function check_stream_for_send(stream_name) {
|
||||||
if (!data.exists) {
|
if (!data.exists) {
|
||||||
// The stream doesn't exist
|
// The stream doesn't exist
|
||||||
result = "does-not-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) {
|
} else if (data.subscribed) {
|
||||||
result = "subscribed";
|
result = "subscribed";
|
||||||
} else {
|
} else {
|
||||||
result = "not-subscribed";
|
result = "not-subscribed";
|
||||||
}
|
}
|
||||||
$("#home-error").hide();
|
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
result = "error";
|
result = "error";
|
||||||
ui.report_error("Error checking subscription", xhr, $("#home-error"));
|
error_xhr = xhr;
|
||||||
$("#stream").focus();
|
|
||||||
$("#compose-send-button").removeAttr('disabled');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue