Move still more validation

(imported from commit a98d145168abc743888fb4a88dc00c925f138b00)
This commit is contained in:
Keegan McAllister 2012-10-03 17:13:38 -04:00
parent 2508e87d03
commit 8e47b33645
2 changed files with 38 additions and 37 deletions

View File

@ -104,16 +104,36 @@ function check_class_for_send(class_name) {
}
function validate_class_message() {
if (compose_class_name() === "") {
var class_name = compose_class_name();
if (class_name === "") {
compose_error("Please specify a class", $("#class"));
return false;
} else if (compose_instance() === "") {
}
if (compose_instance() === "") {
compose_error("Please specify an instance", $("#instance"));
return false;
} else if (compose_message() === "") {
}
if (compose_message() === "") {
compose_error("You have nothing to send!", $("#new_zephyr"));
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;
}
@ -121,9 +141,22 @@ function validate_huddle_message() {
if (compose_recipient() === "") {
compose_error("Please specify at least one recipient", $("#recipient"));
return false;
} else if (compose_huddle_message() === "") {
}
if (compose_huddle_message() === "") {
compose_error("You have nothing to send!", $("#new_personal_zephyr"));
return false;
}
return true;
}
function validate_message() {
submit_buttons().attr('disabled', 'disabled').blur();
if (composing_huddle_message()) {
return validate_huddle_message();
} else {
return validate_class_message();
}
}

View File

@ -17,39 +17,7 @@ $(function () {
var options = {
dataType: 'json', // This seems to be ignored. We still get back an xhr.
beforeSubmit: function (form, _options) {
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;
},
beforeSubmit: validate_message,
success: function (resp, statusText, xhr, form) {
form.find('textarea').val('');
send_status.hide();