2016-10-25 11:53:54 -05:00
|
|
|
/* globals startDate, showOnlyTop, showFullList, endDate, reportType, accountIds, inOutReportUrl, accountReportUrl */
|
2016-04-01 09:06:55 -05:00
|
|
|
/*
|
|
|
|
* all.js
|
2016-04-01 09:46:11 -05:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
2016-04-01 09:06:55 -05:00
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// find the little info buttons and respond to them.
|
|
|
|
$('.firefly-info-button').click(clickInfoButton);
|
|
|
|
|
2016-10-08 09:24:07 -05:00
|
|
|
// load the account report, which this report shows:
|
|
|
|
loadAccountReport();
|
|
|
|
|
2016-10-25 11:53:54 -05:00
|
|
|
// load income / expense / difference:
|
|
|
|
loadInOutReport();
|
|
|
|
|
|
|
|
// trigger list length things:
|
|
|
|
listLengthInitial();
|
|
|
|
|
2016-04-01 09:06:55 -05:00
|
|
|
});
|
|
|
|
|
2016-10-25 11:53:54 -05: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadInOutReport() {
|
|
|
|
"use strict";
|
|
|
|
console.log('Going to grab ' + inOutReportUrl);
|
|
|
|
$.get(inOutReportUrl).done(placeInOutReport).fail(failInOutReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
function placeInOutReport(data) {
|
|
|
|
"use strict";
|
|
|
|
$('#incomeReport').removeClass('loading').html(data.income);
|
|
|
|
$('#expenseReport').removeClass('loading').html(data.expenses);
|
|
|
|
$('#incomeVsExpenseReport').removeClass('loading').html(data.incomes_expenses);
|
|
|
|
listLengthInitial();
|
|
|
|
}
|
|
|
|
|
|
|
|
function failInOutReport() {
|
|
|
|
"use strict";
|
|
|
|
console.log('Fail in/out report data!');
|
|
|
|
$('#incomeReport').removeClass('loading').addClass('general-chart-error');
|
|
|
|
$('#expenseReport').removeClass('loading').addClass('general-chart-error');
|
|
|
|
$('#incomeVsExpenseReport').removeClass('loading').addClass('general-chart-error');
|
|
|
|
}
|
|
|
|
|
2016-10-08 09:24:07 -05:00
|
|
|
function loadAccountReport() {
|
|
|
|
"use strict";
|
|
|
|
$.get(accountReportUrl).done(placeAccountReport).fail(failAccountReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
function placeAccountReport(data) {
|
|
|
|
"use strict";
|
|
|
|
$('#accountReport').removeClass('loading').html(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function failAccountReport(data) {
|
|
|
|
"use strict";
|
|
|
|
$('#accountReport').removeClass('loading').addClass('general-chart-error');
|
|
|
|
}
|
|
|
|
|
2016-04-01 09:06:55 -05: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 04:07:51 -05:00
|
|
|
// set wait cursor
|
|
|
|
$('body').addClass('waiting');
|
|
|
|
|
2016-04-01 09:06:55 -05:00
|
|
|
// add some more elements:
|
|
|
|
attributes.startDate = startDate;
|
|
|
|
attributes.endDate = endDate;
|
|
|
|
attributes.reportType = reportType;
|
|
|
|
attributes.accounts = accountIds;
|
|
|
|
|
2016-09-16 06:29:56 -05:00
|
|
|
$.getJSON('popup/report', {attributes: attributes}).done(respondInfoButton).fail(errorInfoButton);
|
2016-04-01 09:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function errorInfoButton(data) {
|
|
|
|
"use strict";
|
2016-04-03 04:07:51 -05:00
|
|
|
// remove wait cursor
|
|
|
|
$('body').removeClass('waiting');
|
|
|
|
alert('Apologies. The requested data is not (yet) available.');
|
2016-04-01 09:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function respondInfoButton(data) {
|
|
|
|
"use strict";
|
2016-04-03 04:07:51 -05:00
|
|
|
// remove wait cursor
|
|
|
|
$('body').removeClass('waiting');
|
2016-04-01 09:06:55 -05:00
|
|
|
$('#defaultModal').empty().html(data.html);
|
|
|
|
$('#defaultModal').modal('show');
|
|
|
|
|
|
|
|
}
|