diff options
Diffstat (limited to 'web-ui')
-rw-r--r-- | web-ui/app/js/dispatchers/middle_pane_dispatcher.js | 2 | ||||
-rw-r--r-- | web-ui/app/js/mail_list_actions/ui/archive_many_trigger.js | 29 | ||||
-rw-r--r-- | web-ui/app/js/mail_list_actions/ui/mail_list_actions.js | 3 | ||||
-rw-r--r-- | web-ui/app/js/mail_view/ui/no_mails_available_pane.js | 6 | ||||
-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/locales/en-us/translation.json | 2 | ||||
-rw-r--r-- | web-ui/app/locales/pt/translation.json | 2 | ||||
-rw-r--r-- | web-ui/app/locales/sv/translation.json | 2 | ||||
-rw-r--r-- | web-ui/app/templates/compose/no_mails_available.hbs | 6 | ||||
-rw-r--r-- | web-ui/app/templates/mail_actions/actions_box.hbs | 1 | ||||
-rw-r--r-- | web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js | 10 | ||||
-rw-r--r-- | web-ui/test/spec/mail_view/ui/no_mails_available_pane.spec.js | 5 | ||||
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 43 |
14 files changed, 126 insertions, 13 deletions
diff --git a/web-ui/app/js/dispatchers/middle_pane_dispatcher.js b/web-ui/app/js/dispatchers/middle_pane_dispatcher.js index 7a53b769..12222aec 100644 --- a/web-ui/app/js/dispatchers/middle_pane_dispatcher.js +++ b/web-ui/app/js/dispatchers/middle_pane_dispatcher.js @@ -57,7 +57,7 @@ define(['flight/lib/component', 'page/events', 'helpers/triggering', 'mail_view/ NoMailsAvailablePane.teardownAll(); } else { var child_div = this.createChildDiv(this.attr.noMailsAvailablePane); - NoMailsAvailablePane.attachTo(child_div, {tag: data.tag}); + NoMailsAvailablePane.attachTo(child_div, {tag: data.tag, forSearch: data.forSearch}); } }; diff --git a/web-ui/app/js/mail_list_actions/ui/archive_many_trigger.js b/web-ui/app/js/mail_list_actions/ui/archive_many_trigger.js new file mode 100644 index 00000000..b148cdce --- /dev/null +++ b/web-ui/app/js/mail_list_actions/ui/archive_many_trigger.js @@ -0,0 +1,29 @@ +define( + [ + 'flight/lib/component', + 'views/templates', + 'mixins/with_enable_disable_on_event', + 'page/events' + ], + + function(definecomponent, templates, withEnableDisableOnEvent, events) { + 'use strict'; + + return definecomponent(archiveManyTrigger, withEnableDisableOnEvent(events.ui.mails.hasMailsChecked)); + function archiveManyTrigger() { + + this.getMailsToArchive = function() { + this.trigger(document, events.ui.mail.wantChecked, this.$node); + }; + + this.archiveManyEmails = function(event, data) { + this.trigger(document, events.mail.archiveMany, data); + }; + + this.after('initialize', function () { + this.on('click', this.getMailsToArchive); + this.on(events.ui.mail.hereChecked, this.archiveManyEmails); + }); + } + } +); 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 2c9c699f..f71ed07c 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 @@ -29,6 +29,7 @@ define( 'mail_list_actions/ui/pagination_trigger', 'mail_list_actions/ui/delete_many_trigger', 'mail_list_actions/ui/recover_many_trigger', + 'mail_list_actions/ui/archive_many_trigger', 'mail_list_actions/ui/mark_many_as_read_trigger', 'mail_list_actions/ui/mark_as_unread_trigger' ], @@ -45,6 +46,7 @@ define( paginationTrigger, deleteManyTrigger, recoverManyTrigger, + archiveManyTrigger, markManyAsReadTrigger, markAsUnreadTrigger ) { @@ -60,6 +62,7 @@ define( paginationTrigger.attachTo('#pagination-trigger'); deleteManyTrigger.attachTo('#delete-selected'); recoverManyTrigger.attachTo('#recover-selected'); + archiveManyTrigger.attachTo('#archive-selected'); markManyAsReadTrigger.attachTo('#mark-selected-as-read'); markAsUnreadTrigger.attachTo('#mark-selected-as-unread'); refresher.attachTo(document); diff --git a/web-ui/app/js/mail_view/ui/no_mails_available_pane.js b/web-ui/app/js/mail_view/ui/no_mails_available_pane.js index 32b6bc19..b1d5f9dd 100644 --- a/web-ui/app/js/mail_view/ui/no_mails_available_pane.js +++ b/web-ui/app/js/mail_view/ui/no_mails_available_pane.js @@ -30,11 +30,15 @@ define( function noMailsAvailablePane() { this.defaultAttrs({ - tag: null + tag: null, + forSearch: '' }); + var mailsQueryMatch = /-?in:"[\w]+"|tag:"[\w]+"/g; + this.render = function() { this.attr.tag = this.attr.tag.toUpperCase(); + this.attr.forSearch = this.attr.forSearch.replace(mailsQueryMatch, '').trim().toUpperCase(); this.$node.html(templates.noMailsAvailable(this.attr)); }; diff --git a/web-ui/app/js/page/events.js b/web-ui/app/js/page/events.js index f82a6b36..307fc8d1 100644 --- a/web-ui/app/js/page/events.js +++ b/web-ui/app/js/page/events.js @@ -56,6 +56,7 @@ define(function () { delete: 'ui:mail:delete', deleteMany: 'ui:mail:deleteMany', recoverMany: 'ui:mail:recoverMany', + archiveMany: 'ui:mail:archiveMany', wantChecked: 'ui:mail:wantChecked', hereChecked: 'ui:mail:hereChecked', checked: 'ui:mail:checked', @@ -117,6 +118,7 @@ define(function () { unread: 'mail:unread', delete: 'mail:delete', deleteMany: 'mail:deleteMany', + archiveMany: 'mail:archiveMany', recoverMany: 'mail:recoverMany', deleted: 'mail:deleted', saveDraft: 'draft:save', diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js index 04194964..a63d517e 100644 --- a/web-ui/app/js/services/mail_service.js +++ b/web-ui/app/js/services/mail_service.js @@ -128,11 +128,32 @@ define( var mails = dataToRecover.mails || [dataToRecover.mail]; this.refreshMails(); - this.trigger(document, events.ui.userAlerts.displayMessage, { message: dataToRecover.successMessage}); + this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n(dataToRecover.successMessage)}); this.trigger(document, events.ui.mails.uncheckAll); }, this); }; + this.triggerArchived = function (dataToArchive) { + return _.bind(function (response) { + this.refreshMails(); + this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n(response.successMessage)}); + this.trigger(document, events.ui.mails.uncheckAll); + }, this); + }; + + this.archiveManyMails = function(event, dataToArchive) { + var mailIdents = _.map(dataToArchive.checkedMails, function (mail) { + return mail.ident; + }); + monitoredAjax(this, '/mails/archive', { + type: 'POST', + dataType: 'json', + contentType: 'application/json; charset=utf-8', + data: JSON.stringify({idents: mailIdents}) + }).done(this.triggerArchived(dataToArchive)) + .fail(this.errorMessage(i18n('Could not archive emails'))); + }; + this.deleteMail = function (ev, data) { monitoredAjax(this, '/mail/' + data.mail.ident, {type: 'DELETE'}) @@ -222,7 +243,7 @@ define( monitoredAjax(this, url, { dataType: 'json' }) .done(function (data) { this.attr.numPages = Math.ceil(data.stats.total / this.attr.pageSize); - this.trigger(document, events.mails.available, _.merge(_.merge({tag: this.attr.currentTag }), this.parseMails(data))); + this.trigger(document, events.mails.available, _.merge({tag: this.attr.currentTag, forSearch: this.attr.lastQuery }, this.parseMails(data))); }.bind(this)) .fail(function () { this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n('Could not fetch messages') }); @@ -299,6 +320,7 @@ define( 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.mail.archiveMany, this.archiveManyMails); 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/locales/en-us/translation.json b/web-ui/app/locales/en-us/translation.json index 7c90926d..05a65c72 100644 --- a/web-ui/app/locales/en-us/translation.json +++ b/web-ui/app/locales/en-us/translation.json @@ -3,7 +3,7 @@ "re": "Re: ", "Fwd: ": "Fwd: ", "Your message was moved to trash!": "Your message was moved to trash!", - "Your message was archive it!": "Your message was archived!", + "Your message was archived": "Your message was archived", "Your message was permanently deleted!": "Your message was permanently deleted!", "Saved as draft.": "Saved as draft.", "One or more of the recipients are not valid emails": "One or more of the recipients are not valid emails", diff --git a/web-ui/app/locales/pt/translation.json b/web-ui/app/locales/pt/translation.json index 2885e12b..7f553d04 100644 --- a/web-ui/app/locales/pt/translation.json +++ b/web-ui/app/locales/pt/translation.json @@ -2,7 +2,7 @@ "compose": "Escrever", "re": "Res: ", "Your message was moved to trash!": "Sua mensagem foi movida para a lixeira!", - "Your message was archive it!": "Sua mensagem foi arquivada!", + "Your message was archived": "Sua mensagem foi arquivada!", "Your message was permanently deleted!": "Sua mensagem foi permanentemente deletada!", "Saved as draft.": "Mensagem salva como rascunho.", "One or more of the recipients are not valid emails": "Email de um ou mais destinatários é inválido", diff --git a/web-ui/app/locales/sv/translation.json b/web-ui/app/locales/sv/translation.json index f4848d7a..45c34a63 100644 --- a/web-ui/app/locales/sv/translation.json +++ b/web-ui/app/locales/sv/translation.json @@ -3,7 +3,7 @@ "re": "Sv: ", "Fwd: ": "VB: ", "Your message was moved to trash!": "Ditt meddelande har flyttats till papperskorgen!", - "Your message was archive it!": "Ditt meddelande har arkiverats!", + "Your message was archived": "Ditt meddelande har arkiverats!", "Your message was permanently deleted!": "Ditt meddelande har tagits bort permanent!", "Saved as draft.": "Sparat som utkast.", "One or more of the recipients are not valid emails": "En eller flera mottagare är inte giltiga epost-adresser", diff --git a/web-ui/app/templates/compose/no_mails_available.hbs b/web-ui/app/templates/compose/no_mails_available.hbs index ce887267..6388d7db 100644 --- a/web-ui/app/templates/compose/no_mails_available.hbs +++ b/web-ui/app/templates/compose/no_mails_available.hbs @@ -1,3 +1,7 @@ <div class="scene"> - <div class="text">{{t 'NO EMAILS IN'}} '{{ tag }}'.</div> + {{#if forSearch }} + <div class="text">{{t 'NO RESULTS FOR'}}: '{{ forSearch }}'.</div> + {{else}} + <div class="text">{{t 'NO EMAILS IN'}} '{{ tag }}'.</div> + {{/if}} </div> diff --git a/web-ui/app/templates/mail_actions/actions_box.hbs b/web-ui/app/templates/mail_actions/actions_box.hbs index b6dc2f53..07dcc9e9 100644 --- a/web-ui/app/templates/mail_actions/actions_box.hbs +++ b/web-ui/app/templates/mail_actions/actions_box.hbs @@ -2,5 +2,6 @@ <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 'Delete'}}" disabled="disabled"/></li> +<li><input type="button" id="archive-selected" value="{{t 'Archive'}}" disabled="disabled"/></li> <li id="pagination-trigger" class="right"></li> <li id="refresh-trigger" class="right"></li> diff --git a/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js b/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js index 3d55cbaa..220ad96d 100644 --- a/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js +++ b/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js @@ -24,10 +24,10 @@ describeComponent('dispatchers/middle_pane_dispatcher', function () { }); describe('no emails available', function () { - var noMailsAvailablePane; + var noMailsAvailablePane, attachToSpy; beforeEach(function () { noMailsAvailablePane = require('mail_view/ui/no_mails_available_pane'); - spyOn(noMailsAvailablePane, 'attachTo'); + attachToSpy = spyOn(noMailsAvailablePane, 'attachTo'); spyOn(noMailsAvailablePane, 'teardownAll'); }); @@ -47,5 +47,11 @@ describeComponent('dispatchers/middle_pane_dispatcher', function () { expect(noMailsAvailablePane.teardownAll).toHaveBeenCalled(); }); + it('should give search information to component', function () { + var mail_list = { mails: [], tag: 'all', forSearch: 'search'}; + this.component.trigger(document, Pixelated.events.mails.available, mail_list); + + expect(attachToSpy.calls.mostRecent().args[1]).toEqual({tag: 'all', forSearch: 'search'}); + }); }); }); diff --git a/web-ui/test/spec/mail_view/ui/no_mails_available_pane.spec.js b/web-ui/test/spec/mail_view/ui/no_mails_available_pane.spec.js index 2fee45ac..868efc76 100644 --- a/web-ui/test/spec/mail_view/ui/no_mails_available_pane.spec.js +++ b/web-ui/test/spec/mail_view/ui/no_mails_available_pane.spec.js @@ -6,5 +6,10 @@ describeComponent('mail_view/ui/no_mails_available_pane', function () { this.setupComponent({tag: 'inbox'}); expect(this.$node.html()).toMatch('<div class="text">NO EMAILS IN \'INBOX\'.</div>'); }); + + it('show different message for search with no results', function () { + this.setupComponent({tag: 'all', forSearch: 'search'}); + expect(this.$node.html()).toMatch('<div class="text">NO RESULTS FOR: \'SEARCH\'.</div>'); + }); }); }); diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js index 7fb2bfda..d0911768 100644 --- a/web-ui/test/spec/services/mail_service.spec.js +++ b/web-ui/test/spec/services/mail_service.spec.js @@ -93,7 +93,6 @@ describeComponent('services/mail_service', function () { var spyAjax = spyOn($, 'ajax').and.returnValue(deferred); var spyEvent = spyOnEvent(document, Pixelated.events.mail.tags.updated); - var component = jasmine.createSpyObj('component',['successUpdateTags']); this.component.trigger(Pixelated.events.mail.tags.update, { ident: email1.ident, tags: email1.tags }); @@ -111,7 +110,6 @@ describeComponent('services/mail_service', function () { var spyAjax = spyOn($, 'ajax').and.returnValue(deferred); var spyEvent = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage); - var component = jasmine.createSpyObj('component',['failureUpdateTags']); this.component.trigger(Pixelated.events.mail.tags.update, { ident: email1.ident, tags: email1.tags }); @@ -169,7 +167,7 @@ describeComponent('services/mail_service', function () { this.component.trigger(Pixelated.events.mail.delete, {mail: {ident: '43'}}); - deferred.reject({responseJSON: {}}); + deferred.reject({mailsJSON: {}}); expect(spyEvent).toHaveBeenTriggeredOnAndWith(document, {message: i18n('Could not delete email')} ); }); @@ -183,6 +181,45 @@ describeComponent('services/mail_service', function () { expect(spyAjax.calls.all()[0].args[1].data).toEqual(JSON.stringify({ idents: ['43', '44'] } )); }); + // TODO: WIP + describe('when try archive emails', function() { + var deferred, spyAjax, mails; + + beforeEach(function() { + deferred = $.Deferred(); + spyAjax = spyOn($, 'ajax').and.returnValue(deferred); + mails = {checkedMails: [{ident: '43'}, {ident: '44'}]}; + }); + + it('should call triggerArchived', function() { + spyOn(this.component, 'triggerArchived'); + + this.component.trigger(Pixelated.events.mail.archiveMany, mails); + + deferred.resolve(); + expect(this.component.triggerArchived).toHaveBeenCalledWith(mails); + }); + + it('should show an error message when request returns no success', function() { + spyOn(this.component, 'errorMessage'); + + this.component.trigger(Pixelated.events.mail.archiveMany, mails); + + deferred.reject({}); + expect(this.component.errorMessage).toHaveBeenCalledWith(i18n('Could not archive emails')); + }); + + it('make an ajax request to /mails/archive', function() { + this.component.trigger(Pixelated.events.mail.archiveMany, + {checkedMails: [{ident: '43'}, {ident: '44'}]}); + + expect(spyAjax).toHaveBeenCalled(); + expect(spyAjax.calls.mostRecent().args[0]).toEqual('/mails/archive'); + 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; |