diff options
| author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-17 14:35:21 +0200 | 
|---|---|---|
| committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-17 14:35:21 +0200 | 
| commit | a383985643419f85bc7b07a2dcf97cdd15c89783 (patch) | |
| tree | cc25b2d622975b5cc137af156087d6949635fdd5 | |
| parent | 5991ead0ca32de2cdd8f1cf7c9628b3b1443ddec (diff) | |
small refactoring
| -rw-r--r-- | web-ui/app/js/services/mail_service.js | 28 | 
1 files 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) { | 
