2012-10-03 22:53:15 +02:00
|
|
|
var status_classes = 'alert-error alert-success alert-info';
|
|
|
|
|
2012-10-04 00:04:58 +02:00
|
|
|
function show_compose(tabname, focus_area) {
|
2012-10-09 19:53:21 +02:00
|
|
|
$('#zephyr_compose').css({visibility: "visible"});
|
2012-10-09 20:11:44 +02:00
|
|
|
$('.zephyr_comp').slideDown(100);
|
2012-10-04 00:04:58 +02:00
|
|
|
$('#zephyr-type-tabs a[href="#' + tabname + '-message"]').tab('show');
|
|
|
|
focus_area.focus();
|
|
|
|
focus_area.select();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hide_compose() {
|
|
|
|
$('input, textarea, button').blur();
|
2012-10-09 20:11:44 +02:00
|
|
|
$('.zephyr_comp').slideUp(100,
|
|
|
|
function() { $('#zephyr_compose').css({visibility: "hidden"});});
|
2012-10-04 00:04:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
function clear_compose_box() {
|
|
|
|
$("#zephyr_compose").find('input[type=text], textarea').val('');
|
|
|
|
}
|
|
|
|
|
2012-10-03 20:49:58 +02:00
|
|
|
function compose_button() {
|
|
|
|
clear_compose_box();
|
|
|
|
$('#sidebar a[href="#home"]').tab('show');
|
|
|
|
show_compose('class', $("#class"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_compose() {
|
|
|
|
if ($("#zephyr-type-tabs li.active").find("a[href=#class-message]").length !== 0) {
|
|
|
|
// In class tab, switch to personals.
|
2012-10-09 15:36:24 +02:00
|
|
|
show_compose('personal', $("#huddle_recipient"));
|
2012-10-03 20:49:58 +02:00
|
|
|
} else {
|
|
|
|
show_compose('class', $("#class"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function composing_class_message() {
|
|
|
|
return $("#class-message").is(":visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
function composing_huddle_message() {
|
|
|
|
return $("#personal-message").is(":visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
function compose_class_name() {
|
|
|
|
return $.trim($("#class").val());
|
|
|
|
}
|
|
|
|
|
|
|
|
function compose_instance() {
|
|
|
|
return $.trim($("#instance").val());
|
|
|
|
}
|
|
|
|
|
|
|
|
function compose_message() {
|
2012-10-09 23:43:53 +02:00
|
|
|
return $.trim($("#new_message_content").val());
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function compose_recipient() {
|
2012-10-09 15:36:24 +02:00
|
|
|
return $.trim($("#huddle_recipient").val());
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function compose_huddle_message() {
|
2012-10-09 23:43:53 +02:00
|
|
|
return $.trim($("#new_message_content").val());
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function compose_error(error_text, bad_input) {
|
|
|
|
$('#send-status').removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.text(error_text)
|
|
|
|
.stop(true).fadeTo(0, 1);
|
2012-10-05 23:42:58 +02:00
|
|
|
$('#zephyr_compose').find('input[type="submit"]').removeAttr('disabled');
|
2012-10-03 20:49:58 +02:00
|
|
|
bad_input.focus().select();
|
|
|
|
}
|
2012-10-03 22:39:05 +02:00
|
|
|
|
2012-10-03 23:04:36 +02:00
|
|
|
function submit_buttons() {
|
2012-10-05 23:42:58 +02:00
|
|
|
return $('#zephyr_compose').find('input[type="submit"]');
|
2012-10-03 23:04:36 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:53:15 +02:00
|
|
|
// *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;
|
2012-10-04 00:04:58 +02:00
|
|
|
$('#send-status').removeClass(status_classes).show();
|
2012-10-03 22:53:15 +02:00
|
|
|
$('#class-dne-name').text(class_name);
|
|
|
|
$('#class-dne').show();
|
2012-10-03 23:04:36 +02:00
|
|
|
submit_buttons().removeAttr('disabled');
|
2012-10-03 22:53:15 +02:00
|
|
|
hide_compose();
|
2012-10-09 20:06:56 +02:00
|
|
|
$('#create-it').focus();
|
2012-10-03 22:53:15 +02:00
|
|
|
}
|
|
|
|
$("#home-error").hide();
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
okay = false;
|
|
|
|
report_error("Error checking subscription", xhr, $("#home-error"));
|
|
|
|
$("#class").focus();
|
2012-10-03 23:04:36 +02:00
|
|
|
submit_buttons().removeAttr('disabled');
|
2012-10-03 22:53:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return okay;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:39:05 +02:00
|
|
|
function validate_class_message() {
|
2012-10-03 23:13:38 +02:00
|
|
|
var class_name = compose_class_name();
|
|
|
|
if (class_name === "") {
|
2012-10-03 22:39:05 +02:00
|
|
|
compose_error("Please specify a class", $("#class"));
|
|
|
|
return false;
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (compose_instance() === "") {
|
2012-10-03 22:39:05 +02:00
|
|
|
compose_error("Please specify an instance", $("#instance"));
|
|
|
|
return false;
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (compose_message() === "") {
|
2012-10-09 23:43:53 +02:00
|
|
|
compose_error("You have nothing to send!", $("#new_message_content"));
|
2012-10-03 22:39:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-03 23:13:38 +02:00
|
|
|
|
2012-10-04 00:04:58 +02:00
|
|
|
if (!check_class_for_send(class_name))
|
2012-10-03 23:13:38 +02:00
|
|
|
return false;
|
|
|
|
|
2012-10-09 21:01:41 +02:00
|
|
|
if (!subscribed_to(class_name)) {
|
2012-10-03 23:13:38 +02:00
|
|
|
// You're not subbed to the class
|
|
|
|
$('#send-status').removeClass(status_classes).show();
|
2012-10-04 00:04:58 +02:00
|
|
|
$('#class-nosub-name').text(class_name);
|
2012-10-03 23:13:38 +02:00
|
|
|
$('#class-nosub').show();
|
|
|
|
submit_buttons().removeAttr('disabled');
|
|
|
|
hide_compose();
|
2012-10-09 20:06:56 +02:00
|
|
|
$('#sub-it').focus();
|
2012-10-03 23:13:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:39:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function validate_huddle_message() {
|
|
|
|
if (compose_recipient() === "") {
|
2012-10-09 15:36:24 +02:00
|
|
|
compose_error("Please specify at least one recipient", $("#huddle_recipient"));
|
2012-10-03 22:39:05 +02:00
|
|
|
return false;
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (compose_huddle_message() === "") {
|
2012-10-09 23:43:53 +02:00
|
|
|
compose_error("You have nothing to send!", $("#new_message_content"));
|
2012-10-03 22:39:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-03 23:13:38 +02:00
|
|
|
|
2012-10-03 22:39:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-10-03 23:13:38 +02:00
|
|
|
|
|
|
|
function validate_message() {
|
|
|
|
submit_buttons().attr('disabled', 'disabled').blur();
|
|
|
|
|
|
|
|
if (composing_huddle_message()) {
|
|
|
|
return validate_huddle_message();
|
|
|
|
} else {
|
|
|
|
return validate_class_message();
|
|
|
|
}
|
|
|
|
}
|