mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
Move still more validation
(imported from commit a98d145168abc743888fb4a88dc00c925f138b00)
This commit is contained in:
@@ -104,16 +104,36 @@ function check_class_for_send(class_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function validate_class_message() {
|
function validate_class_message() {
|
||||||
if (compose_class_name() === "") {
|
var class_name = compose_class_name();
|
||||||
|
if (class_name === "") {
|
||||||
compose_error("Please specify a class", $("#class"));
|
compose_error("Please specify a class", $("#class"));
|
||||||
return false;
|
return false;
|
||||||
} else if (compose_instance() === "") {
|
}
|
||||||
|
|
||||||
|
if (compose_instance() === "") {
|
||||||
compose_error("Please specify an instance", $("#instance"));
|
compose_error("Please specify an instance", $("#instance"));
|
||||||
return false;
|
return false;
|
||||||
} else if (compose_message() === "") {
|
}
|
||||||
|
|
||||||
|
if (compose_message() === "") {
|
||||||
compose_error("You have nothing to send!", $("#new_zephyr"));
|
compose_error("You have nothing to send!", $("#new_zephyr"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!check_class_for_send(zephyr_class))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (class_list.indexOf(zephyr_class.toLowerCase()) === -1) {
|
||||||
|
// You're not subbed to the class
|
||||||
|
$('#send-status').removeClass(status_classes).show();
|
||||||
|
$('#class-nosub-name').text(zephyr_class);
|
||||||
|
$('#class-nosub').show();
|
||||||
|
$('#sub-it').focus();
|
||||||
|
submit_buttons().removeAttr('disabled');
|
||||||
|
hide_compose();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +141,22 @@ function validate_huddle_message() {
|
|||||||
if (compose_recipient() === "") {
|
if (compose_recipient() === "") {
|
||||||
compose_error("Please specify at least one recipient", $("#recipient"));
|
compose_error("Please specify at least one recipient", $("#recipient"));
|
||||||
return false;
|
return false;
|
||||||
} else if (compose_huddle_message() === "") {
|
}
|
||||||
|
|
||||||
|
if (compose_huddle_message() === "") {
|
||||||
compose_error("You have nothing to send!", $("#new_personal_zephyr"));
|
compose_error("You have nothing to send!", $("#new_personal_zephyr"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validate_message() {
|
||||||
|
submit_buttons().attr('disabled', 'disabled').blur();
|
||||||
|
|
||||||
|
if (composing_huddle_message()) {
|
||||||
|
return validate_huddle_message();
|
||||||
|
} else {
|
||||||
|
return validate_class_message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,39 +17,7 @@ $(function () {
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
||||||
beforeSubmit: function (form, _options) {
|
beforeSubmit: validate_message,
|
||||||
send_status.hide();
|
|
||||||
buttons.attr('disabled', 'disabled');
|
|
||||||
buttons.blur();
|
|
||||||
|
|
||||||
// If validation fails, the validate function will pop up
|
|
||||||
// an error message.
|
|
||||||
|
|
||||||
// For huddles, all the logic is in validate_huddle_message.
|
|
||||||
if (composing_huddle_message())
|
|
||||||
return validate_huddle_message();
|
|
||||||
|
|
||||||
if (composing_class_message() && !validate_class_message())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var zephyr_class = compose_class_name();
|
|
||||||
if (!check_class_for_send(zephyr_class))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (class_list.indexOf(zephyr_class.toLowerCase()) === -1) {
|
|
||||||
// You're not subbed to the class
|
|
||||||
send_status.removeClass(status_classes);
|
|
||||||
send_status.show();
|
|
||||||
$('#class-nosub-name').text(zephyr_class);
|
|
||||||
$('#class-nosub').show();
|
|
||||||
$('#sub-it').focus();
|
|
||||||
buttons.removeAttr('disabled');
|
|
||||||
hide_compose();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
success: function (resp, statusText, xhr, form) {
|
success: function (resp, statusText, xhr, form) {
|
||||||
form.find('textarea').val('');
|
form.find('textarea').val('');
|
||||||
send_status.hide();
|
send_status.hide();
|
||||||
|
|||||||
Reference in New Issue
Block a user