2012-10-18 20:29:16 +02:00
|
|
|
var compose = (function () {
|
2012-10-03 22:53:15 +02:00
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
var exports = {};
|
2012-10-19 19:51:19 +02:00
|
|
|
var is_composing_message = false;
|
2013-02-13 21:30:17 +01:00
|
|
|
var faded_to;
|
2012-10-18 20:29:16 +02:00
|
|
|
|
2012-11-26 19:10:05 +01:00
|
|
|
function show(tabname, focus_area) {
|
|
|
|
if (tabname === "stream") {
|
|
|
|
$('#private-message').hide();
|
|
|
|
$('#stream-message').show();
|
|
|
|
$("#stream_toggle").addClass("active");
|
|
|
|
$("#private_message_toggle").removeClass("active");
|
|
|
|
} else {
|
|
|
|
$('#private-message').show();
|
|
|
|
$('#stream-message').hide();
|
|
|
|
$("#stream_toggle").removeClass("active");
|
|
|
|
$("#private_message_toggle").addClass("active");
|
|
|
|
}
|
|
|
|
$("#send-status").removeClass(status_classes).hide();
|
|
|
|
$('#compose').css({visibility: "visible"});
|
|
|
|
$("#new_message_content").trigger("autosize");
|
2012-11-30 03:49:18 +01:00
|
|
|
$('.message_comp').slideDown(100, function () {
|
|
|
|
// If the compose box is obscuring the currently selected message,
|
|
|
|
// scroll up until the message is no longer occluded.
|
2013-02-20 18:26:50 +01:00
|
|
|
if (current_msg_list.selected_id() === -1) {
|
2012-12-05 19:27:31 +01:00
|
|
|
// If there's no selected message, there's no need to
|
|
|
|
// scroll the compose box to avoid it.
|
|
|
|
return;
|
|
|
|
}
|
2013-02-14 23:48:37 +01:00
|
|
|
var selected_row = current_msg_list.selected_row();
|
|
|
|
var cover = selected_row.offset().top + selected_row.height()
|
2012-11-30 03:49:18 +01:00
|
|
|
- $("#compose").offset().top;
|
|
|
|
if (cover > 0) {
|
|
|
|
disable_pointer_movement = true;
|
|
|
|
// We use $('html, body') because you can't animate window.scrollTop
|
|
|
|
// on Chrome (http://bugs.jquery.com/ticket/10419).
|
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: viewport.scrollTop() + cover + 5
|
|
|
|
}, {
|
|
|
|
complete: function () {
|
|
|
|
// The complete callback is actually called before the
|
|
|
|
// scrolling has completed, so we try to let scrolling
|
|
|
|
// finish before allowing pointer movements again or the
|
|
|
|
// pointer may still move.
|
|
|
|
setTimeout(function () {
|
|
|
|
disable_pointer_movement = false;
|
|
|
|
}, 50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-11-26 19:10:05 +01:00
|
|
|
focus_area.focus();
|
|
|
|
focus_area.select();
|
2013-01-30 21:49:56 +01:00
|
|
|
// Disable the notifications bar if it overlaps with the composebox
|
|
|
|
notifications_bar.maybe_disable();
|
2012-11-26 19:10:05 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 22:19:38 +01:00
|
|
|
// In an attempt to decrease mixing, make the composebox's
|
|
|
|
// stream bar look like what you're replying to.
|
|
|
|
// (In particular, if there's a color associated with it,
|
|
|
|
// have that color be reflected here too.)
|
|
|
|
exports.decorate_stream_bar = function (stream_name) {
|
|
|
|
var color = subs.get_color(stream_name);
|
2013-02-19 20:13:50 +01:00
|
|
|
$("#stream-message .message_header_stream")
|
|
|
|
.css('background-color', color)
|
|
|
|
.removeClass(subs.color_classes)
|
|
|
|
.addClass(subs.get_color_class(color));
|
2013-01-15 22:19:38 +01:00
|
|
|
};
|
|
|
|
|
2013-03-06 23:47:32 +01:00
|
|
|
function messages_with_different_recipients(target_message) {
|
|
|
|
var all_elts = rows.get_table(current_msg_list.table_name).find(".recipient_row, .messagebox");
|
|
|
|
var i, elts_to_fade = [];
|
|
|
|
var different_recipient = false;
|
|
|
|
// Note: The below algorithm relies on the fact that all_elts is
|
|
|
|
// sorted as it would be displayed in the message view
|
|
|
|
for (i = 0; i < all_elts.length; i++) {
|
|
|
|
var elt = $(all_elts[i]);
|
|
|
|
if (elt.hasClass("recipient_row")) {
|
|
|
|
if (!util.same_recipient(target_message, current_msg_list.get(rows.id(elt)))) {
|
|
|
|
elts_to_fade.push(elt);
|
|
|
|
different_recipient = true;
|
|
|
|
} else {
|
|
|
|
different_recipient = false;
|
|
|
|
}
|
|
|
|
} else if (different_recipient) {
|
|
|
|
elts_to_fade.push(elt);
|
2013-02-13 21:30:17 +01:00
|
|
|
}
|
2013-03-06 23:47:32 +01:00
|
|
|
}
|
|
|
|
return elts_to_fade;
|
2013-02-13 21:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function fade_around(reply_message) {
|
2013-03-06 23:47:32 +01:00
|
|
|
var i, fade_class = narrow.active() ? "message_reply_fade_narrowed" : "message_reply_fade";
|
|
|
|
var elts_to_fade = messages_with_different_recipients(reply_message);
|
2013-02-13 21:30:17 +01:00
|
|
|
|
2013-03-06 23:47:32 +01:00
|
|
|
faded_to = reply_message;
|
|
|
|
for (i = 0; i < elts_to_fade.length; i++) {
|
|
|
|
$(elts_to_fade[i]).addClass(fade_class);
|
|
|
|
}
|
2013-02-13 21:30:17 +01:00
|
|
|
ui.disable_floating_recipient_bar();
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.unfade_messages = function () {
|
|
|
|
if (faded_to === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var fade_class = narrow.active() ? "message_reply_fade_narrowed" : "message_reply_fade";
|
2013-03-06 23:47:32 +01:00
|
|
|
rows.get_table(current_msg_list.table_name).find(".recipient_row, .messagebox").removeClass(fade_class);
|
2013-02-13 21:30:17 +01:00
|
|
|
faded_to = undefined;
|
|
|
|
ui.enable_floating_recipient_bar();
|
|
|
|
};
|
|
|
|
|
2013-03-04 16:59:09 +01:00
|
|
|
exports.update_faded_messages = function () {
|
|
|
|
if (faded_to === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fade_around(faded_to);
|
|
|
|
};
|
|
|
|
|
2012-10-18 20:16:56 +02:00
|
|
|
exports.start = function (msg_type, opts) {
|
2012-11-26 19:30:11 +01:00
|
|
|
if (reload.is_in_progress()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-18 21:28:28 +01:00
|
|
|
compose.clear();
|
|
|
|
|
2013-02-27 19:24:56 +01:00
|
|
|
var default_opts = {
|
|
|
|
message_type: msg_type,
|
|
|
|
stream: '',
|
|
|
|
subject: '',
|
|
|
|
private_message_recipient: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set default parameters based on the current narrowed view.
|
|
|
|
narrow.set_compose_defaults(default_opts);
|
|
|
|
|
|
|
|
opts = $.extend(default_opts, opts);
|
2012-10-18 20:16:56 +02:00
|
|
|
|
2012-11-16 21:00:38 +01:00
|
|
|
compose.stream_name(opts.stream);
|
|
|
|
compose.subject(opts.subject);
|
|
|
|
compose.recipient(opts.private_message_recipient);
|
2012-12-05 17:29:56 +01:00
|
|
|
// If the user opens the compose box, types some text, and then clicks on a
|
|
|
|
// different stream/subject, we want to keep the text in the compose box
|
|
|
|
if (opts.message !== undefined) {
|
|
|
|
compose.message_content(opts.message);
|
|
|
|
}
|
2012-10-18 20:16:56 +02:00
|
|
|
|
2012-12-19 21:19:29 +01:00
|
|
|
ui.change_tab_to("#home");
|
2012-10-18 20:16:56 +02:00
|
|
|
|
2012-10-19 22:09:13 +02:00
|
|
|
var focus_area;
|
|
|
|
if (opts.stream && ! opts.subject) {
|
|
|
|
focus_area = 'subject';
|
2012-11-08 00:38:21 +01:00
|
|
|
} else if (opts.stream || opts.private_message_recipient) {
|
2012-10-19 22:09:13 +02:00
|
|
|
focus_area = 'new_message_content';
|
|
|
|
}
|
2012-10-19 19:51:19 +02:00
|
|
|
|
2012-10-19 22:09:13 +02:00
|
|
|
if (msg_type === 'stream') {
|
2012-11-26 19:10:05 +01:00
|
|
|
show('stream', $("#" + (focus_area || 'stream')));
|
2012-10-19 22:09:13 +02:00
|
|
|
} else {
|
2012-11-26 19:10:05 +01:00
|
|
|
show('private', $("#" + (focus_area || 'private_message_recipient')));
|
2012-10-18 20:16:56 +02:00
|
|
|
}
|
2012-10-19 22:09:13 +02:00
|
|
|
|
2013-02-13 21:30:17 +01:00
|
|
|
if (opts.replying_to_message !== undefined) {
|
|
|
|
if (exports.composing() && (faded_to !== opts.replying_to_message)) {
|
|
|
|
// Already faded to another message. First unfade everything.
|
|
|
|
exports.unfade_messages();
|
|
|
|
}
|
|
|
|
fade_around(opts.replying_to_message);
|
|
|
|
}
|
|
|
|
|
2012-10-19 19:51:19 +02:00
|
|
|
is_composing_message = msg_type;
|
2013-01-15 22:19:38 +01:00
|
|
|
exports.decorate_stream_bar(opts.stream);
|
2012-10-18 20:25:36 +02:00
|
|
|
$(document).trigger($.Event('compose_started.zephyr', opts));
|
2012-10-18 20:16:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.cancel = function () {
|
|
|
|
compose.hide();
|
2012-10-19 19:51:19 +02:00
|
|
|
is_composing_message = false;
|
2012-10-18 20:25:36 +02:00
|
|
|
$(document).trigger($.Event('compose_canceled.zephyr'));
|
2012-10-18 20:16:56 +02:00
|
|
|
};
|
|
|
|
|
2013-02-01 17:04:23 +01:00
|
|
|
function compose_error(error_text, bad_input) {
|
|
|
|
$('#send-status').removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.stop(true).fadeTo(0, 1);
|
2013-02-20 17:04:00 +01:00
|
|
|
$('#error-msg').html(error_text);
|
2013-02-01 17:04:23 +01:00
|
|
|
$("#compose-send-button").removeAttr('disabled');
|
2013-03-06 17:40:51 +01:00
|
|
|
$("#sending-indicator").hide();
|
2013-02-01 17:04:23 +01:00
|
|
|
bad_input.focus().select();
|
|
|
|
}
|
|
|
|
|
2012-10-29 18:06:53 +01:00
|
|
|
var send_options;
|
|
|
|
|
2012-11-07 20:26:24 +01:00
|
|
|
function send_message() {
|
2012-10-29 18:06:53 +01:00
|
|
|
var send_status = $('#send-status');
|
|
|
|
|
2012-11-07 20:26:24 +01:00
|
|
|
// TODO: this should be collapsed with the code in composebox_typeahead.js
|
|
|
|
var recipients = compose.recipient().split(/\s*[,;]\s*/);
|
|
|
|
|
|
|
|
var request = {client: 'website',
|
|
|
|
type: compose.composing(),
|
|
|
|
subject: compose.subject(),
|
|
|
|
content: compose.message_content()};
|
2012-11-14 23:21:46 +01:00
|
|
|
if (request.type === "private") {
|
|
|
|
request.to = JSON.stringify(recipients);
|
|
|
|
} else {
|
2013-02-13 18:29:07 +01:00
|
|
|
request.to = JSON.stringify([compose.stream_name()]);
|
2012-11-14 23:21:46 +01:00
|
|
|
}
|
2012-11-07 20:26:24 +01:00
|
|
|
|
2013-02-13 22:15:13 +01:00
|
|
|
if (tutorial.is_running()) {
|
|
|
|
// We make a new copy of the request object for the tutorial so that we
|
|
|
|
// don't mess up the request we're actually sending to the server
|
|
|
|
var tutorial_copy_of_message = $.extend({}, request, {to: compose.stream_name()});
|
|
|
|
if (request.type === "private") {
|
|
|
|
$.extend(tutorial_copy_of_message, {to: recipients});
|
|
|
|
}
|
|
|
|
tutorial.message_was_sent(tutorial_copy_of_message);
|
|
|
|
}
|
|
|
|
|
2012-11-07 20:26:24 +01:00
|
|
|
$.ajax({
|
2012-10-29 18:06:53 +01:00
|
|
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
2012-11-07 20:26:24 +01:00
|
|
|
url: '/json/send_message',
|
|
|
|
type: 'POST',
|
|
|
|
data: request,
|
|
|
|
success: function (resp, statusText, xhr) {
|
|
|
|
compose.clear();
|
2012-10-29 18:06:53 +01:00
|
|
|
send_status.hide();
|
2012-11-07 19:59:35 +01:00
|
|
|
is_composing_message = false;
|
2012-10-29 18:06:53 +01:00
|
|
|
compose.hide();
|
2012-10-31 21:17:07 +01:00
|
|
|
$("#compose-send-button").removeAttr('disabled');
|
2013-03-06 17:40:51 +01:00
|
|
|
$("#sending-indicator").hide();
|
2012-10-29 18:06:53 +01:00
|
|
|
},
|
|
|
|
error: function (xhr, error_type) {
|
2012-12-11 21:44:04 +01:00
|
|
|
if (error_type !== 'timeout' && reload.is_pending()) {
|
2012-10-29 18:06:53 +01:00
|
|
|
// The error might be due to the server changing
|
2012-10-29 21:02:46 +01:00
|
|
|
reload.initiate({immediate: true, send_after_reload: true});
|
2012-10-29 18:06:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var response = "Error sending message";
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
|
|
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
|
|
|
}
|
2013-02-01 17:04:23 +01:00
|
|
|
compose_error(response, $('#new_message_content'));
|
2012-10-29 18:06:53 +01:00
|
|
|
}
|
2012-11-07 20:26:24 +01:00
|
|
|
});
|
2012-10-29 18:06:53 +01:00
|
|
|
|
|
|
|
send_status.hide();
|
2012-11-07 20:26:24 +01:00
|
|
|
}
|
2012-10-29 18:06:53 +01:00
|
|
|
|
2012-10-18 20:16:56 +02:00
|
|
|
exports.finish = function () {
|
2012-10-29 22:37:34 +01:00
|
|
|
if (! compose.validate()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-07 20:26:24 +01:00
|
|
|
send_message();
|
2012-11-07 19:59:35 +01:00
|
|
|
// TODO: Do we want to fire the event even if the send failed due
|
|
|
|
// to a server-side error?
|
2012-10-18 20:25:36 +02:00
|
|
|
$(document).trigger($.Event('compose_finished.zephyr'));
|
2012-10-29 22:37:34 +01:00
|
|
|
return true;
|
2012-10-18 20:16:56 +02:00
|
|
|
};
|
|
|
|
|
2012-10-29 18:06:53 +01:00
|
|
|
$(function () {
|
|
|
|
$("#compose form").on("submit", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
compose.finish();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
exports.hide = function () {
|
2013-03-06 17:11:20 +01:00
|
|
|
$('.message_comp').find('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"});});
|
2013-01-30 21:49:56 +01:00
|
|
|
notifications_bar.enable();
|
2013-02-13 21:30:17 +01:00
|
|
|
exports.unfade_messages();
|
2012-10-18 20:29:16 +02:00
|
|
|
};
|
2012-10-04 00:04:58 +02:00
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
exports.clear = function () {
|
2012-10-09 23:56:16 +02:00
|
|
|
$("#compose").find('input[type=text], textarea').val('');
|
2012-10-18 20:29:16 +02:00
|
|
|
};
|
2012-10-03 21:44:07 +02:00
|
|
|
|
2012-11-29 20:35:24 +01:00
|
|
|
// Set the mode of a compose already in progress.
|
|
|
|
// Does not clear the input fields.
|
|
|
|
exports.set_mode = function (mode) {
|
2013-02-17 23:44:02 +01:00
|
|
|
ui.change_tab_to('#home');
|
2013-01-11 22:14:45 +01:00
|
|
|
if (!is_composing_message) {
|
|
|
|
exports.start(mode);
|
|
|
|
}
|
2012-11-29 20:35:24 +01:00
|
|
|
if (mode === 'private') {
|
2012-11-26 19:10:05 +01:00
|
|
|
show('private', $("#private_message_recipient"));
|
2012-11-26 19:04:22 +01:00
|
|
|
is_composing_message = "private";
|
2012-10-03 20:49:58 +02:00
|
|
|
} else {
|
2013-02-06 00:33:45 +01:00
|
|
|
show('stream', $("#stream"));
|
2012-11-26 19:04:22 +01:00
|
|
|
is_composing_message = "stream";
|
2012-10-03 20:49:58 +02:00
|
|
|
}
|
2012-10-18 20:29:16 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
exports.composing = function () {
|
2012-10-19 19:51:19 +02:00
|
|
|
return is_composing_message;
|
2012-10-18 20:29:16 +02:00
|
|
|
};
|
2012-10-11 20:30:34 +02:00
|
|
|
|
2013-01-29 00:28:56 +01:00
|
|
|
function get_or_set(fieldname, keep_outside_whitespace) {
|
2012-10-31 22:12:45 +01:00
|
|
|
// We can't hoist the assignment of 'elem' out of this lambda,
|
|
|
|
// because the DOM element might not exist yet when get_or_set
|
|
|
|
// is called.
|
|
|
|
return function (newval) {
|
|
|
|
var elem = $('#'+fieldname);
|
2013-01-29 00:28:56 +01:00
|
|
|
var oldval = elem.val();
|
2012-10-31 22:12:45 +01:00
|
|
|
if (newval !== undefined) {
|
|
|
|
elem.val(newval);
|
|
|
|
}
|
2013-01-29 00:28:56 +01:00
|
|
|
return keep_outside_whitespace ? oldval : $.trim(oldval);
|
2012-10-31 22:12:45 +01:00
|
|
|
};
|
|
|
|
}
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-31 22:12:45 +01:00
|
|
|
exports.stream_name = get_or_set('stream');
|
|
|
|
exports.subject = get_or_set('subject');
|
2013-01-29 00:28:56 +01:00
|
|
|
exports.message_content = get_or_set('new_message_content', true);
|
2012-11-08 00:38:21 +01:00
|
|
|
exports.recipient = get_or_set('private_message_recipient');
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-10 23:37:14 +02:00
|
|
|
// *Synchronously* check if a stream exists.
|
2013-01-31 21:03:45 +01:00
|
|
|
exports.check_stream_existence = function (stream_name) {
|
2012-11-15 19:13:33 +01:00
|
|
|
var result = "error";
|
2012-10-03 22:53:15 +02:00
|
|
|
$.ajax({
|
2012-10-16 22:10:48 +02:00
|
|
|
type: "POST",
|
2012-10-17 20:05:17 +02:00
|
|
|
url: "/json/subscriptions/exists",
|
|
|
|
data: {'stream': stream_name},
|
2012-10-03 22:53:15 +02:00
|
|
|
async: false,
|
|
|
|
success: function (data) {
|
2012-10-18 19:40:53 +02:00
|
|
|
if (!data.exists) {
|
2012-11-15 19:13:33 +01:00
|
|
|
result = "does-not-exist";
|
|
|
|
} else if (data.subscribed) {
|
|
|
|
result = "subscribed";
|
|
|
|
} else {
|
|
|
|
result = "not-subscribed";
|
2012-10-03 22:53:15 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2012-11-15 19:13:33 +01:00
|
|
|
result = "error";
|
2012-10-03 22:53:15 +02:00
|
|
|
}
|
|
|
|
});
|
2013-03-11 23:13:37 +01:00
|
|
|
return result;
|
2013-01-31 21:03:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks if a stream exists. If not, displays an error and returns
|
|
|
|
// false.
|
|
|
|
function check_stream_for_send(stream_name) {
|
2013-03-11 23:13:37 +01:00
|
|
|
var result = exports.check_stream_existence(stream_name);
|
2013-01-31 21:03:45 +01:00
|
|
|
|
|
|
|
if (result === "error") {
|
2013-03-11 23:09:22 +01:00
|
|
|
compose_error("Error checking subscription", $("#stream"));
|
2013-01-31 21:03:45 +01:00
|
|
|
$("#compose-send-button").removeAttr('disabled');
|
2013-03-06 17:40:51 +01:00
|
|
|
$("#sending-indicator").hide();
|
2013-01-31 21:03:45 +01:00
|
|
|
}
|
|
|
|
|
2012-11-15 19:13:33 +01:00
|
|
|
return result;
|
2012-10-03 22:53:15 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 23:37:14 +02:00
|
|
|
function validate_stream_message() {
|
2012-10-18 20:29:16 +02:00
|
|
|
var stream_name = exports.stream_name();
|
2012-10-10 23:28:31 +02:00
|
|
|
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-18 20:29:16 +02:00
|
|
|
if (exports.subject() === "") {
|
2012-10-30 21:47:43 +01:00
|
|
|
compose_error("Please specify a subject", $("#subject"));
|
2012-10-03 22:39:05 +02:00
|
|
|
return false;
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:04:23 +01:00
|
|
|
var response;
|
|
|
|
|
2012-10-18 21:37:07 +02:00
|
|
|
if (!subs.have(stream_name)) {
|
2012-11-15 19:13:33 +01:00
|
|
|
switch(check_stream_for_send(stream_name)) {
|
|
|
|
case "does-not-exist":
|
2013-02-20 17:04:00 +01:00
|
|
|
response = "<p>The stream <b>" +
|
|
|
|
Handlebars.Utils.escapeExpression(stream_name) + "</b> does not exist.</p>" +
|
|
|
|
"<p>Manage your subscriptions <a href='#subscriptions'>on your Streams page</a>.</p>";
|
2013-02-01 17:04:23 +01:00
|
|
|
compose_error(response, $('#stream'));
|
|
|
|
return false;
|
2012-11-15 19:13:33 +01:00
|
|
|
case "error":
|
|
|
|
return false;
|
|
|
|
case "subscribed":
|
|
|
|
// You're actually subscribed to the stream, but this
|
|
|
|
// browser window doesn't know it.
|
|
|
|
return true;
|
|
|
|
case "not-subscribed":
|
2013-02-20 17:04:00 +01:00
|
|
|
response = "<p>You're not subscribed to the stream <b>" +
|
|
|
|
Handlebars.Utils.escapeExpression(stream_name) + "</b>.</p>" +
|
|
|
|
"<p>Manage your subscriptions <a href='#subscriptions'>on your Streams page</a>.</p>";
|
2013-02-01 17:04:23 +01:00
|
|
|
compose_error(response, $('#stream'));
|
2012-10-18 19:26:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:39:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-08 00:38:21 +01:00
|
|
|
function validate_private_message() {
|
2012-10-18 20:29:16 +02:00
|
|
|
if (exports.recipient() === "") {
|
2012-11-08 00:38:21 +01:00
|
|
|
compose_error("Please specify at least one recipient", $("#private_message_recipient"));
|
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
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
exports.validate = function () {
|
2012-10-31 21:17:07 +01:00
|
|
|
$("#compose-send-button").attr('disabled', 'disabled').blur();
|
2013-03-06 17:40:51 +01:00
|
|
|
$("#sending-indicator").show();
|
2012-10-03 23:13:38 +02:00
|
|
|
|
2012-10-31 22:18:48 +01:00
|
|
|
if (exports.message_content() === "") {
|
|
|
|
compose_error("You have nothing to send!", $("#new_message_content"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-08 00:38:21 +01:00
|
|
|
if (exports.composing() === 'private') {
|
|
|
|
return validate_private_message();
|
2012-10-03 23:13:38 +02:00
|
|
|
} else {
|
2012-10-10 23:37:14 +02:00
|
|
|
return validate_stream_message();
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
2012-10-18 20:29:16 +02:00
|
|
|
};
|
|
|
|
|
2012-10-24 04:02:39 +02:00
|
|
|
$(function () {
|
|
|
|
$("#new_message_content").autosize();
|
|
|
|
});
|
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|