From e5b4ca353863a600a8d6151090b83f3210720a47 Mon Sep 17 00:00:00 2001 From: Roberto Soares Date: Thu, 9 Apr 2015 15:58:22 -0300 Subject: listening event 'recoverMany' --- web-ui/app/js/services/mail_service.js | 26 +++++++++++++++++++++ web-ui/app/js/services/recover_service.js | 39 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 web-ui/app/js/services/recover_service.js (limited to 'web-ui/app/js/services') diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js index 1fa41619..04194964 100644 --- a/web-ui/app/js/services/mail_service.js +++ b/web-ui/app/js/services/mail_service.js @@ -123,6 +123,16 @@ define( }, this); }; + this.triggerRecovered = function (dataToRecover) { + return _.bind(function () { + var mails = dataToRecover.mails || [dataToRecover.mail]; + + this.refreshMails(); + this.trigger(document, events.ui.userAlerts.displayMessage, { message: dataToRecover.successMessage}); + this.trigger(document, events.ui.mails.uncheckAll); + }, this); + }; + this.deleteMail = function (ev, data) { monitoredAjax(this, '/mail/' + data.mail.ident, {type: 'DELETE'}) @@ -145,6 +155,21 @@ define( .fail(this.errorMessage(i18n('Could not delete emails'))); }; + this.recoverManyMails = function (ev, data) { + var dataToRecover = data; + var mailIdents = _.map(data.mails, function (mail) { + return mail.ident; + }); + + monitoredAjax(this, '/mails/recover', { + type: 'POST', + dataType: 'json', + contentType: 'application/json; charset=utf-8', + data: JSON.stringify({idents: mailIdents}) + }).done(this.triggerRecovered(dataToRecover)) + .fail(this.errorMessage(i18n('Could not move emails to inbox'))); + }; + function compileQuery(data) { var query = 'tag:"' + that.attr.currentTag + '"'; @@ -273,6 +298,7 @@ define( this.on(document, events.mail.unread, this.unreadMail); this.on(document, events.mail.delete, this.deleteMail); this.on(document, events.mail.deleteMany, this.deleteManyMails); + this.on(document, events.mail.recoverMany, this.recoverManyMails); this.on(document, events.search.perform, this.newSearch); this.on(document, events.ui.tag.selected, this.fetchByTag); this.on(document, events.ui.tag.select, this.fetchByTag); diff --git a/web-ui/app/js/services/recover_service.js b/web-ui/app/js/services/recover_service.js new file mode 100644 index 00000000..c3fbc98c --- /dev/null +++ b/web-ui/app/js/services/recover_service.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see . + */ + +define(['flight/lib/component', 'page/events', 'views/i18n'], function (defineComponent, events, i18n) { + 'use strict'; + + return defineComponent(function() { + + this.recoverManyEmails = function (event, data) { + debugger; + var emails = _.values(data.checkedMails); + + this.trigger(document, events.mail.recoverMany, { + mails: emails, + successMessage: i18n('Your messages were moved to inbox!') + }); + + }; + + this.after('initialize', function () { + this.on(document, events.ui.mail.recoverMany, this.recoverManyEmails); + }); + + }); +}); -- cgit v1.2.3 From e6931bed853a798acaced4ae92985866b2a32691 Mon Sep 17 00:00:00 2001 From: Roberto Soares Date: Thu, 9 Apr 2015 16:42:08 -0300 Subject: removes debugger (whoops) --- web-ui/app/js/services/recover_service.js | 1 - 1 file changed, 1 deletion(-) (limited to 'web-ui/app/js/services') diff --git a/web-ui/app/js/services/recover_service.js b/web-ui/app/js/services/recover_service.js index c3fbc98c..62fcf1f9 100644 --- a/web-ui/app/js/services/recover_service.js +++ b/web-ui/app/js/services/recover_service.js @@ -21,7 +21,6 @@ define(['flight/lib/component', 'page/events', 'views/i18n'], function (defineCo return defineComponent(function() { this.recoverManyEmails = function (event, data) { - debugger; var emails = _.values(data.checkedMails); this.trigger(document, events.mail.recoverMany, { -- cgit v1.2.3