summaryrefslogtreecommitdiff
path: root/web-ui/app/js
diff options
context:
space:
mode:
Diffstat (limited to 'web-ui/app/js')
-rw-r--r--web-ui/app/js/helpers/monitored_ajax.js4
-rw-r--r--web-ui/app/js/mail_view/data/mail_sender.js32
2 files changed, 8 insertions, 28 deletions
diff --git a/web-ui/app/js/helpers/monitored_ajax.js b/web-ui/app/js/helpers/monitored_ajax.js
index 0f851c7a..0068e10c 100644
--- a/web-ui/app/js/helpers/monitored_ajax.js
+++ b/web-ui/app/js/helpers/monitored_ajax.js
@@ -51,7 +51,9 @@ define(['page/events', 'views/i18n'], function (events, i18n) {
return $.ajax(url, config).fail(function (xmlhttprequest, textstatus, message) {
if (!config.skipErrorMessage) {
- var msg = messages[textstatus] || 'unexpected problem while talking to server';
+ var msg = (xmlhttprequest.responseJSON && xmlhttprequest.responseJSON.message) ||
+ messages[textstatus] ||
+ 'unexpected problem while talking to server';
on.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n(msg) });
}
}.bind(this));
diff --git a/web-ui/app/js/mail_view/data/mail_sender.js b/web-ui/app/js/mail_view/data/mail_sender.js
index 834cb205..4c7e07ea 100644
--- a/web-ui/app/js/mail_view/data/mail_sender.js
+++ b/web-ui/app/js/mail_view/data/mail_sender.js
@@ -40,43 +40,22 @@ define(
};
}
- function failure(on, context) {
- return function(xhr, status, error) {
- var contextMessage = '';
-
- if (context) {
- contextMessage = context + ': ';
- }
-
- if (xhr.status === 422) {
- return; // ignore the fact that it failed to save the draft - it will succeed eventually
- }
-
- if (xhr && xhr.responseJSON && xhr.responseJSON.message) {
- on.trigger(document, events.ui.userAlerts.displayMessage, {message: contextMessage + xhr.responseJSON.message});
- } else {
- on.trigger(document, events.ui.userAlerts.displayMessage, {message: 'Ops! something went wrong, try again later.'});
- }
- on.trigger(document, events.mail.send_failed, {xhr: xhr, error:error});
- };
- }
-
this.defaultAttrs({
mailsResource: '/mails'
});
this.sendMail = function(event, data) {
- monitoredAjax(this, this.attr.mailsResource, {
+ monitoredAjax.call(_, this, this.attr.mailsResource, {
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
- }).done(successSendMail(this))
- .fail(failure(this, 'Error sending mail'));
+ }).done(successSendMail(this));
+
};
this.saveMail = function(mail) {
- return monitoredAjax(this, this.attr.mailsResource, {
+ return monitoredAjax.call(_, this, this.attr.mailsResource, {
type: 'PUT',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
@@ -88,8 +67,7 @@ define(
this.saveDraft = function(event, data) {
this.saveMail(data)
- .done(successSaveDraft(this))
- .fail(failure(this));
+ .done(successSaveDraft(this));
};
this.saveMailWithCallback = function(event, data) {