summaryrefslogtreecommitdiff
path: root/static/js/kosten.ls
blob: fa96f4a8e4b4d1433a0a1df49bcc1935f15b046d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
jQuery.fn.extend do
    copy : -> @clone!remove-attr 'id class'

jq = (f) -> !-> $ f

# Add
export addJS = jq ->
    $ 'input[name=date]' .datepicker do
        dateFormat: \dd.mm.yy
        firstDay: 1

# Show
export showJS = jq ->
    $ ".detail span" .click ->
        $ @ .prev-all \.mark:last .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}: <b>#{@y.toFixed 2} €</b> / #{@percentage.toFixed 2}%"
            chart:
                backgroundColor: null
                plotBorderWidth: null
                plotShadow: off
                margin: [0,0,0,0]
            credits: enabled: false
            series: [
                type: \pie
                size: \50%
                allowPointSelect: true
                dataLabels:
                    color: ..css \color
                data: [ {name: if v>0 then k else '' , y: v, visible: v > 0} \
                        for k,v of ..data \pie ]
            ]

# 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 "<li />"
            .parent! # wrap does not return the li
            .append img
            .hide!
            .insert-before add_img.parent!
            .fade-in \slow -> input.focus!

        counter++