Move some stuff over to AJAX thing.

This commit is contained in:
James Cole
2016-10-25 18:53:54 +02:00
parent e2d187d74b
commit a7e5fcc806
20 changed files with 164 additions and 247 deletions

View File

@@ -1,4 +1,4 @@
/* globals startDate, endDate, reportType, accountIds */
/* globals startDate, showOnlyTop, showFullList, endDate, reportType, accountIds, inOutReportUrl, accountReportUrl */
/*
* all.js
* Copyright (C) 2016 thegrumpydictator@gmail.com
@@ -7,10 +7,6 @@
* of the MIT license. See the LICENSE file for details.
*/
/**
* Created by sander on 01/04/16.
*/
$(function () {
"use strict";
@@ -20,8 +16,62 @@ $(function () {
// load the account report, which this report shows:
loadAccountReport();
// load income / expense / difference:
loadInOutReport();
// trigger list length things:
listLengthInitial();
});
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');
}
function loadAccountReport() {
"use strict";
$.get(accountReportUrl).done(placeAccountReport).fail(failAccountReport);