Added @humanFileSize() helper for template files.

This commit is contained in:
Martin Edenhofer 2015-03-09 02:06:10 +01:00
parent bdfd51fc26
commit c128c2f742
4 changed files with 16 additions and 8 deletions

View file

@ -160,13 +160,7 @@ class App.Controller extends Spine.Controller
# human readable file size # human readable file size
humanFileSize: (size) => humanFileSize: (size) =>
if size > ( 1024 * 1024 ) App.Utils.humanFileSize(size)
size = Math.round( size / ( 1024 * 1024 ) ) + ' MB'
else if size > 1024
size = Math.round( size / 1024 ) + ' KB'
else
size = size + ' Bytes'
size
# human readable time # human readable time
humanTime: ( time, escalation, long = true ) => humanTime: ( time, escalation, long = true ) =>

View file

@ -212,6 +212,10 @@ class App extends Spine.Controller
result result
# define file size helper
params.humanFileSize = ( size ) ->
App.Utils.humanFileSize(size)
# define template # define template
JST["app/views/#{name}"](params) JST["app/views/#{name}"](params)
template template

View file

@ -273,3 +273,13 @@ class App.Utils
attachmentTranslatedRegExp = new RegExp( attachmentTranslated, 'i' ) attachmentTranslatedRegExp = new RegExp( attachmentTranslated, 'i' )
return true if message.match( attachmentTranslatedRegExp ) return true if message.match( attachmentTranslatedRegExp )
false false
# human readable file size
@humanFileSize: (size) =>
if size > ( 1024 * 1024 )
size = Math.round( size / ( 1024 * 1024 ) ) + ' MB'
else if size > 1024
size = Math.round( size / 1024 ) + ' KB'
else
size = size + ' Bytes'
size

View file

@ -56,7 +56,7 @@
<% for attachment in @article.attachments: %> <% for attachment in @article.attachments: %>
<div class="attachment horizontal"> <div class="attachment horizontal">
<a class="attachment-name u-highlight" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>" target="_blank" data-type="attachment"><%= attachment.filename %></a> <a class="attachment-name u-highlight" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>" target="_blank" data-type="attachment"><%= attachment.filename %></a>
<div class="attachment-size"><%= attachment.size %></div> <div class="attachment-size"><%- @humanFileSize(attachment.size) %></div>
</div> </div>
<% end %> <% end %>
</div> </div>