mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Move more validation
(imported from commit 62d660a3c34f4aeb170771ee85580362a2c1b8a7)
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
var status_classes = 'alert-error alert-success alert-info';
|
||||||
|
|
||||||
function clear_compose_box() {
|
function clear_compose_box() {
|
||||||
$("#zephyr_compose").find('input[type=text], textarea').val('');
|
$("#zephyr_compose").find('input[type=text], textarea').val('');
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,37 @@ function compose_error(error_text, bad_input) {
|
|||||||
bad_input.focus().select();
|
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() {
|
function validate_class_message() {
|
||||||
if (compose_class_name() === "") {
|
if (compose_class_name() === "") {
|
||||||
compose_error("Please specify a class", $("#class"));
|
compose_error("Please specify a class", $("#class"));
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
var zephyr_array = [];
|
var zephyr_array = [];
|
||||||
var zephyr_dict = {};
|
var zephyr_dict = {};
|
||||||
var instance_list = [];
|
var instance_list = [];
|
||||||
var status_classes = 'alert-error alert-success alert-info';
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var send_status = $('#send-status');
|
var send_status = $('#send-status');
|
||||||
@@ -40,34 +39,11 @@ $(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var zephyr_class = compose_class_name();
|
var zephyr_class = compose_class_name();
|
||||||
var okay = true;
|
if (!check_class_for_send(zephyr_class))
|
||||||
$.ajax({
|
return false;
|
||||||
url: "subscriptions/exists/" + zephyr_class,
|
|
||||||
async: false,
|
if (class_list.indexOf(zephyr_class.toLowerCase()) === -1) {
|
||||||
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) {
|
|
||||||
// You're not subbed to the class
|
// You're not subbed to the class
|
||||||
okay = false;
|
|
||||||
send_status.removeClass(status_classes);
|
send_status.removeClass(status_classes);
|
||||||
send_status.show();
|
send_status.show();
|
||||||
$('#class-nosub-name').text(zephyr_class);
|
$('#class-nosub-name').text(zephyr_class);
|
||||||
@@ -75,8 +51,10 @@ $(function () {
|
|||||||
$('#sub-it').focus();
|
$('#sub-it').focus();
|
||||||
buttons.removeAttr('disabled');
|
buttons.removeAttr('disabled');
|
||||||
hide_compose();
|
hide_compose();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return okay;
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
success: function (resp, statusText, xhr, form) {
|
success: function (resp, statusText, xhr, form) {
|
||||||
form.find('textarea').val('');
|
form.find('textarea').val('');
|
||||||
|
|||||||
Reference in New Issue
Block a user