mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
Use plain $.ajax instead of jquery.form for sending messages
(imported from commit 46651224dfb0b1b3b4903b30cba5385025da173c)
This commit is contained in:
@@ -51,24 +51,31 @@ exports.cancel = function () {
|
|||||||
|
|
||||||
var send_options;
|
var send_options;
|
||||||
|
|
||||||
$(function () {
|
function send_message() {
|
||||||
var send_status = $('#send-status');
|
var send_status = $('#send-status');
|
||||||
|
|
||||||
send_options = {
|
|
||||||
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
|
||||||
beforeSubmit: function (arr, form, options) {
|
|
||||||
$.each(arr, function (idx, elem) {
|
|
||||||
if (elem.name === 'recipient') {
|
|
||||||
var recipients = elem.value;
|
|
||||||
// TODO: this should be collapsed with the code in composebox_typeahead.js
|
// TODO: this should be collapsed with the code in composebox_typeahead.js
|
||||||
recipients = recipients.split(/\s*[,;]\s*/);
|
var recipients = compose.recipient().split(/\s*[,;]\s*/);
|
||||||
elem.value = JSON.stringify(recipients);
|
|
||||||
|
var request = {client: 'website',
|
||||||
|
type: compose.composing(),
|
||||||
|
stream: compose.stream_name(),
|
||||||
|
subject: compose.subject(),
|
||||||
|
recipient: JSON.stringify(recipients),
|
||||||
|
content: compose.message_content()};
|
||||||
|
|
||||||
|
// TODO: this is just dumb
|
||||||
|
if (request.type === 'huddle') {
|
||||||
|
request.type = 'personal';
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return true;
|
$.ajax({
|
||||||
},
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
||||||
success: function (resp, statusText, xhr, form) {
|
url: '/json/send_message',
|
||||||
form.find('textarea').val('');
|
type: 'POST',
|
||||||
|
data: request,
|
||||||
|
success: function (resp, statusText, xhr) {
|
||||||
|
compose.clear();
|
||||||
send_status.hide();
|
send_status.hide();
|
||||||
is_composing_message = false;
|
is_composing_message = false;
|
||||||
compose.hide();
|
compose.hide();
|
||||||
@@ -96,16 +103,16 @@ $(function () {
|
|||||||
|
|
||||||
$("#compose-send-button").removeAttr('disabled');
|
$("#compose-send-button").removeAttr('disabled');
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
send_status.hide();
|
send_status.hide();
|
||||||
});
|
}
|
||||||
|
|
||||||
exports.finish = function () {
|
exports.finish = function () {
|
||||||
if (! compose.validate()) {
|
if (! compose.validate()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$("#compose form").ajaxSubmit(send_options);
|
send_message();
|
||||||
// TODO: Do we want to fire the event even if the send failed due
|
// TODO: Do we want to fire the event even if the send failed due
|
||||||
// to a server-side error?
|
// to a server-side error?
|
||||||
$(document).trigger($.Event('compose_finished.zephyr'));
|
$(document).trigger($.Event('compose_finished.zephyr'));
|
||||||
@@ -158,7 +165,6 @@ exports.set_message_type = function (tabname) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.toggle_mode = function () {
|
exports.toggle_mode = function () {
|
||||||
if ($("#message-type-tabs li.active").find("a[href=#stream-message]").length !== 0) {
|
if ($("#message-type-tabs li.active").find("a[href=#stream-message]").length !== 0) {
|
||||||
// In stream tab, switch to personals.
|
// In stream tab, switch to personals.
|
||||||
|
|||||||
Reference in New Issue
Block a user