This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haushalt.js
128 lines (114 loc) · 3.62 KB
/
haushalt.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var currentRequest = false;
var _nav = {
"2013": {"3": "Erträge", "4": "Aufwendungen", "11": "Forderungen", "21": "Verpflichtungen", "12": "Barvermögen"},
"2014": {"3": "Erträge", "4": "Aufwendungen", "12": "Forderungen", "23": "Verpflichtungen", "13": "Barvermögen"}
};
function formatCurrency(value) {
if (value == 0) {
return "-";
}
var units = [
{ unit: "EUR",
fixed: 2 },
/**
{ unit: "Tsd EUR",
fixed: 1 },
{ unit: "Mio EUR",
fixed: 1 },
{ unit: "Mrd EUR",
fixed: 1 }
**/
];
var curUnit = 0;
while (Math.abs(value) > 1500 && curUnit < units.length-1) {
value /= 1000;
curUnit++;
}
return value.toFixed(units[curUnit].fixed) + " " + units[curUnit].unit;
}
function clearView() {
$("title").text("Junge Piraten Haushalt");
$(".haushaltNav").removeClass("active");
$(".parentBudget").addClass("disabled").unbind("click");
$(".exportJson").attr("href","#");
$(".subBudgets tbody").empty();
$(".ktoNav").empty();
viz_hide();
}
function initView(year, budgetCode) {
$(".year").text(year);
for (var ktoPrefix in _nav[year]) {
var kto = ktoPrefix + "00000".substring(ktoPrefix.length, 5);
var item = $("<li>").addClass("haushaltNav").addClass("budget-" + ktoPrefix)
.append($("<a>")
.data("kto",kto)
.click(function () {
goToBudget(year, $(this).data("kto"));
}).text(_nav[year][ktoPrefix]));
$(".ktoNav").append(item);
}
if (currentRequest != false) {
currentRequest.abort();
}
currentRequest = $.ajax({
type: "GET",
url: "/getBudgetInfo.php?year=" + year + "&code=" + budgetCode,
success: function(data) {
if (data.label == null) {
$(".budgetLabel").text("(Unbekannt)");
$(".subBudgets tbody").append($("<tr>")
.append($("<td>").attr("colspan","3").text("Unbekannte Budgetnummer"))
);
return;
}
if (data.parentCode) {
$(".parentBudget").removeClass("disabled").click(function () {
goToBudget(year, data.parentCode);
});
}
$(".budgetLabel").text(data.label);
$(".budgetDescription").text(data.description);
$(".budgetValue").text(formatCurrency(Math.abs(data.value)));
$(".exportJson").attr("href","http://opendata.junge-piraten.de/konten/" + year + "/" + data.code + "/info.json");
$("title").text(data.label + " – Junge Piraten Haushalt " + year);
if (data.subaccounts.length == 0) {
$(".subBudgets tbody").append($("<tr>")
.append($("<td>").attr("colspan","3").text("Keine Unterbudgets vorhanden"))
);
} else {
data.subaccounts.sort(function (a, b) {
return a.code - b.code;
});
// Div by 0 otherwise
if (data.value != 0) {
viz_load(year, data);
}
for (var i in data.subaccounts) {
var subAccount = data.subaccounts[i];
$(".subBudgets tbody").append($("<tr>").css("cursor",(subAccount.hasSubAccounts ? "pointer" : "")).addClass("subBudget-" + subAccount.code)
.data("code", subAccount.code)
.data("hasSubAccounts", subAccount.hasSubAccounts)
.attr("title", subAccount.description + "")
.append($("<td>")
.append($("<div>").addClass("viz-icon").css({
width: "16px",
height: "16px",
border: "1px solid black",
background: viz_color(subAccount),
float: "left",
marginRight: "5px"
}).text(" "))
.append(subAccount.label) )
.append($("<td>").text(formatCurrency(Math.abs(subAccount.value))))
.append($("<td>").text((data.value == 0 ? " - " : Math.abs(subAccount.value / data.value * 100).toFixed(2) + " %")))
.click(function() {
if ($(this).data("hasSubAccounts")) {
goToBudget(year, $(this).data("code"));
}
})
);
}
}
}
});
}