Files
firefly-iii/public/js/ff/reports/default/all.js

130 lines
3.6 KiB
JavaScript
Raw Normal View History

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
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
2016-04-01 16:06:55 +02:00
*/
/** global: accountReportUri, incomeReportUri, expenseReportUri, incExpReportUri, startDate, endDate, accountIds */
2016-04-01 16:06:55 +02:00
$(function () {
"use strict";
2016-10-08 16:24:07 +02:00
// load the account report, which this report shows:
loadAjaxPartial('accountReport', accountReportUri);
2016-10-08 16:24:07 +02:00
// load income and expense reports:
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
});
function triggerInfoClick() {
"use strict";
// find the little info buttons and respond to them.
$('.firefly-info-button').unbind('click').click(clickInfoButton);
}
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.accounts = accountIds;
2016-12-06 09:07:50 +01:00
$.getJSON('popup/general', {attributes: attributes}).done(respondInfoButton).fail(errorInfoButton);
2016-04-01 16:06:55 +02:00
}
function errorInfoButton() {
2016-04-01 16:06:55 +02:00
"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');
$('#defaultModal').empty().html(data.html).modal('show');
2016-04-01 16:06:55 +02:00
}
function loadAjaxPartial(holder, uri) {
"use strict";
$.get(uri).done(function (data) {
displayAjaxPartial(data, holder);
}).fail(function () {
failAjaxPartial(uri, holder);
});
}
function displayAjaxPartial(data, holder) {
"use strict";
var obj = $('#' + holder);
obj.html(data);
obj.parent().find('.overlay').remove();
// call some often needed recalculations and what-not:
// find a sortable table and make it sortable:
if (typeof $.bootstrapSortable === "function") {
$.bootstrapSortable(true);
}
// find the info click things and respond to them:
triggerInfoClick();
// trigger list thing
listLengthInitial();
2016-11-06 15:04:35 +01:00
2016-12-03 21:48:40 +01:00
// budget thing in year and multi year report:
2016-11-06 15:04:35 +01:00
$('.budget-chart-activate').unbind('click').on('click', clickBudgetChart);
2016-12-03 21:48:40 +01:00
// category thing in year and multi year report:
$('.category-chart-activate').unbind('click').on('click', clickCategoryChart);
}
function failAjaxPartial(uri, holder) {
"use strict";
2017-04-09 07:56:46 +02:00
var holderObject = $('#' + holder);
holderObject.parent().find('.overlay').remove();
holderObject.addClass('general-chart-error');
2016-11-06 15:04:35 +01:00
}
2016-12-03 21:48:40 +01:00
function clickCategoryChart(e) {
"use strict";
var link = $(e.target);
var categoryId = link.data('category');
2017-09-03 11:02:18 +02:00
$('#category_help').remove();
2016-12-03 21:48:40 +01:00
2016-12-06 07:48:41 +01:00
var URL = 'chart/category/report-period/' + categoryId + '/' + accountIds + '/' + startDate + '/' + endDate;
2016-12-03 21:48:40 +01:00
var container = 'category_chart';
columnChart(URL, container);
return false;
}
2016-11-06 15:04:35 +01:00
function clickBudgetChart(e) {
"use strict";
var link = $(e.target);
var budgetId = link.data('budget');
2017-09-03 11:02:18 +02:00
$('#budget_help').remove();
2016-11-16 20:35:25 +01:00
2016-12-06 07:06:20 +01:00
var URL = 'chart/budget/period/' + budgetId + '/' + accountIds + '/' + startDate + '/' + endDate;
2016-11-06 15:04:35 +01:00
var container = 'budget_chart';
2016-11-16 20:35:25 +01:00
columnChart(URL, container);
2016-11-06 15:04:35 +01:00
return false;
2016-04-01 16:06:55 +02:00
}