diff options
author | Rafael Lisboa <rafaelzlisboa@gmail.com> | 2015-04-27 12:35:02 -0300 |
---|---|---|
committer | Rafael Lisboa <rafaelzlisboa@gmail.com> | 2015-04-27 12:35:02 -0300 |
commit | 9234ef399cac44dcdc8dab11c20dd162953e447c (patch) | |
tree | bbc3c618a245b903f99c1c41fa726062ead55ebf /web-ui | |
parent | 5cc53a2ac0b47a05423ed9e4a64e24a3a9994a58 (diff) | |
parent | 6617b24ae00490cf86282147b732cfa31de127fb (diff) |
Merge pull request #373 from roberto/master
Allow user to move emails from trash to inbox
Diffstat (limited to 'web-ui')
-rw-r--r-- | web-ui/app/js/mail_list_actions/ui/mail_list_actions.js | 23 | ||||
-rw-r--r-- | web-ui/app/js/mail_list_actions/ui/recover_many_trigger.js | 47 | ||||
-rw-r--r-- | web-ui/app/js/page/default.js | 3 | ||||
-rw-r--r-- | web-ui/app/js/page/events.js | 2 | ||||
-rw-r--r-- | web-ui/app/js/services/mail_service.js | 26 | ||||
-rw-r--r-- | web-ui/app/js/services/recover_service.js | 38 | ||||
-rw-r--r-- | web-ui/app/js/views/templates.js | 1 | ||||
-rw-r--r-- | web-ui/app/templates/mail_actions/actions_box.hbs | 2 | ||||
-rw-r--r-- | web-ui/app/templates/mail_actions/trash_actions_box.hbs | 5 | ||||
-rw-r--r-- | web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js | 18 | ||||
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 36 | ||||
-rw-r--r-- | web-ui/test/spec/services/recover_service.spec.js | 32 |
12 files changed, 221 insertions, 12 deletions
diff --git a/web-ui/app/js/mail_list_actions/ui/mail_list_actions.js b/web-ui/app/js/mail_list_actions/ui/mail_list_actions.js index 8987a7d4..2c9c699f 100644 --- a/web-ui/app/js/mail_list_actions/ui/mail_list_actions.js +++ b/web-ui/app/js/mail_list_actions/ui/mail_list_actions.js @@ -28,6 +28,7 @@ define( 'mail_list_actions/ui/toggle_check_all_trigger', 'mail_list_actions/ui/pagination_trigger', 'mail_list_actions/ui/delete_many_trigger', + 'mail_list_actions/ui/recover_many_trigger', 'mail_list_actions/ui/mark_many_as_read_trigger', 'mail_list_actions/ui/mark_as_unread_trigger' ], @@ -43,6 +44,7 @@ define( toggleCheckAllMailTrigger, paginationTrigger, deleteManyTrigger, + recoverManyTrigger, markManyAsReadTrigger, markAsUnreadTrigger ) { @@ -51,14 +53,13 @@ define( function mailsActions() { this.render = function() { - this.$node.html(templates.mailActions.actionsBox({ - txtDeleteButton: this.getTxtDeleteButton() - })); + this.$node.html(this.getActionsBoxTemplate()); refreshTrigger.attachTo('#refresh-trigger'); composeTrigger.attachTo('#compose-trigger'); toggleCheckAllMailTrigger.attachTo('#toggle-check-all-emails'); paginationTrigger.attachTo('#pagination-trigger'); deleteManyTrigger.attachTo('#delete-selected'); + recoverManyTrigger.attachTo('#recover-selected'); markManyAsReadTrigger.attachTo('#mark-selected-as-read'); markAsUnreadTrigger.attachTo('#mark-selected-as-unread'); refresher.attachTo(document); @@ -68,19 +69,19 @@ define( return this.attr.currentTag || urlParams.getTag(); }; - this.getTxtDeleteButton = function() { - if(this.getCurrentTag() === 'trash') { - return 'Delete permanently'; - } else { - return 'Delete'; - } - }; - this.updateCurrentTag = function (ev, data) { this.attr.currentTag = data.tag; this.render(); }; + this.getActionsBoxTemplate = function () { + if(this.getCurrentTag() === 'trash') { + return templates.mailActions.trashActionsBox(); + } else { + return templates.mailActions.actionsBox(); + } + }; + this.after('initialize', function () { this.on(document, events.ui.tag.select, this.updateCurrentTag); this.render(); diff --git a/web-ui/app/js/mail_list_actions/ui/recover_many_trigger.js b/web-ui/app/js/mail_list_actions/ui/recover_many_trigger.js new file mode 100644 index 00000000..e0a32094 --- /dev/null +++ b/web-ui/app/js/mail_list_actions/ui/recover_many_trigger.js @@ -0,0 +1,47 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +define( + [ + 'flight/lib/component', + 'views/templates', + 'mixins/with_enable_disable_on_event', + 'page/events' + ], + + function(defineComponent, templates, withEnableDisableOnEvent, events) { + 'use strict'; + + return defineComponent(recoverManyTrigger, withEnableDisableOnEvent(events.ui.mails.hasMailsChecked)); + + function recoverManyTrigger() { + this.defaultAttrs({}); + + this.getMailsToRecover = function(event) { + this.trigger(document, events.ui.mail.wantChecked, this.$node); + }; + + this.recoverManyEmails = function (event, data) { + this.trigger(document, events.ui.mail.recoverMany, data); + }; + + this.after('initialize', function () { + this.on('click', this.getMailsToRecover); + this.on(events.ui.mail.hereChecked, this.recoverManyEmails); + }); + } + } +); diff --git a/web-ui/app/js/page/default.js b/web-ui/app/js/page/default.js index bbff271f..1571202e 100644 --- a/web-ui/app/js/page/default.js +++ b/web-ui/app/js/page/default.js @@ -27,6 +27,7 @@ define( 'mail_view/data/mail_sender', 'services/mail_service', 'services/delete_service', + 'services/recover_service', 'tags/ui/tag_list', 'tags/data/tags', 'page/router', @@ -56,6 +57,7 @@ define( mailSender, mailService, deleteService, + recoverService, tagList, tags, router, @@ -89,6 +91,7 @@ define( mailService.attachTo(document); deleteService.attachTo(document); + recoverService.attachTo(document); tags.attachTo(document); tagList.attachTo('#tag-list'); diff --git a/web-ui/app/js/page/events.js b/web-ui/app/js/page/events.js index f1f426f7..cf1b29ad 100644 --- a/web-ui/app/js/page/events.js +++ b/web-ui/app/js/page/events.js @@ -55,6 +55,7 @@ define(function () { updateSelected: 'ui:mail:updateSelected', delete: 'ui:mail:delete', deleteMany: 'ui:mail:deleteMany', + recoverMany: 'ui:mail:recoverMany', wantChecked: 'ui:mail:wantChecked', hereChecked: 'ui:mail:hereChecked', checked: 'ui:mail:checked', @@ -108,6 +109,7 @@ define(function () { unread: 'mail:unread', delete: 'mail:delete', deleteMany: 'mail:deleteMany', + recoverMany: 'mail:recoverMany', deleted: 'mail:deleted', saveDraft: 'draft:save', draftSaved: 'draft:saved', 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..62fcf1f9 --- /dev/null +++ b/web-ui/app/js/services/recover_service.js @@ -0,0 +1,38 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ + +define(['flight/lib/component', 'page/events', 'views/i18n'], function (defineComponent, events, i18n) { + 'use strict'; + + return defineComponent(function() { + + this.recoverManyEmails = function (event, data) { + 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); + }); + + }); +}); diff --git a/web-ui/app/js/views/templates.js b/web-ui/app/js/views/templates.js index 64e269ca..5e991a20 100644 --- a/web-ui/app/js/views/templates.js +++ b/web-ui/app/js/views/templates.js @@ -46,6 +46,7 @@ define(['hbs/templates'], function (templates) { }, mailActions: { actionsBox: window.Pixelated['app/templates/mail_actions/actions_box.hbs'], + trashActionsBox: window.Pixelated['app/templates/mail_actions/trash_actions_box.hbs'], composeTrigger: window.Pixelated['app/templates/mail_actions/compose_trigger.hbs'], refreshTrigger: window.Pixelated['app/templates/mail_actions/refresh_trigger.hbs'], paginationTrigger: window.Pixelated['app/templates/mail_actions/pagination_trigger.hbs'] diff --git a/web-ui/app/templates/mail_actions/actions_box.hbs b/web-ui/app/templates/mail_actions/actions_box.hbs index 628a6240..b6dc2f53 100644 --- a/web-ui/app/templates/mail_actions/actions_box.hbs +++ b/web-ui/app/templates/mail_actions/actions_box.hbs @@ -1,6 +1,6 @@ <li><input type="checkbox" id="toggle-check-all-emails"/></li> <li><input type="button" id="mark-selected-as-read" value="{{t 'Mark as read'}}" disabled="disabled"/></li> <li><input type="button" id="mark-selected-as-unread" value="{{t 'Mark as unread'}}" disabled="disabled"/></li> -<li><input type="button" id="delete-selected" value="{{t txtDeleteButton}}" disabled="disabled"/></li> +<li><input type="button" id="delete-selected" value="{{t 'Delete'}}" disabled="disabled"/></li> <li id="pagination-trigger" class="right"></li> <li id="refresh-trigger" class="right"></li> diff --git a/web-ui/app/templates/mail_actions/trash_actions_box.hbs b/web-ui/app/templates/mail_actions/trash_actions_box.hbs new file mode 100644 index 00000000..7852bd6f --- /dev/null +++ b/web-ui/app/templates/mail_actions/trash_actions_box.hbs @@ -0,0 +1,5 @@ +<li><input type="checkbox" id="toggle-check-all-emails"/></li> +<li><input type="button" id="delete-selected" value="{{t 'Delete permanently'}}" disabled="disabled"/></li> +<li><input type="button" id="recover-selected" value="{{t 'Move to Inbox'}}" disabled="disabled"/></li> +<li id="pagination-trigger" class="right"></li> +<li id="refresh-trigger" class="right"></li> diff --git a/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js b/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js index 7f7ba64a..d8917ed9 100644 --- a/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js +++ b/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js @@ -28,6 +28,24 @@ describeComponent('mail_list_actions/ui/mail_list_actions', function () { expect(this.component.$node.html()).toMatch('<li><input type="button" id="delete-selected" value="Delete permanently" disabled="disabled"></li>'); }); + + it('should render move to inbox if on trash', function () { + var urlParams = require('page/router/url_params'); + spyOn(urlParams, 'getTag').and.returnValue('trash'); + + this.setupComponent(); + + expect(this.component.$node.html()).toMatch('<li><input type="button" id="recover-selected" value="Move to Inbox" disabled="disabled"></li>'); + }); + + it('should not render move to inbox if on trash', function () { + var urlParams = require('page/router/url_params'); + spyOn(urlParams, 'getTag').and.returnValue('inbox'); + + this.setupComponent(); + + expect(this.component.$node.html()).not.toMatch('<li><input type="button" id="recover-selected" value="Move to Inbox" disabled="disabled"></li>'); + }); }); }); diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js index 1a5cb9f7..7fb2bfda 100644 --- a/web-ui/test/spec/services/mail_service.spec.js +++ b/web-ui/test/spec/services/mail_service.spec.js @@ -174,6 +174,42 @@ describeComponent('services/mail_service', function () { expect(spyEvent).toHaveBeenTriggeredOnAndWith(document, {message: i18n('Could not delete email')} ); }); + it('will try to recover a message when requested to', function() { + var spyAjax = spyOn($, 'ajax').and.returnValue($.Deferred()); + this.component.trigger(Pixelated.events.mail.recoverMany, {mails: [{ident: '43'}, {ident: '44'}]}); + expect(spyAjax).toHaveBeenCalled(); + expect(spyAjax.calls.mostRecent().args[0]).toEqual('/mails/recover'); + expect(spyAjax.calls.mostRecent().args[1].type).toEqual('POST'); + expect(spyAjax.calls.all()[0].args[1].data).toEqual(JSON.stringify({ idents: ['43', '44'] } )); + }); + + describe('when successfuly recovers emails', function () { + var displayMessageEvent, uncheckAllEvent, mailsRecoveredEvent; + + beforeEach(function () { + displayMessageEvent = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage); + uncheckAllEvent = spyOnEvent(document, Pixelated.events.ui.mails.uncheckAll); + spyOn(this.component, 'refreshMails'); + + this.component.triggerRecovered({ + successMessage: 'A success message', + mails: {1: 'email 1', 2: 'email 2'} + })(); + }); + + it('will trigger that a message has been recovered when it is done recovering', function() { + expect(this.component.refreshMails).toHaveBeenCalled(); + }); + + it('displays a success message', function () { + expect(displayMessageEvent).toHaveBeenTriggeredOnAndWith(document, {message: 'A success message'}); + }); + + it('unchecks all checked mails', function () { + expect(uncheckAllEvent).toHaveBeenTriggeredOn(document); + }); + }); + it('triggers mails:available with received mails and keeps that tag as the current tag', function() { var eventSpy = spyOnEvent(document, Pixelated.events.mails.available); diff --git a/web-ui/test/spec/services/recover_service.spec.js b/web-ui/test/spec/services/recover_service.spec.js new file mode 100644 index 00000000..86fe9f87 --- /dev/null +++ b/web-ui/test/spec/services/recover_service.spec.js @@ -0,0 +1,32 @@ +describeComponent('services/recover_service', function () { + 'use strict'; + + var i18n; + + beforeEach( function () { + this.setupComponent(); + i18n = require('views/i18n'); + }); + + var mail1 = { + ident: 42, + isInTrash: function() { return false; } + }; + + var mail2 = { + ident: 34, + isInTrash: function() { return true; } + }; + + it('moves selected emails from trash back to inbox', function () { + var mailRecoverManyEvent = spyOnEvent(document, Pixelated.events.mail.recoverMany); + this.component.trigger(document, Pixelated.events.ui.mail.recoverMany, {checkedMails: {mail1: mail1, mail2: mail2}}); + + var expectedRecoverManyEventData = { + mails: [mail1, mail2], + successMessage: i18n('Your messages were moved to inbox!') + }; + + expect(mailRecoverManyEvent).toHaveBeenTriggeredOnAndWith(document, expectedRecoverManyEventData); + }); +}); |