2017-04-15 01:15:59 +02:00
|
|
|
var compose_state = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var message_type = false; // 'stream', 'private', or false-y
|
|
|
|
|
|
|
|
exports.set_message_type = function (msg_type) {
|
|
|
|
message_type = msg_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_message_type = function () {
|
|
|
|
return message_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.composing = function () {
|
2017-04-24 20:35:26 +02:00
|
|
|
// This is very similar to get_message_type(), but it returns
|
|
|
|
// a boolean.
|
|
|
|
return !!message_type;
|
2017-04-15 01:15:59 +02:00
|
|
|
};
|
|
|
|
|
2017-09-18 21:54:06 +02:00
|
|
|
exports.focus_in_empty_compose = function () {
|
|
|
|
return (
|
|
|
|
exports.composing() &&
|
|
|
|
exports.message_content() === "" &&
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').is(':focus'));
|
2017-09-18 21:54:06 +02:00
|
|
|
};
|
|
|
|
|
2017-04-15 01:15:59 +02:00
|
|
|
function get_or_set(fieldname, keep_leading_whitespace) {
|
|
|
|
// 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) {
|
2018-06-04 21:13:07 +02:00
|
|
|
var elem = $('#' + fieldname);
|
2017-04-15 01:15:59 +02:00
|
|
|
var oldval = elem.val();
|
|
|
|
if (newval !== undefined) {
|
|
|
|
elem.val(newval);
|
|
|
|
}
|
|
|
|
return keep_leading_whitespace ? util.rtrim(oldval) : $.trim(oldval);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Break out setters and getter into their own functions.
|
|
|
|
exports.stream_name = get_or_set('stream');
|
|
|
|
exports.subject = get_or_set('subject');
|
2017-11-26 20:37:44 +01:00
|
|
|
// We can't trim leading whitespace in `compose_textarea` because
|
2017-04-15 01:15:59 +02:00
|
|
|
// of the indented syntax for multi-line code blocks.
|
2017-11-26 20:37:44 +01:00
|
|
|
exports.message_content = get_or_set('compose-textarea', true);
|
2018-03-06 15:07:55 +01:00
|
|
|
exports.recipient = function (value) {
|
|
|
|
if (typeof value === "string") {
|
|
|
|
compose_pm_pill.set_from_emails(value);
|
|
|
|
} else {
|
|
|
|
return compose_pm_pill.get_emails();
|
|
|
|
}
|
|
|
|
};
|
2017-04-15 01:15:59 +02:00
|
|
|
|
|
|
|
exports.has_message_content = function () {
|
|
|
|
return exports.message_content() !== "";
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = compose_state;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.compose_state = compose_state;
|