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/mail_view/data/attachment_list.js | 52 ------------------------- web-ui/app/js/mail_view/ui/attachment_icon.js | 1 - web-ui/app/js/mail_view/ui/attachment_list.js | 29 +++++++------- web-ui/app/js/mail_view/ui/compose_box.js | 7 ++-- web-ui/app/js/mail_view/ui/draft_box.js | 5 ++- 5 files changed, 21 insertions(+), 73 deletions(-) delete mode 100644 web-ui/app/js/mail_view/data/attachment_list.js (limited to 'web-ui/app/js/mail_view') diff --git a/web-ui/app/js/mail_view/data/attachment_list.js b/web-ui/app/js/mail_view/data/attachment_list.js deleted file mode 100644 index d1d07e0c..00000000 --- a/web-ui/app/js/mail_view/data/attachment_list.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2015 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 . - */ - -define( - [ - 'page/events' - ], - - function (events) { - 'use strict'; - - function attachmentList() { - this.defaultAttrs({ - attachments: [] - }); - - this.addAttachment = function (event, data) { - this.attr.attachments.push(data); - }; - - this.resetAttachmentList = function () { - this.attr.attachments = []; - }; - - this.resetAll = function () { - this.resetAttachmentList(); - this.teardown(); - }; - - this.after('initialize', function () { - this.on(document, events.mail.appendAttachment, this.addAttachment); - this.on(document, events.mail.resetAttachments, this.resetAttachmentList); - this.on(document, events.mail.sent, this.resetAll); - }); - } - - return attachmentList; - }); \ No newline at end of file diff --git a/web-ui/app/js/mail_view/ui/attachment_icon.js b/web-ui/app/js/mail_view/ui/attachment_icon.js index 802087f8..b9028f2c 100644 --- a/web-ui/app/js/mail_view/ui/attachment_icon.js +++ b/web-ui/app/js/mail_view/ui/attachment_icon.js @@ -37,7 +37,6 @@ define( this.after('initialize', function () { if (features.isEnabled('attachment')) { this.render(); - $('.attachmentsAreaWrap').hide(); } this.on(this.$node, 'click', this.triggerUploadAttachment); }); diff --git a/web-ui/app/js/mail_view/ui/attachment_list.js b/web-ui/app/js/mail_view/ui/attachment_list.js index 60e6abad..32a48d0b 100644 --- a/web-ui/app/js/mail_view/ui/attachment_list.js +++ b/web-ui/app/js/mail_view/ui/attachment_list.js @@ -17,11 +17,10 @@ define( [ - 'flight/lib/component', 'page/events' ], - function (defineComponent, events) { + function (events) { 'use strict'; function attachmentList() { @@ -29,14 +28,19 @@ define( inputFileUpload: '#fileupload', attachmentListItem: '#attachment-list-item', progressBar: '#progress .progress-bar', - attachmentBaseUrl: '/attachment' + attachmentBaseUrl: '/attachment', + attachments: [] }); - this.showAttachment = function (event, data) { + this.showAttachment = function (ev, data) { this.trigger(document, events.mail.appendAttachment, data); this.renderAttachmentListView(data); }; + this.addAttachment = function (event, data) { + this.attr.attachments.push(data); + }; + this.renderAttachmentListView = function (data) { var currentHtml = this.select('attachmentListItem').html(); var item = this.buildAttachmentListItem(data); @@ -48,9 +52,9 @@ define( return (bytes / Math.pow(1024, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + 'b'; } - this.buildAttachmentListItem = function (data) { - return '' + data.filename + ' (' + humanReadable(data.filesize) + ')' + + this.buildAttachmentListItem = function (attachment) { + return '' + attachment.name + ' (' + humanReadable(attachment.size) + ')' + ''; }; @@ -74,20 +78,17 @@ define( } this.startUpload = function () { + addJqueryFileUploadConfig(this); this.select('inputFileUpload').click(); }; - this.resetAll = function () { - this.teardown(); - }; - this.after('initialize', function () { - addJqueryFileUploadConfig(this); this.on(document, events.mail.uploadedAttachment, this.showAttachment); this.on(document, events.mail.startUploadAttachment, this.startUpload); - this.on(document, events.mail.sent, this.resetAll); + //this.on(document, events.mail.sent, this.resetAll); + this.on(document, events.mail.appendAttachment, this.addAttachment); }); } - return defineComponent(attachmentList); + return attachmentList; }); \ No newline at end of file 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 48a7c23f..101dc939 100644 --- a/web-ui/app/js/mail_view/ui/compose_box.js +++ b/web-ui/app/js/mail_view/ui/compose_box.js @@ -20,14 +20,13 @@ define( 'views/templates', 'mixins/with_mail_edit_base', 'page/events', - 'mail_view/data/mail_builder', - 'mail_view/data/attachment_list' + 'mail_view/data/mail_builder' ], - function (defineComponent, templates, withMailEditBase, events, mailBuilder, attachmentList) { + function (defineComponent, templates, withMailEditBase, events, mailBuilder) { 'use strict'; - return defineComponent(composeBox, withMailEditBase, attachmentList); + return defineComponent(composeBox, withMailEditBase); function composeBox() { 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 675020cb..6a640d88 100644 --- a/web-ui/app/js/mail_view/ui/draft_box.js +++ b/web-ui/app/js/mail_view/ui/draft_box.js @@ -48,6 +48,7 @@ define( .cc(this.attr.recipientValues.cc) .bcc(this.attr.recipientValues.bcc) .body(this.select('bodyBox').val()) + .attachment(this.attr.attachments) .tag(tag); }; @@ -55,7 +56,6 @@ define( var mail = data.mail; var body = mail.textPlainBody; this.attr.ident = mail.ident; - this.render(templates.compose.box, { recipients: { to: mail.header.to, @@ -63,7 +63,8 @@ define( bcc: mail.header.bcc }, subject: mail.header.subject, - body: body + body: body, + attachments: mail.attachments }); this.enableFloatlabel('input.floatlabel'); -- cgit v1.2.3