mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
Use compose.finish() instead of manually calling ajaxSubmit() in multiple places
(imported from commit 3bbe4a03171d9eace413b576ae2c7ccf99141bf1)
This commit is contained in:
@@ -38,7 +38,7 @@ var globals =
|
|||||||
+ ' update_autocomplete autocomplete_needs_update'
|
+ ' update_autocomplete autocomplete_needs_update'
|
||||||
|
|
||||||
// zephyr.js
|
// zephyr.js
|
||||||
+ ' message_array message_dict'
|
+ ' message_array message_dict get_updates_params'
|
||||||
+ ' clear_table add_to_table subject_dict'
|
+ ' clear_table add_to_table subject_dict'
|
||||||
+ ' keep_pointer_in_view move_pointer_at_page_top_and_bottom'
|
+ ' keep_pointer_in_view move_pointer_at_page_top_and_bottom'
|
||||||
+ ' respond_to_message'
|
+ ' respond_to_message'
|
||||||
|
|||||||
@@ -49,12 +49,61 @@ exports.cancel = function () {
|
|||||||
$(document).trigger($.Event('compose_canceled.zephyr'));
|
$(document).trigger($.Event('compose_canceled.zephyr'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var send_options;
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
var send_status = $('#send-status');
|
||||||
|
var buttons = $('#compose').find('input[type="submit"]');
|
||||||
|
|
||||||
|
send_options = {
|
||||||
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
||||||
|
beforeSubmit: function () { compose.validate(); },
|
||||||
|
success: function (resp, statusText, xhr, form) {
|
||||||
|
form.find('textarea').val('');
|
||||||
|
send_status.hide();
|
||||||
|
compose.hide();
|
||||||
|
buttons.removeAttr('disabled');
|
||||||
|
},
|
||||||
|
error: function (xhr, error_type) {
|
||||||
|
if (error_type !== 'timeout' && get_updates_params.reload_pending) {
|
||||||
|
// The error might be due to the server changing
|
||||||
|
do_reload_app_preserving_compose(true);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
send_status.removeClass(status_classes)
|
||||||
|
.addClass('alert-error')
|
||||||
|
.text(response)
|
||||||
|
.append($('<span />')
|
||||||
|
.addClass('send-status-close').html('×')
|
||||||
|
.click(function () { send_status.stop(true).fadeOut(500); }))
|
||||||
|
.stop(true).fadeTo(0,1);
|
||||||
|
|
||||||
|
buttons.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
send_status.hide();
|
||||||
|
});
|
||||||
|
|
||||||
exports.finish = function () {
|
exports.finish = function () {
|
||||||
$("#compose form").ajaxSubmit();
|
$("#compose form").ajaxSubmit(send_options);
|
||||||
is_composing_message = false;
|
is_composing_message = false;
|
||||||
$(document).trigger($.Event('compose_finished.zephyr'));
|
$(document).trigger($.Event('compose_finished.zephyr'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$("#compose form").on("submit", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
compose.finish();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
exports.show = function (tabname, focus_area) {
|
exports.show = function (tabname, focus_area) {
|
||||||
if (reloading_app) {
|
if (reloading_app) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ exports.add_for_send = function (stream, prompt_button) {
|
|||||||
timeout: 10*60*1000, // 10 minutes in ms
|
timeout: 10*60*1000, // 10 minutes in ms
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
add_to_stream_list(response.data);
|
add_to_stream_list(response.data);
|
||||||
$("#compose form").ajaxSubmit();
|
compose.finish();
|
||||||
prompt_button.stop(true).fadeOut(500);
|
prompt_button.stop(true).fadeOut(500);
|
||||||
},
|
},
|
||||||
error: function (xhr, error_type, exn) {
|
error: function (xhr, error_type, exn) {
|
||||||
|
|||||||
@@ -17,46 +17,6 @@ var get_updates_params = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var i;
|
|
||||||
var send_status = $('#send-status');
|
|
||||||
var buttons = $('#compose').find('input[type="submit"]');
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
|
||||||
beforeSubmit: compose.validate,
|
|
||||||
success: function (resp, statusText, xhr, form) {
|
|
||||||
form.find('textarea').val('');
|
|
||||||
send_status.hide();
|
|
||||||
compose.hide();
|
|
||||||
buttons.removeAttr('disabled');
|
|
||||||
},
|
|
||||||
error: function (xhr, error_type) {
|
|
||||||
if (error_type !== 'timeout' && get_updates_params.reload_pending) {
|
|
||||||
// The error might be due to the server changing
|
|
||||||
do_reload_app_preserving_compose(true);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
send_status.removeClass(status_classes)
|
|
||||||
.addClass('alert-error')
|
|
||||||
.text(response)
|
|
||||||
.append($('<span />')
|
|
||||||
.addClass('send-status-close').html('×')
|
|
||||||
.click(function () { send_status.stop(true).fadeOut(500); }))
|
|
||||||
.stop(true).fadeTo(0,1);
|
|
||||||
|
|
||||||
buttons.removeAttr('disabled');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
send_status.hide();
|
|
||||||
$("#compose form").ajaxForm(options);
|
|
||||||
|
|
||||||
$.each(people_list, function (idx, person) {
|
$.each(people_list, function (idx, person) {
|
||||||
people_hash[person.email] = 1;
|
people_hash[person.email] = 1;
|
||||||
});
|
});
|
||||||
@@ -610,7 +570,7 @@ $(function () {
|
|||||||
huddle_recipient: vars.recipient,
|
huddle_recipient: vars.recipient,
|
||||||
message: vars.msg});
|
message: vars.msg});
|
||||||
if (send_now) {
|
if (send_now) {
|
||||||
$("#compose form").ajaxSubmit();
|
compose.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user