jQuery.fn.extend do
copy : -> @clone!remove-attr 'id class'
jq = (f) -> !-> $ f
# Call this to localize Highcharts
set-lang = ->
Highcharts .set-options do
lang:
months: [\Januar, \Februar, \März, \April, \Mai, \Juni, \Juli, \August, \September, \Oktober, \November, \Dezember]
short-months: [\Jan, \Feb, \Mär, \Apr, \Mai, \Jun, \Jul, \Aug, \Sep, \Okt, \Nov, \Dez]
weekdays: [\Sonntag, \Montag, \Dienstag, \Mittwoch, \Donnerstag, \Freitag, \Samstag]
range-selector-from: \von
range-selector-to: \bis
range-selector-zoom: null
# Add
export addJS = jq ->
$ 'input[name=date]' .datepicker do
date-format: \dd.mm.yy
first-day: 1
# Show
export showJS = jq ->
set-lang!
$ ".detail .heading" .click ->
$ @ .closest \.detail .children \.mark:first .click!
$ ".detail > .mark" .click ->
if (@src.index-of \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:
hide-delay: 200
formatter: ->
"#{@key}: #{@y.toFixed 2} € / #{@percentage.to-fixed 2}%"
chart:
background-color: null
plot-border-width: null
plot-shadow: off
spacing-top: 0
credits: enabled: false
series: [
type: \pie
size: \70%
allow-point-select: true
data-labels:
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
range-selector:
buttons: []
input-date-format: "%d. %b %Y"
input-edit-date-format: "%d.%m.%Y"
input-date-parser: (value) ->
value .= split /\./
Date.UTC value[2], # year
value[1] - 1, # month ... 0-based -.-
value[0], #day
0,0,0,0 # time
x-axis:
min-tick-interval: month
min-range: month
series: [
data : ..data \stats
]
tooltip:
point-format: "{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 "