jQuery.fn.extend do
copy : -> @clone!remove-attr 'id class'
jq = (f) -> !-> $ f
# Call this to localize HighCharts
set_lang = ->
Highcharts .setOptions do
lang:
months: [\Januar, \Februar, \März, \April, \Mai, \Juni, \Juli, \August, \September, \Oktober, \November, \Dezember]
shortMonths: [\Jan, \Feb, \Mär, \Apr, \Mai, \Jun, \Jul, \Aug, \Sep, \Okt, \Nov, \Dez]
weekdays: [\Sonntag, \Montag, \Dienstag, \Mittwoch, \Donnerstag, \Freitag, \Samstag]
rangeSelectorFrom: \von
rangeSelectorTo: \bis
rangeSelectorZoom: null
# Add
export addJS = jq ->
$ 'input[name=date]' .datepicker do
dateFormat: \dd.mm.yy
firstDay: 1
# Show
export showJS = jq ->
set_lang!
$ ".detail .heading" .click ->
$ @ .closest \.detail .children \.mark:first .click!
$ ".detail > .mark" .click ->
if (@src.indexOf \closed) is not -1
@src .= replace \closed \open
else
@src .= replace \open \closed
$ @ .next-all \.details:first .toggle!
$ \.details .hide!
# draw the pies
<- $ \.pie .each
$ @
..highcharts do
title: text: null
tooltip:
hideDelay: 200
formatter: ->
"#{@key}: #{@y.toFixed 2} € / #{@percentage.toFixed 2}%"
chart:
backgroundColor: null
plotBorderWidth: null
plotShadow: off
spacingTop: 0
credits: enabled: false
series: [
type: \pie
size: \70%
allowPointSelect: true
dataLabels:
color: ..css \color
distance: 20
data: [ {name: if v>0 then k else '' , y: v, visible: v > 0} \
for k,v of ..data \pie ]
]
# Statistics
export statJS = jq ->
set_lang!
month = 30 * 24 * 60 * 60 * 1000
<- $ \.stats .each
$ @
..highcharts 'StockChart' do
title: text: null
credits: enabled: false
rangeSelector:
buttons: []
inputDateFormat: "%d. %b %Y"
inputEditDateFormat: "%d.%m.%Y"
inputDateParser: (value) ->
value .= split /\./
Date.UTC(value[2], # year
value[1] - 1, # month ... 0-based -.-
value[0], #day
0,0,0,0 # time
)
xAxis:
minTickInterval: month
minRange: month
series: [
data : ..data \stats
]
tooltip:
pointFormat: "{point.y} €
"
# Categories
export catsJS = jq ->
counter = 0
add_img = $ \img#add
new_input = $ \input#new
new_image = (new_name) ->
# we need to copy the image to get the correct URL
add_img.copy!
..attr \src -> @src.replace \add new_name
$ "li > span" .click ->
span = $ @
input = span.next!
img = new_image \undo
..click ->
$ @ .remove!
# reset text
input.val span.text!
<- input.fade-out \slow
span.toggle!
span.toggle!
<- input.fade-in \slow
img.insert-after input
add_img.click ->
input = new_input.copy!
img = new_image \minus
..click ->
<- $ @ .parent!fade-out \slow
$ @ .remove!
input.attr \name -> @name + counter
.remove-attr \style
.wrap "