summaryrefslogtreecommitdiff
path: root/web-ui/app/js/services/delete_service.js
blob: 7c6e8cc46063d735d6956ac511a44038edc44e92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*global _ */

define(['flight/lib/component', 'page/events', 'views/i18n'], function (defineComponent, events, i18n) {
  'use strict';

  return defineComponent(function() {

    this.successDeleteMessageFor = function(mail) {
      return mail.isInTrash() ?
        i18n('Your message was permanently deleted!') :
        i18n('Your message was moved to trash!');
    };

    this.successDeleteManyMessageFor = function(mail) {
      return mail.isInTrash() ?
        i18n('Your messages were permanently deleted!') :
        i18n('Your messages were moved to trash!');
    };

    this.deleteEmail = function (event, data) {
      this.trigger(document, events.mail.delete, {
        mail: data.mail,
        successMessage: this.successDeleteMessageFor(data.mail)
      });
    };

    this.deleteManyEmails = function (event, data) {
      var emails = _.values(data.checkedMails),
         firstEmail = emails[_.first(_.keys(emails))];

      this.trigger(document, events.mail.deleteMany, {
        mails: emails,
        successMessage: this.successDeleteManyMessageFor(firstEmail)
      });
    };

    this.after('initialize', function () {
      this.on(document, events.ui.mail.delete, this.deleteEmail);
      this.on(document, events.ui.mail.deleteMany, this.deleteManyEmails);
    });

  });
});