From 058d14143c179d9923eea433fc63094f4f9059aa Mon Sep 17 00:00:00 2001 From: NavaL Date: Mon, 11 Jan 2016 16:55:25 +0100 Subject: merging attachment_list ui and data, and making it into a mixin Issue #573 --- web-ui/app/js/mixins/with_mail_edit_base.js | 218 ++++++++++++++-------------- 1 file changed, 112 insertions(+), 106 deletions(-) (limited to 'web-ui/app/js/mixins') 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 d0942d4e..d078c582 100644 --- a/web-ui/app/js/mixins/with_mail_edit_base.js +++ b/web-ui/app/js/mixins/with_mail_edit_base.js @@ -17,6 +17,7 @@ define( [ + 'flight/lib/compose', 'helpers/view_helper', 'mail_view/ui/recipients/recipients', 'mail_view/ui/draft_save_status', @@ -27,7 +28,7 @@ define( 'mail_view/ui/attachment_list', 'flight/lib/utils' ], - function (viewHelper, Recipients, DraftSaveStatus, events, i18n, SendButton, AttachmentIcon, AttachmentListUI, utils) { + function (compose, viewHelper, Recipients, DraftSaveStatus, events, i18n, SendButton, AttachmentIcon, attachmentList, utils) { 'use strict'; function withMailEditBase() { @@ -93,12 +94,12 @@ define( context.recipients = {to: [], cc: [], bcc: []}; } this.attr.recipientValues = context.recipients; + this.attr.attachments = context.attachments || []; this.attachRecipients(context); this.on(this.select('trashButton'), 'click', this.discardMail); SendButton.attachTo(this.select('sendButton')); AttachmentIcon.attachTo(this.select('attachmentButton')); - AttachmentListUI.attachTo(this.select('attachmentList')); this.warnSendButtonOfRecipients(); }; @@ -149,108 +150,113 @@ 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.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(); + }); + + compose.mixin(this, [attachmentList]); + } + + return withMailEditBase; + }); -- cgit v1.2.3