diff --git a/app/assets/javascripts/app/index.js.coffee b/app/assets/javascripts/app/index.js.coffee index b2874c142..996cb273c 100644 --- a/app/assets/javascripts/app/index.js.coffee +++ b/app/assets/javascripts/app/index.js.coffee @@ -32,6 +32,53 @@ class App extends Spine.Controller # return raw data 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 params.T = ( item, args... ) -> App.i18n.translateContent( item, args )