From a22f4372334d59bfe06d6554e8f917e331a06855 Mon Sep 17 00:00:00 2001 From: Gabriel Albo Date: Wed, 6 Jan 2016 14:29:14 -0200 Subject: #563 - Giovane/Albo - Fixing arrow toggling for drafts --- web-ui/app/js/mail_view/ui/compose_box.js | 12 -- web-ui/app/js/mail_view/ui/draft_box.js | 3 +- web-ui/app/js/mixins/with_mail_edit_base.js | 200 +++++++++++++++------------- 3 files changed, 106 insertions(+), 109 deletions(-) (limited to 'web-ui/app') 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 993cf880..48a7c23f 100644 --- a/web-ui/app/js/mail_view/ui/compose_box.js +++ b/web-ui/app/js/mail_view/ui/compose_box.js @@ -73,24 +73,12 @@ define( this.trigger(events.dispatchers.rightPane.openNoMessageSelected); }; - this.toggleRecipientsArrows = function () { - if ($('#cc-bcc-collapse').hasClass('fa-angle-down')) { - $('#cc-bcc-collapse').removeClass('fa-angle-down'); - $('#cc-bcc-collapse').addClass('fa-angle-up'); - } else { - $('#cc-bcc-collapse').removeClass('fa-angle-up'); - $('#cc-bcc-collapse').addClass('fa-angle-down'); - } - }; - - this.after('initialize', function () { this.renderComposeBox(); this.select('toBox').focus(); this.on(document, events.mail.deleted, this.mailDeleted); this.on(document, events.mail.sent, this.showNoMessageSelected); - this.on($('#cc-bcc-collapse'), 'click', this.toggleRecipientsArrows); }); } } 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 e8dd10ea..675020cb 100644 --- a/web-ui/app/js/mail_view/ui/draft_box.js +++ b/web-ui/app/js/mail_view/ui/draft_box.js @@ -72,6 +72,7 @@ define( this.select('bodyBox').focus(); this.select('tipMsg').hide(); this.enableAutoSave(); + this.bindCollapse(); this.on(this.select('closeMailButton'), 'click', this.showNoMessageSelected); }; @@ -85,7 +86,7 @@ define( this.on(this, events.mail.here, this.renderDraftBox); this.on(document, events.mail.sent, this.showNoMessageSelected); this.on(document, events.mail.deleted, this.mailDeleted); - this.trigger(document, events.mail.want, { mail: this.attr.mailIdent, caller: this }); + this.trigger(document, events.mail.want, { mail: this.attr.mailIdent , caller: this }); }); } } 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 0aaa6628..d0942d4e 100644 --- a/web-ui/app/js/mixins/with_mail_edit_base.js +++ b/web-ui/app/js/mixins/with_mail_edit_base.js @@ -149,100 +149,108 @@ define( this.trigger(events.mail.send_failed); } }; + + this.buildAndSaveDraft = function () { + var mail = this.buildMail(); + this.saveDraft(mail); + }; + + this.recipientsUpdated = function (ev, data) { + this.attr.recipientValues[data.recipientsName] = data.newRecipients; + this.trigger(document, events.ui.mail.recipientsUpdated); + if (data.skipSaveDraft) { return; } + + var mail = this.buildMail(); + this.postponeSaveDraft(mail); + }; + + this.saveDraft = function (mail) { + this.cancelPostponedSaveDraft(); + this.trigger(document, events.mail.saveDraft, mail); + }; + + this.cancelPostponedSaveDraft = function() { + clearTimeout(this.attr.timeout); + }; + + this.postponeSaveDraft = function (mail) { + this.cancelPostponedSaveDraft(); + + this.attr.timeout = window.setTimeout(_.bind(function() { + this.saveDraft(mail); + }, this), this.attr.saveDraftInterval); + }; + + this.draftSaved = function(event, data) { + this.attr.ident = data.ident; + }; + + this.validateAnyRecipient = function () { + return !_.isEmpty(_.flatten(_.values(this.attr.recipientValues))); + }; + + function allRecipientsAreEmails(mail) { + var allRecipients = mail.header.to.concat(mail.header.cc).concat(mail.header.bcc); + return _.isEmpty(allRecipients) ? false : _.all(allRecipients, emailFormatChecker); + } + + function emailFormatChecker(email) { + var emailFormat = /[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailFormat.test(email); + } + + this.saveTag = function(ev, data) { + this.attr.currentTag = data.tag; + }; + + this.mailSent = function() { + this.trigger(document, events.ui.userAlerts.displayMessage, { message: 'Your message was sent!' }); + }; + + this.enableFloatlabel = function(element) { + var showClass = 'showfloatlabel'; + $(element).bind('keyup', function() { + var label = $(this).prev('label'); + if (this.value !== '') { + label.addClass(showClass); + $(this).addClass(showClass); + } else { + label.removeClass(showClass); + $(this).removeClass(showClass); + } + }); + }; + + this.toggleRecipientsArrows = function () { + $('#cc-bcc-collapse').toggleClass('fa-angle-down'); + $('#cc-bcc-collapse').toggleClass('fa-angle-up'); + }; + + this.before('initialize', function () { + if (!this.discardDraft){ + this.discardDraft = function () {}; + } + }); + + this.bindCollapse = function () { + this.on($('#cc-bcc-collapse'), 'click', this.toggleRecipientsArrows); + }; + + this.after('initialize', function () { + this.on(document, events.dispatchers.rightPane.clear, this.teardown); + this.on(document, events.ui.recipients.updated, this.recipientsUpdated); + this.on(document, events.mail.draftSaved, this.draftSaved); + this.on(document, events.mail.sent, this.mailSent); + + 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); + this.bindCollapse(); + }); + } + + return withMailEditBase; + }); - this.buildAndSaveDraft = function () { - var mail = this.buildMail(); - this.saveDraft(mail); - }; - - this.recipientsUpdated = function (ev, data) { - this.attr.recipientValues[data.recipientsName] = data.newRecipients; - this.trigger(document, events.ui.mail.recipientsUpdated); - if (data.skipSaveDraft) { - return; - } - - var mail = this.buildMail(); - this.postponeSaveDraft(mail); - }; - - this.saveDraft = function (mail) { - this.cancelPostponedSaveDraft(); - this.trigger(document, events.mail.saveDraft, mail); - }; - - this.cancelPostponedSaveDraft = function () { - clearTimeout(this.attr.timeout); - }; - - this.postponeSaveDraft = function (mail) { - this.cancelPostponedSaveDraft(); - - this.attr.timeout = window.setTimeout(_.bind(function () { - this.saveDraft(mail); - }, this), this.attr.saveDraftInterval); - }; - - this.draftSaved = function (event, data) { - this.attr.ident = data.ident; - }; - - this.validateAnyRecipient = function () { - return !_.isEmpty(_.flatten(_.values(this.attr.recipientValues))); - }; - - function allRecipientsAreEmails(mail) { - var allRecipients = mail.header.to.concat(mail.header.cc).concat(mail.header.bcc); - return _.isEmpty(allRecipients) ? false : _.all(allRecipients, emailFormatChecker); - } - - function emailFormatChecker(email) { - var emailFormat = /[^\s@]+@[^\s@]+\.[^\s@]+$/; - return emailFormat.test(email); - } - - this.saveTag = function (ev, data) { - this.attr.currentTag = data.tag; - }; - - this.mailSent = function () { - this.trigger(document, events.ui.userAlerts.displayMessage, {message: 'Your message was sent!'}); - }; - - this.enableFloatlabel = function (element) { - var showClass = 'showfloatlabel'; - $(element).bind('keyup', function () { - var label = $(this).prev('label'); - if (this.value !== '') { - label.addClass(showClass); - $(this).addClass(showClass); - } else { - label.removeClass(showClass); - $(this).removeClass(showClass); - } - }); - }; - - this.before('initialize', function () { - if (!this.discardDraft) { - 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); - this.on(document, events.mail.draftSaved, this.draftSaved); - this.on(document, events.mail.sent, this.mailSent); - - 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); - }); - } - - return withMailEditBase; - }); -- cgit v1.2.3