mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
compose: Remove duplicated code in getters / setters
(imported from commit 3a17ef6fbcf9b8b4a31a54656152a1d37dea4fa0)
This commit is contained in:
@@ -159,37 +159,24 @@ exports.composing = function () {
|
|||||||
return is_composing_message;
|
return is_composing_message;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.stream_name = function (newval) {
|
function get_or_set(fieldname) {
|
||||||
var oldval = $.trim($("#stream").val());
|
// 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);
|
||||||
|
var oldval = $.trim(elem.val());
|
||||||
if (newval !== undefined) {
|
if (newval !== undefined) {
|
||||||
$("#stream").val(newval);
|
elem.val(newval);
|
||||||
}
|
}
|
||||||
return oldval;
|
return oldval;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
exports.subject = function (newval) {
|
exports.stream_name = get_or_set('stream');
|
||||||
var oldval = $.trim($("#subject").val());
|
exports.subject = get_or_set('subject');
|
||||||
if (newval !== undefined) {
|
exports.message_content = get_or_set('new_message_content');
|
||||||
$("#subject").val(newval);
|
exports.recipient = get_or_set('huddle_recipient');
|
||||||
}
|
|
||||||
return oldval;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.message_content = function (newval) {
|
|
||||||
var oldval = $.trim($("#new_message_content").val());
|
|
||||||
if (newval !== undefined) {
|
|
||||||
$("#new_message_content").val(newval);
|
|
||||||
}
|
|
||||||
return oldval;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.recipient = function (newval) {
|
|
||||||
var oldval = $.trim($("#huddle_recipient").val());
|
|
||||||
if (newval !== undefined) {
|
|
||||||
$("#huddle_recipient").val(newval);
|
|
||||||
}
|
|
||||||
return oldval;
|
|
||||||
};
|
|
||||||
|
|
||||||
function compose_error(error_text, bad_input) {
|
function compose_error(error_text, bad_input) {
|
||||||
$('#send-status').removeClass(status_classes)
|
$('#send-status').removeClass(status_classes)
|
||||||
|
|||||||
Reference in New Issue
Block a user