diff options
author | Giovane <giovaneliberato@gmail.com> | 2015-11-27 15:47:58 -0200 |
---|---|---|
committer | Giovane <giovaneliberato@gmail.com> | 2015-11-27 15:53:11 -0200 |
commit | 07be9f6109e3dff49775aa51f0a481b5fd524d3b (patch) | |
tree | 29e2df328027c60349d17a8f62fdd556fafceeb3 /web-ui | |
parent | c1476b4b1c96996464217444e8cdf5d94d248bea (diff) |
Created a discard draft behaviour #512 w/ bwagner
If a draft was never saved before, and there wasn't
any change to save, we now discard it instead saving
and deleting it. This also lessens the calls to saveDraft
that was causing some draft duplication.
Diffstat (limited to 'web-ui')
-rw-r--r-- | web-ui/app/js/mail_view/ui/compose_box.js | 6 | ||||
-rw-r--r-- | web-ui/app/js/mail_view/ui/draft_box.js | 1 | ||||
-rw-r--r-- | web-ui/app/js/mail_view/ui/mail_view.js | 1 | ||||
-rw-r--r-- | web-ui/app/js/mixins/with_compose_inline.js | 4 | ||||
-rw-r--r-- | web-ui/app/js/mixins/with_mail_edit_base.js | 19 | ||||
-rw-r--r-- | web-ui/app/js/page/events.js | 1 | ||||
-rw-r--r-- | web-ui/test/spec/mail_view/ui/reply_box.spec.js | 8 | ||||
-rw-r--r-- | web-ui/test/spec/mixins/with_mail_edit_base.spec.js | 23 |
8 files changed, 43 insertions, 20 deletions
diff --git a/web-ui/app/js/mail_view/ui/compose_box.js b/web-ui/app/js/mail_view/ui/compose_box.js index 92588310..dcc8fd76 100644 --- a/web-ui/app/js/mail_view/ui/compose_box.js +++ b/web-ui/app/js/mail_view/ui/compose_box.js @@ -67,13 +67,15 @@ define( } }; + this.discardDraft = function () { + this.trigger(events.dispatchers.rightPane.openNoMessageSelected); + }; + this.after('initialize', function () { this.renderComposeBox(); this.select('toBox').focus(); - this.on(this.select('cancelButton'), 'click', this.showNoMessageSelected); this.on(document, events.mail.deleted, this.mailDeleted); - this.on(document, events.mail.sent, this.showNoMessageSelected); }); } diff --git a/web-ui/app/js/mail_view/ui/draft_box.js b/web-ui/app/js/mail_view/ui/draft_box.js index 8c2e15c7..e8dd10ea 100644 --- a/web-ui/app/js/mail_view/ui/draft_box.js +++ b/web-ui/app/js/mail_view/ui/draft_box.js @@ -72,7 +72,6 @@ define( this.select('bodyBox').focus(); this.select('tipMsg').hide(); this.enableAutoSave(); - this.on(this.select('cancelButton'), 'click', this.showNoMessageSelected); this.on(this.select('closeMailButton'), 'click', this.showNoMessageSelected); }; diff --git a/web-ui/app/js/mail_view/ui/mail_view.js b/web-ui/app/js/mail_view/ui/mail_view.js index 3c5b0ccc..01db6c4f 100644 --- a/web-ui/app/js/mail_view/ui/mail_view.js +++ b/web-ui/app/js/mail_view/ui/mail_view.js @@ -212,7 +212,6 @@ define( this.trigger(events.mail.want, {mail: this.attr.ident, caller: this}); }; - this.after('initialize', function () { this.on(this, events.mail.here, this.displayMail); this.on(this, events.mail.notFound, this.openNoMessageSelectedPane); diff --git a/web-ui/app/js/mixins/with_compose_inline.js b/web-ui/app/js/mixins/with_compose_inline.js index cd5dcd8b..b39201ae 100644 --- a/web-ui/app/js/mixins/with_compose_inline.js +++ b/web-ui/app/js/mixins/with_compose_inline.js @@ -65,6 +65,10 @@ define( this.attr.mail.ident = data.ident; }; + this.discardDraft = function() { + this.trashReply(); + }; + this.after('initialize', function () { this.on(document, events.mail.sent, this.openMail); this.on(document, events.mail.deleted, this.trashReply); diff --git a/web-ui/app/js/mixins/with_mail_edit_base.js b/web-ui/app/js/mixins/with_mail_edit_base.js index da92ad29..a3c88e66 100644 --- a/web-ui/app/js/mixins/with_mail_edit_base.js +++ b/web-ui/app/js/mixins/with_mail_edit_base.js @@ -118,10 +118,14 @@ define( this.trashMail = function() { this.cancelPostponedSaveDraft(); - this.trigger(document, events.mail.save, { - mail: this.buildMail(), - callback: this.deleteMail.bind(this) - }); + if (this.attr.ident) { + this.trigger(document, events.mail.save, { + mail: this.buildMail(), + callback: this.deleteMail.bind(this) + }); + } else { + this.trigger(document, events.ui.mail.discard); + } }; this.trim_recipient = function(recipients) { @@ -133,7 +137,7 @@ define( this.sendMail = function () { this.cancelPostponedSaveDraft(); var mail = this.buildMail('sent'); - + if (allRecipientsAreEmails(mail)) { mail.header.to = this.trim_recipient(mail.header.to); mail.header.cc = this.trim_recipient(mail.header.cc); @@ -219,6 +223,10 @@ define( }); }; + this.before('initialize', function () { + this.discardDraft = function () {}; + }); + this.after('initialize', function () { this.on(document, events.dispatchers.rightPane.clear, this.teardown); this.on(document, events.ui.recipients.updated, this.recipientsUpdated); @@ -227,6 +235,7 @@ define( this.on(document, events.ui.mail.send, this.sendMail); + this.on(document, events.ui.mail.discard, this.discardDraft); this.on(document, events.ui.tag.selected, this.saveTag); this.on(document, events.ui.tag.select, this.saveTag); }); diff --git a/web-ui/app/js/page/events.js b/web-ui/app/js/page/events.js index 307fc8d1..6897cf63 100644 --- a/web-ui/app/js/page/events.js +++ b/web-ui/app/js/page/events.js @@ -60,6 +60,7 @@ define(function () { wantChecked: 'ui:mail:wantChecked', hereChecked: 'ui:mail:hereChecked', checked: 'ui:mail:checked', + discard: 'ui:mail:discard', unchecked: 'ui:mail:unchecked', changedSinceLastSave: 'ui:mail:changedSinceLastSave', send: 'ui:mail:send', diff --git a/web-ui/test/spec/mail_view/ui/reply_box.spec.js b/web-ui/test/spec/mail_view/ui/reply_box.spec.js index 9542f37a..731d57b3 100644 --- a/web-ui/test/spec/mail_view/ui/reply_box.spec.js +++ b/web-ui/test/spec/mail_view/ui/reply_box.spec.js @@ -82,14 +82,6 @@ describeComponent('mail_view/ui/reply_box', function () { expect(this.component.select('bodyBox').val()).toBe('quoted email'); }); - it('triggers mail when cancelling a reply', function () { - var mailSaveEvent = spyOnEvent(document, Pixelated.events.mail.save); - - this.component.select('trashButton').click(); - - expect(mailSaveEvent).toHaveBeenTriggeredOn(document); - }); - it('reopens the mail after the reply is sent', function () { var mailOpenEvent = spyOnEvent(document, Pixelated.events.ui.mail.open); diff --git a/web-ui/test/spec/mixins/with_mail_edit_base.spec.js b/web-ui/test/spec/mixins/with_mail_edit_base.spec.js index 601f2c11..2ad12361 100644 --- a/web-ui/test/spec/mixins/with_mail_edit_base.spec.js +++ b/web-ui/test/spec/mixins/with_mail_edit_base.spec.js @@ -2,12 +2,14 @@ describeMixin('mixins/with_mail_edit_base', function () { 'use strict'; beforeEach(function () { + this.Component.discardDraft = function () {}; this.setupComponent(); // Stubing mixing wrongly!!! 'deprecated' while waiting for draft component extraction this.component.buildMail = function (tag) { return { header: { to: ['a@smth.com'], from: 'b@smth.com', subject: 'Sbject' } }; }; + spyOn(this.component, 'trim_recipient').and.callFake(function(recipients) { return recipients.map(function(recipient) { return recipient.trim(); @@ -66,11 +68,26 @@ describeMixin('mixins/with_mail_edit_base', function () { }); }); - describe('when user asks to trash the mail', function() { - it('triggers mail delete for this mail', function() { + describe('when user asks to discard the mail', function() { + var mailSaveSpy, mailDiscardSpy; + + beforeEach(function () { + mailSaveSpy = spyOnEvent(document, Pixelated.events.mail.save); + mailDiscardSpy = spyOnEvent(document, Pixelated.events.ui.mail.discard); + }); + + it('discards the mail if it was never saved', function() { + delete this.component.attr.ident; + this.component.trashMail(); + expect(mailSaveSpy).not.toHaveBeenTriggeredOn(document); + expect(mailDiscardSpy).toHaveBeenTriggeredOn(document); + }); + + it('deletes the draft if it was saved before', function() { var spy = spyOnEvent(document, Pixelated.events.mail.save); + this.component.attr.ident = 'ident'; this.component.trashMail(); - expect(spy).toHaveBeenTriggeredOn(document); + expect(mailSaveSpy).toHaveBeenTriggeredOn(document); }); }); |