2016-11-02 20:45:11 +01:00
|
|
|
/* globals startDate, showOnlyTop, showFullList, endDate, reportType, expenseReportUri, accountIds, incExpReportUri,accountReportUri, incomeReportUri */
|
2016-04-01 16:06:55 +02:00
|
|
|
/*
|
|
|
|
* all.js
|
2016-04-01 16:46:11 +02:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
2016-04-01 16:06:55 +02:00
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
"use strict";
|
|
|
|
|
2016-10-26 16:46:43 +02:00
|
|
|
|
2016-10-08 16:24:07 +02:00
|
|
|
// load the account report, which this report shows:
|
2016-11-02 20:45:11 +01:00
|
|
|
loadAjaxPartial('accountReport', accountReportUri);
|
2016-10-08 16:24:07 +02:00
|
|
|
|
2016-11-02 20:45:11 +01:00
|
|
|
// load income and expense reports:
|
2016-11-02 20:52:40 +01:00
|
|
|
loadAjaxPartial('incomeReport', incomeReportUri);
|
|
|
|
loadAjaxPartial('expenseReport', expenseReportUri);
|
|
|
|
loadAjaxPartial('incomeVsExpenseReport', incExpReportUri);
|
2016-10-25 18:53:54 +02:00
|
|
|
|
2016-04-01 16:06:55 +02:00
|
|
|
});
|
|
|
|
|
2016-10-26 16:46:43 +02:00
|
|
|
function triggerInfoClick() {
|
|
|
|
"use strict";
|
|
|
|
// find the little info buttons and respond to them.
|
2016-11-02 20:45:11 +01:00
|
|
|
$('.firefly-info-button').unbind('click').click(clickInfoButton);
|
2016-10-26 16:46:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-25 18:53:54 +02:00
|
|
|
function listLengthInitial() {
|
|
|
|
"use strict";
|
|
|
|
$('.overListLength').hide();
|
|
|
|
$('.listLengthTrigger').unbind('click').click(triggerList)
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerList(e) {
|
|
|
|
"use strict";
|
|
|
|
var link = $(e.target);
|
|
|
|
var table = link.parent().parent().parent().parent();
|
|
|
|
console.log('data-hidden = ' + table.attr('data-hidden'));
|
|
|
|
if (table.attr('data-hidden') === 'no') {
|
|
|
|
// hide all elements, return false.
|
|
|
|
table.find('.overListLength').hide();
|
|
|
|
table.attr('data-hidden', 'yes');
|
|
|
|
link.text(showFullList);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// show all, return false
|
|
|
|
table.find('.overListLength').show();
|
|
|
|
table.attr('data-hidden', 'no');
|
|
|
|
link.text(showOnlyTop);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-01 16:06:55 +02:00
|
|
|
function clickInfoButton(e) {
|
|
|
|
"use strict";
|
|
|
|
// find all data tags, regardless of what they are:
|
|
|
|
var element = $(e.target);
|
|
|
|
var attributes = element.data();
|
|
|
|
|
2016-04-03 11:07:51 +02:00
|
|
|
// set wait cursor
|
|
|
|
$('body').addClass('waiting');
|
|
|
|
|
2016-04-01 16:06:55 +02:00
|
|
|
// add some more elements:
|
|
|
|
attributes.startDate = startDate;
|
|
|
|
attributes.endDate = endDate;
|
|
|
|
attributes.reportType = reportType;
|
|
|
|
attributes.accounts = accountIds;
|
|
|
|
|
2016-09-16 13:29:56 +02:00
|
|
|
$.getJSON('popup/report', {attributes: attributes}).done(respondInfoButton).fail(errorInfoButton);
|
2016-04-01 16:06:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function errorInfoButton(data) {
|
|
|
|
"use strict";
|
2016-04-03 11:07:51 +02:00
|
|
|
// remove wait cursor
|
|
|
|
$('body').removeClass('waiting');
|
|
|
|
alert('Apologies. The requested data is not (yet) available.');
|
2016-04-01 16:06:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function respondInfoButton(data) {
|
|
|
|
"use strict";
|
2016-04-03 11:07:51 +02:00
|
|
|
// remove wait cursor
|
|
|
|
$('body').removeClass('waiting');
|
2016-11-02 20:45:11 +01:00
|
|
|
$('#defaultModal').empty().html(data.html).modal('show');
|
2016-04-01 16:06:55 +02:00
|
|
|
|
2016-11-02 20:08:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadAjaxPartial(holder, uri) {
|
|
|
|
"use strict";
|
|
|
|
console.log('Going to grab URI ' + uri);
|
|
|
|
$.get(uri).done(function (data) {
|
|
|
|
displayAjaxPartial(data, holder);
|
|
|
|
}).fail(function () {
|
|
|
|
failAjaxPartial(uri, holder);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayAjaxPartial(data, holder) {
|
|
|
|
"use strict";
|
|
|
|
console.log('Display stuff in ' + holder);
|
|
|
|
var obj = $('#' + holder);
|
|
|
|
obj.removeClass('loading').html(data);
|
|
|
|
|
|
|
|
// call some often needed recalculations and what-not:
|
|
|
|
|
|
|
|
// find a sortable table and make it sortable:
|
2016-11-02 20:52:40 +01:00
|
|
|
if (typeof $.bootstrapSortable === "function") {
|
|
|
|
$.bootstrapSortable(true);
|
|
|
|
}
|
2016-11-02 20:45:11 +01:00
|
|
|
|
|
|
|
// find the info click things and respond to them:
|
|
|
|
triggerInfoClick();
|
|
|
|
|
|
|
|
// trigger list thing
|
|
|
|
listLengthInitial();
|
2016-11-06 15:04:35 +01:00
|
|
|
|
|
|
|
// budget thing
|
|
|
|
$('.budget-chart-activate').unbind('click').on('click', clickBudgetChart);
|
2016-11-02 20:08:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function failAjaxPartial(uri, holder) {
|
|
|
|
"use strict";
|
|
|
|
console.log('Failed to load' + uri);
|
|
|
|
$('#' + holder).removeClass('loading').addClass('general-chart-error');
|
|
|
|
|
2016-11-06 15:04:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function clickBudgetChart(e) {
|
|
|
|
"use strict";
|
|
|
|
var link = $(e.target);
|
|
|
|
var budgetId = link.data('budget');
|
|
|
|
var URL = 'chart/budget/period/' + budgetId + '/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds;
|
|
|
|
var container = 'budget_chart';
|
|
|
|
// if chart drawn is false, draw the first one, then
|
|
|
|
// set to true
|
|
|
|
if (chartDrawn == false) {
|
|
|
|
// do new chart:
|
|
|
|
|
|
|
|
|
|
|
|
$.getJSON(URL).done(function (data) {
|
|
|
|
console.log('Will draw new columnChart(' + URL + ')');
|
|
|
|
|
|
|
|
var ctx = document.getElementById(container).getContext("2d");
|
|
|
|
var newData = {};
|
|
|
|
newData.datasets = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < data.count; i++) {
|
|
|
|
newData.labels = data.labels;
|
|
|
|
var dataset = data.datasets[i];
|
|
|
|
dataset.backgroundColor = fillColors[i];
|
|
|
|
newData.datasets.push(dataset);
|
|
|
|
}
|
|
|
|
// completely new chart.
|
|
|
|
budgetChart = new Chart(ctx, {
|
|
|
|
type: 'bar',
|
|
|
|
data: data,
|
|
|
|
options: defaultColumnOptions
|
|
|
|
});
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
$('#' + container).addClass('general-chart-error');
|
|
|
|
});
|
|
|
|
console.log('URL for column chart : ' + URL);
|
|
|
|
chartDrawn = true;
|
|
|
|
} else {
|
|
|
|
console.log('Will now handle remove data and add new!');
|
|
|
|
$.getJSON(URL).done(function (data) {
|
|
|
|
console.log('Will draw updated columnChart(' + URL + ')');
|
|
|
|
var newData = {};
|
|
|
|
newData.datasets = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < data.count; i++) {
|
|
|
|
newData.labels = data.labels;
|
|
|
|
var dataset = data.datasets[i];
|
|
|
|
dataset.backgroundColor = fillColors[i];
|
|
|
|
newData.datasets.push(dataset);
|
|
|
|
}
|
|
|
|
// update the chart
|
|
|
|
console.log('Now update chart thing.');
|
|
|
|
budgetChart.data.datasets = newData.datasets;
|
|
|
|
budgetChart.update();
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
$('#' + container).addClass('general-chart-error');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-04-01 16:06:55 +02:00
|
|
|
}
|