From 0c6c8bed304884ab5f3ade69fb0d68d2cbe043e6 Mon Sep 17 00:00:00 2001 From: NavaL Date: Mon, 11 Jan 2016 17:54:53 +0100 Subject: format attachment size Issue #573 --- web-ui/app/js/helpers/view_helper.js | 8 ++++++++ web-ui/app/js/mail_view/ui/attachment_list.js | 7 ++++--- web-ui/app/js/mail_view/ui/mail_view.js | 6 +----- web-ui/app/templates/compose/compose_box.hbs | 2 +- web-ui/app/templates/mails/full_view.hbs | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) (limited to 'web-ui/app') diff --git a/web-ui/app/js/helpers/view_helper.js b/web-ui/app/js/helpers/view_helper.js index 8d841cc7..e4e9277d 100644 --- a/web-ui/app/js/helpers/view_helper.js +++ b/web-ui/app/js/helpers/view_helper.js @@ -121,11 +121,19 @@ define( } } + function formatSize(bytes) { + var e = Math.floor(Math.log(bytes) / Math.log(1024)); + return (bytes / Math.pow(1024, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + 'b'; + } + + Handlebars.registerHelper('formatDate', formatDate); + Handlebars.registerHelper('formatSize', formatSize); Handlebars.registerHelper('formatStatusClasses', formatStatusClasses); return { formatStatusClasses: formatStatusClasses, + formatSize: formatSize, formatMailBody: formatMailBody, moveCaretToEndOfText: moveCaretToEndOfText, quoteMail: quoteMail, 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 32a48d0b..632242ca 100644 --- a/web-ui/app/js/mail_view/ui/attachment_list.js +++ b/web-ui/app/js/mail_view/ui/attachment_list.js @@ -17,10 +17,11 @@ define( [ - 'page/events' + 'page/events', + 'helpers/view_helper' ], - function (events) { + function (events, viewHelper) { 'use strict'; function attachmentList() { @@ -54,7 +55,7 @@ define( this.buildAttachmentListItem = function (attachment) { return '' + attachment.name + ' (' + humanReadable(attachment.size) + ')' + + attachment.name + '&encoding=' + attachment.encoding + '">' + attachment.name + ' (' + viewHelper.formatSize(attachment.size) + ')' + ''; }; 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 76c5b7d9..093f498d 100644 --- a/web-ui/app/js/mail_view/ui/mail_view.js +++ b/web-ui/app/js/mail_view/ui/mail_view.js @@ -56,10 +56,6 @@ define( encrypted = undefined; } - var attachments = _.map(data.mail.attachments, function(a){ - return { 'encoding': a.encoding, 'name': a.name, 'ident': a.ident }; - }); - this.$node.html(templates.mails.fullView({ header: data.mail.header, body: [], @@ -68,7 +64,7 @@ define( tags: data.mail.tags, encryptionStatus: encrypted, signatureStatus: signed, - attachments: attachments + attachments: data.mail.attachments })); this.$node.find('.bodyArea').html(viewHelpers.formatMailBody(data.mail)); diff --git a/web-ui/app/templates/compose/compose_box.hbs b/web-ui/app/templates/compose/compose_box.hbs index 902221e0..eb204501 100644 --- a/web-ui/app/templates/compose/compose_box.hbs +++ b/web-ui/app/templates/compose/compose_box.hbs @@ -36,7 +36,7 @@