Added new template helpers.
This commit is contained in:
parent
7bd5c7511d
commit
255ad93737
1 changed files with 47 additions and 0 deletions
|
@ -32,6 +32,53 @@ class App extends Spine.Controller
|
||||||
# return raw data
|
# return raw data
|
||||||
item
|
item
|
||||||
|
|
||||||
|
# define date format helper
|
||||||
|
params.date = ( time ) ->
|
||||||
|
return '' if !time
|
||||||
|
s = ( num, digits ) ->
|
||||||
|
while num.toString().length < digits
|
||||||
|
num = "0" + num
|
||||||
|
num
|
||||||
|
|
||||||
|
timeObject = new Date(time)
|
||||||
|
d = s( timeObject.getDate(), 2 )
|
||||||
|
m = s( timeObject.getMonth() + 1, 2 )
|
||||||
|
y = timeObject.getFullYear()
|
||||||
|
"#{y}-#{m}-#{d}"
|
||||||
|
|
||||||
|
# define datetime format helper
|
||||||
|
params.datetime = ( time ) ->
|
||||||
|
return '' if !time
|
||||||
|
s = ( num, digits ) ->
|
||||||
|
while num.toString().length < digits
|
||||||
|
num = "0" + num
|
||||||
|
num
|
||||||
|
|
||||||
|
timeObject = new Date(time)
|
||||||
|
d = s( timeObject.getDate(), 2 )
|
||||||
|
m = s( timeObject.getMonth() + 1, 2 )
|
||||||
|
y = timeObject.getFullYear()
|
||||||
|
S = s( timeObject.getSeconds(), 2 )
|
||||||
|
M = s( timeObject.getMinutes(), 2 )
|
||||||
|
H = s( timeObject.getHours(), 2 )
|
||||||
|
"#{y}-#{m}-#{d} #{H}:#{M}:#{S}"
|
||||||
|
|
||||||
|
# define decimal format helper
|
||||||
|
params.decimal = ( data, positions = 2 ) ->
|
||||||
|
return '' if !data
|
||||||
|
s = ( num, digits ) ->
|
||||||
|
while num.toString().length < digits
|
||||||
|
num = num + "0"
|
||||||
|
num
|
||||||
|
result = data.toString().match(/^(.+?)\.(.+?)$/)
|
||||||
|
if !result || !result[2]
|
||||||
|
return "#{data}." + s( 0, positions ).toString()
|
||||||
|
length = result[2].toString().length
|
||||||
|
diff = positions - length
|
||||||
|
if diff > 0
|
||||||
|
return "#{result[1]}." + s( result[2], positions ).toString()
|
||||||
|
"#{result[1]}.#{result[2].substr(0,positions)}"
|
||||||
|
|
||||||
# define translation helper
|
# define translation helper
|
||||||
params.T = ( item, args... ) ->
|
params.T = ( item, args... ) ->
|
||||||
App.i18n.translateContent( item, args )
|
App.i18n.translateContent( item, args )
|
||||||
|
|
Loading…
Reference in a new issue