Added @humanFileSize() helper for template files.
This commit is contained in:
parent
bdfd51fc26
commit
c128c2f742
4 changed files with 16 additions and 8 deletions
|
@ -160,13 +160,7 @@ class App.Controller extends Spine.Controller
|
|||
|
||||
# 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
|
||||
App.Utils.humanFileSize(size)
|
||||
|
||||
# human readable time
|
||||
humanTime: ( time, escalation, long = true ) =>
|
||||
|
|
|
@ -212,6 +212,10 @@ class App extends Spine.Controller
|
|||
|
||||
result
|
||||
|
||||
# define file size helper
|
||||
params.humanFileSize = ( size ) ->
|
||||
App.Utils.humanFileSize(size)
|
||||
|
||||
# define template
|
||||
JST["app/views/#{name}"](params)
|
||||
template
|
||||
|
|
|
@ -273,3 +273,13 @@ class App.Utils
|
|||
attachmentTranslatedRegExp = new RegExp( attachmentTranslated, 'i' )
|
||||
return true if message.match( attachmentTranslatedRegExp )
|
||||
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
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
<% for attachment in @article.attachments: %>
|
||||
<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>
|
||||
<div class="attachment-size"><%= attachment.size %></div>
|
||||
<div class="attachment-size"><%- @humanFileSize(attachment.size) %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue