mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
stream_create: Convert stream_name_error to an ES6 class.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
3319848768
commit
30e4b51731
@@ -39,28 +39,26 @@ class StreamSubscriptionError {
|
|||||||
}
|
}
|
||||||
const stream_subscription_error = new StreamSubscriptionError();
|
const stream_subscription_error = new StreamSubscriptionError();
|
||||||
|
|
||||||
const stream_name_error = (function () {
|
class StreamNameError {
|
||||||
const self = {};
|
report_already_exists() {
|
||||||
|
|
||||||
self.report_already_exists = function () {
|
|
||||||
$("#stream_name_error").text(i18n.t("A stream with this name already exists"));
|
$("#stream_name_error").text(i18n.t("A stream with this name already exists"));
|
||||||
$("#stream_name_error").show();
|
$("#stream_name_error").show();
|
||||||
};
|
}
|
||||||
|
|
||||||
self.clear_errors = function () {
|
clear_errors() {
|
||||||
$("#stream_name_error").hide();
|
$("#stream_name_error").hide();
|
||||||
};
|
}
|
||||||
|
|
||||||
self.report_empty_stream = function () {
|
report_empty_stream() {
|
||||||
$("#stream_name_error").text(i18n.t("A stream needs to have a name"));
|
$("#stream_name_error").text(i18n.t("A stream needs to have a name"));
|
||||||
$("#stream_name_error").show();
|
$("#stream_name_error").show();
|
||||||
};
|
}
|
||||||
|
|
||||||
self.select = function () {
|
select() {
|
||||||
$("#create_stream_name").trigger("focus").trigger("select");
|
$("#create_stream_name").trigger("focus").trigger("select");
|
||||||
};
|
}
|
||||||
|
|
||||||
self.pre_validate = function (stream_name) {
|
pre_validate(stream_name) {
|
||||||
// Don't worry about empty strings...we just want to call this
|
// Don't worry about empty strings...we just want to call this
|
||||||
// to warn users early before they start doing too much work
|
// to warn users early before they start doing too much work
|
||||||
// after they make the effort to type in a stream name. (The
|
// after they make the effort to type in a stream name. (The
|
||||||
@@ -69,23 +67,23 @@ const stream_name_error = (function () {
|
|||||||
// the public streams that I'm not subscribed to yet. Once I
|
// the public streams that I'm not subscribed to yet. Once I
|
||||||
// realize the stream already exists, I may want to cancel.)
|
// realize the stream already exists, I may want to cancel.)
|
||||||
if (stream_name && stream_data.get_sub(stream_name)) {
|
if (stream_name && stream_data.get_sub(stream_name)) {
|
||||||
self.report_already_exists();
|
this.report_already_exists();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.clear_errors();
|
this.clear_errors();
|
||||||
};
|
}
|
||||||
|
|
||||||
self.validate_for_submit = function (stream_name) {
|
validate_for_submit(stream_name) {
|
||||||
if (!stream_name) {
|
if (!stream_name) {
|
||||||
self.report_empty_stream();
|
this.report_empty_stream();
|
||||||
self.select();
|
this.select();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream_data.get_sub(stream_name)) {
|
if (stream_data.get_sub(stream_name)) {
|
||||||
self.report_already_exists();
|
this.report_already_exists();
|
||||||
self.select();
|
this.select();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,10 +92,9 @@ const stream_name_error = (function () {
|
|||||||
// however, that there's some invite-only stream that we don't
|
// however, that there's some invite-only stream that we don't
|
||||||
// know about locally that will cause a name collision.)
|
// know about locally that will cause a name collision.)
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return self;
|
const stream_name_error = new StreamNameError();
|
||||||
})();
|
|
||||||
|
|
||||||
// Within the new stream modal...
|
// Within the new stream modal...
|
||||||
function update_announce_stream_state() {
|
function update_announce_stream_state() {
|
||||||
|
|||||||
Reference in New Issue
Block a user