Files
firefly-iii/public/assets/javascript/firefly/accounts.js

132 lines
3.9 KiB
JavaScript
Raw Normal View History

2014-07-27 20:29:58 +02:00
$(function () {
if ($('#accountTable').length == 1) {
drawDatatable();
}
if ($('#overviewChart').length == 1) {
drawOverviewChart();
}
});
function drawDatatable() {
var opt = {
serverSide: true,
ajax: URL,
paging: true,
processing: true,
columns: [
{
name: 'name',
data: 'name',
searchable: true,
render: function (data) {
return '<a href="' + data.url + '">' + data.name + '</a>';
}
},
{
name: 'balance',
data: 'balance',
title: 'Amount (\u20AC)',
searchable: false,
sortable: true,
render: function (data) {
var amount = parseInt(data);
if (amount < 0) {
'<span class="text-danger">\u20AC ' + data.toFixed(2) + '</span>'
}
if (amount > 0) {
'<span class="text-info">\u20AC ' + data.toFixed(2) + '</span>'
}
return '<span class="text-info">\u20AC ' + data.toFixed(2) + '</span>'
}
},
{
name: 'id',
data: 'id',
title: '',
render: function (data) {
return '<div class="btn-group btn-group-xs">' +
'<a class="btn btn-default btn-xs" href="' + data.edit + '">' +
'<span class="glyphicon glyphicon-pencil"</a>' +
'<a class="btn btn-danger btn-xs" href="' + data.delete + '">' +
'<span class="glyphicon glyphicon-trash"</a>' +
'</a></div>';
}
}
]
};
$('#accountTable').DataTable(opt);
}
function drawOverviewChart() {
2014-07-27 20:29:58 +02:00
$.getJSON('chart/home/account/' + accountID).success(function (data) {
var options = {
chart: {
renderTo: 'overviewChart',
type: 'spline'
2014-07-27 20:29:58 +02:00
},
series: data.series,
2014-07-27 20:29:58 +02:00
title: {
2014-09-11 21:58:08 +02:00
text: null
2014-07-27 20:29:58 +02:00
},
yAxis: {
2014-09-11 21:58:08 +02:00
allowDecimals: false,
labels: {
formatter: function () {
if (this.value >= 1000 || this.value <= -1000) {
2014-09-11 21:58:08 +02:00
return '\u20AC ' + (this.value / 1000) + 'k';
}
return '\u20AC ' + this.value;
2014-07-27 20:29:58 +02:00
2014-09-11 21:58:08 +02:00
}
},
title: {text: null}
},
2014-07-27 20:29:58 +02:00
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: '%e %b',
2014-09-11 21:58:08 +02:00
week: '%e %b'
2014-07-27 20:29:58 +02:00
},
title: {
2014-09-11 21:58:08 +02:00
text: null
2014-07-27 20:29:58 +02:00
}
},
legend: {enabled: false},
2014-07-27 20:29:58 +02:00
tooltip: {
formatter: function () {
return this.series.name + ': \u20AC ' + Highcharts.numberFormat(this.y, 2);
2014-07-27 20:29:58 +02:00
}
},
plotOptions: {
line: {
shadow: true
},
series: {
cursor: 'pointer',
negativeColor: '#FF0000',
threshold: 0,
lineWidth: 1,
marker: {
2014-09-11 21:58:08 +02:00
radius: 0
2014-07-27 20:29:58 +02:00
},
point: {
events: {
click: function (e) {
2014-09-11 21:58:08 +02:00
alert('click!');
2014-07-27 20:29:58 +02:00
}
}
}
}
},
credits: {
enabled: false
}
};
$('#overviewChart').highcharts(options);
2014-07-27 20:29:58 +02:00
});
}