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-10 22:57:02 +02:00
|
|
|
$("#send-status").removeClass(status_classes).hide();
|
2012-10-09 23:56:16 +02:00
|
|
|
$('#compose').css({visibility: "visible"});
|
2012-10-10 00:06:04 +02:00
|
|
|
$('.message_comp').slideDown(100);
|
2012-10-09 23:46:41 +02:00
|
|
|
$('#message-type-tabs a[href="#' + tabname + '-message"]').tab('show');
|
2012-10-04 00:04:58 +02:00
|
|
|
focus_area.focus();
|
|
|
|
focus_area.select();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hide_compose() {
|
|
|
|
$('input, textarea, button').blur();
|
2012-10-10 00:06:04 +02:00
|
|
|
$('.message_comp').slideUp(100,
|
2012-10-09 23:56:16 +02:00
|
|
|
function() { $('#compose').css({visibility: "hidden"});});
|
2012-10-04 00:04:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
function clear_compose_box() {
|
2012-10-09 23:56:16 +02:00
|
|
|
$("#compose").find('input[type=text], textarea').val('');
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 20:49:58 +02:00
|
|
|
function compose_button() {
|
|
|
|
clear_compose_box();
|
|
|
|
$('#sidebar a[href="#home"]').tab('show');
|
2012-10-10 23:33:38 +02:00
|
|
|
show_compose('stream', $("#stream"));
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_compose() {
|
2012-10-10 23:29:02 +02:00
|
|
|
if ($("#message-type-tabs li.active").find("a[href=#stream-message]").length !== 0) {
|
2012-10-10 23:37:14 +02:00
|
|
|
// In stream 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 {
|
2012-10-10 23:33:38 +02:00
|
|
|
show_compose('stream', $("#stream"));
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-10 23:37:14 +02:00
|
|
|
function composing_stream_message() {
|
2012-10-10 23:29:02 +02:00
|
|
|
return $("#stream-message").is(":visible");
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function composing_huddle_message() {
|
|
|
|
return $("#personal-message").is(":visible");
|
|
|
|
}
|
|
|
|
|
2012-10-11 20:30:34 +02:00
|
|
|
function composing_message() {
|
|
|
|
return composing_stream_message() || composing_huddle_message();
|
|
|
|
}
|
|
|
|
|
2012-10-16 21:12:52 +02:00
|
|
|
function compose_stream_name(newval) {
|
|
|
|
var oldval = $.trim($("#stream").val());
|
|
|
|
if (newval !== undefined) {
|
|
|
|
$("#stream").val(newval);
|
|
|
|
}
|
|
|
|
return oldval;
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:12:52 +02:00
|
|
|
function compose_subject(newval) {
|
|
|
|
var oldval = $.trim($("#subject").val());
|
|
|
|
if (newval !== undefined) {
|
|
|
|
$("#subject").val(newval);
|
|
|
|
}
|
|
|
|
return oldval;
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:12:52 +02:00
|
|
|
function compose_message(newval) {
|
|
|
|
var oldval = $.trim($("#new_message_content").val());
|
|
|
|
if (newval !== undefined) {
|
|
|
|
$("#new_message_content").val(newval);
|
|
|
|
}
|
|
|
|
return oldval;
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:12:52 +02:00
|
|
|
function compose_recipient(newval) {
|
|
|
|
var oldval = $.trim($("#huddle_recipient").val());
|
|
|
|
if (newval !== undefined) {
|
|
|
|
$("#huddle_recipient").val(newval);
|
|
|
|
}
|
|
|
|
return oldval;
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:12:52 +02:00
|
|
|
function compose_huddle_message(newval) {
|
|
|
|
return compose_message(newval);
|
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-09 23:56:16 +02:00
|
|
|
$('#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-09 23:56:16 +02:00
|
|
|
return $('#compose').find('input[type="submit"]');
|
2012-10-03 23:04:36 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 23:37:14 +02:00
|
|
|
// *Synchronously* check if a stream exists.
|
2012-10-03 22:53:15 +02:00
|
|
|
// If not, displays an error and returns false.
|
2012-10-10 23:37:14 +02:00
|
|
|
function check_stream_for_send(stream_name) {
|
2012-10-03 22:53:15 +02:00
|
|
|
var okay = true;
|
|
|
|
$.ajax({
|
2012-10-10 23:28:31 +02:00
|
|
|
url: "subscriptions/exists/" + stream_name,
|
2012-10-03 22:53:15 +02:00
|
|
|
async: false,
|
|
|
|
success: function (data) {
|
|
|
|
if (data === "False") {
|
2012-10-10 23:37:14 +02:00
|
|
|
// The stream doesn't exist
|
2012-10-03 22:53:15 +02:00
|
|
|
okay = false;
|
2012-10-04 00:04:58 +02:00
|
|
|
$('#send-status').removeClass(status_classes).show();
|
2012-10-10 23:33:38 +02:00
|
|
|
$('#stream-dne-name').text(stream_name);
|
|
|
|
$('#stream-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"));
|
2012-10-10 23:33:38 +02:00
|
|
|
$("#stream").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-10 23:37:14 +02:00
|
|
|
function validate_stream_message() {
|
2012-10-10 23:28:31 +02:00
|
|
|
var stream_name = compose_stream_name();
|
|
|
|
if (stream_name === "") {
|
2012-10-10 23:37:14 +02:00
|
|
|
compose_error("Please specify a stream", $("#stream"));
|
2012-10-03 22:39:05 +02:00
|
|
|
return false;
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
2012-10-11 00:01:39 +02:00
|
|
|
if (compose_subject() === "") {
|
|
|
|
compose_error("Please specify an subject", $("#subject"));
|
2012-10-03 22:39:05 +02:00
|
|
|
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-10 23:37:14 +02:00
|
|
|
if (!check_stream_for_send(stream_name))
|
2012-10-03 23:13:38 +02:00
|
|
|
return false;
|
|
|
|
|
2012-10-10 23:28:31 +02:00
|
|
|
if (!subscribed_to(stream_name)) {
|
2012-10-10 23:37:14 +02:00
|
|
|
// You're not subbed to the stream
|
2012-10-03 23:13:38 +02:00
|
|
|
$('#send-status').removeClass(status_classes).show();
|
2012-10-10 23:33:38 +02:00
|
|
|
$('#stream-nosub-name').text(stream_name);
|
|
|
|
$('#stream-nosub').show();
|
2012-10-03 23:13:38 +02:00
|
|
|
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 {
|
2012-10-10 23:37:14 +02:00
|
|
|
return validate_stream_message();
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
}
|