A basic box for #786

This commit is contained in:
James Cole
2017-09-29 08:52:15 +02:00
parent aaac47ebfc
commit 76ed261441
8 changed files with 163 additions and 32 deletions

View File

@@ -10,6 +10,37 @@
/** global: spent, budgeted, available, currencySymbol, budgetIndexUri, updateIncomeUri, periodStart, periodEnd, budgetAmountUri, accounting */
/**
*
*/
$(function () {
"use strict";
$('.updateIncome').on('click', updateIncome);
$('.infoIncome').on('click', infoIncome);
/*
On start, fill the "spent"-bar using the content from the page.
*/
drawSpentBar();
drawBudgetedBar();
/*
When the input changes, update the percentages for the budgeted bar:
*/
$('input[type="number"]').on('input', updateBudgetedAmounts);
//
$('.selectPeriod').change(function (e) {
var sel = $(e.target).val();
if (sel !== "x") {
var newUri = budgetIndexUri.replace("REPLACE", sel);
window.location.assign(newUri);
}
});
});
function drawSpentBar() {
"use strict";
if ($('.spentBar').length > 0) {
@@ -55,6 +86,10 @@ function drawBudgetedBar() {
}
}
/**
*
* @param e
*/
function updateBudgetedAmounts(e) {
"use strict";
var target = $(e.target);
@@ -90,7 +125,7 @@ function updateBudgetedAmounts(e) {
// send a post to Firefly to update the amount:
var newUri = budgetAmountUri.replace("REPLACE", id);
$.post(newUri, {amount: value,start: periodStart, end: periodEnd}).done(function (data) {
$.post(newUri, {amount: value, start: periodStart, end: periodEnd}).done(function (data) {
// update the link if relevant:
if (data.repetition > 0) {
$('.budget-link[data-id="' + id + '"]').attr('href', 'budgets/show/' + id + '/' + data.repetition);
@@ -101,33 +136,10 @@ function updateBudgetedAmounts(e) {
}
}
$(function () {
"use strict";
$('.updateIncome').on('click', updateIncome);
/*
On start, fill the "spent"-bar using the content from the page.
*/
drawSpentBar();
drawBudgetedBar();
/*
When the input changes, update the percentages for the budgeted bar:
*/
$('input[type="number"]').on('input', updateBudgetedAmounts);
//
$('.selectPeriod').change(function (e) {
var sel = $(e.target).val();
if (sel !== "x") {
var newUri = budgetIndexUri.replace("REPLACE", sel);
window.location.assign(newUri);
}
});
});
/**
*
* @returns {boolean}
*/
function updateIncome() {
"use strict";
$('#defaultModal').empty().load(updateIncomeUri, function () {
@@ -136,3 +148,11 @@ function updateIncome() {
return false;
}
function infoIncome() {
$('#defaultModal').empty().load(infoIncomeUri, function () {
$('#defaultModal').modal('show');
});
return false;
}