From a383985643419f85bc7b07a2dcf97cdd15c89783 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Fri, 17 Oct 2014 14:35:21 +0200 Subject: small refactoring --- web-ui/app/js/services/mail_service.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js index 4337da0e..1383f74e 100644 --- a/web-ui/app/js/services/mail_service.js +++ b/web-ui/app/js/services/mail_service.js @@ -50,23 +50,27 @@ define( }; this.updateTags = function (ev, data) { - var that = this; var ident = data.ident; + + var success = function (data) { + this.refreshResults(); + $(document).trigger(events.mail.tags.updated, { ident: ident, tags: data.tags }); + }; + + var failure = function (resp) { + var msg = i18n('Could not update mail tags'); + if (resp.status === 403) { + msg = i18n('Invalid tag name'); + } + this.trigger(document, events.ui.userAlerts.displayMessage, { message: msg }); + }; + $.ajax('/mail/' + ident + '/tags', { type: 'POST', contentType: 'application/json; charset=utf-8', data: JSON.stringify({newtags: data.tags}) - }).done(function (data) { - that.refreshResults(); - $(document).trigger(events.mail.tags.updated, { ident: ident, tags: data.tags }); - }) - .fail(function (resp) { - var msg = i18n('Could not update mail tags'); - if(resp.status === 403) { - msg = i18n('Invalid tag name'); - } - that.trigger(document, events.ui.userAlerts.displayMessage, { message: msg }); - }); + }).done(success.bind(this)).fail(failure.bind(this)); + }; this.readMail = function (ev, data) { -- cgit v1.2.3