From b714eaac0643359b6cfd120c7ef31f6653de10cc Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 29 Apr 2016 09:47:47 +0200 Subject: [PATCH] Boxes will try to remember their state and auto-collapse. --- public/js/ff/boxes.js | 61 +++++++++++++++++++++++ public/js/ff/charts.js | 13 +++++ public/js/ff/firefly.js | 14 ------ resources/views/accounts/index.twig | 2 +- resources/views/layout/default.twig | 1 + resources/views/reports/default/year.twig | 48 ++++++------------ 6 files changed, 90 insertions(+), 49 deletions(-) create mode 100644 public/js/ff/boxes.js diff --git a/public/js/ff/boxes.js b/public/js/ff/boxes.js new file mode 100644 index 0000000000..ae787e7f5b --- /dev/null +++ b/public/js/ff/boxes.js @@ -0,0 +1,61 @@ +/* + * boxes.js + * Copyright (C) 2016 thegrumpydictator@gmail.com + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +$(function () { + "use strict"; + $('button[data-widget="collapse"]').click(storeBoxState); + + // restore boxes to their original state: + $.each($('.box'), function (i, v) { + var box = $(v); + if (box.attr('id')) { + var state = getBoxState(box.attr('id')); + console.log('Box ' + box.attr('id') + ' should be ' + state); + if(state == 'closed') { + $('button[data-widget="collapse"]', box).click(); + } + } + }); +}); + +function storeBoxState(e) { + "use strict"; + //Find the box parent + var button = $(e.target); + var box = button.parents(".box").first(); + var id = box.attr('id'); + if (id) { + console.log('Box has id: ' + id); + if (box.hasClass('collapsed-box')) { + setBoxState(id, 'open'); + console.log('Box "' + id + '" is now opening / open.'); + } else { + setBoxState(id, 'closed'); + console.log('Box "' + id + '" is now closing / closed.'); + } + } +} + +function setBoxState(id, state) { + "use strict"; + var index = 'ff-box-state-' + id; + if (typeof(Storage) !== "undefined") { + localStorage.setItem(index, state); + } +} +function getBoxState(id) { + "use strict"; + var index = 'ff-box-state-' + id; + if (typeof(Storage) !== "undefined") { + var state = localStorage.getItem(index); + if (state) { + return state; + } + } + return 'open'; +} \ No newline at end of file diff --git a/public/js/ff/charts.js b/public/js/ff/charts.js index 83fa029dda..e6b00274cd 100644 --- a/public/js/ff/charts.js +++ b/public/js/ff/charts.js @@ -285,6 +285,19 @@ function areaChart(URL, container, options) { function columnChart(URL, container, options) { "use strict"; + // find the parent box: + var cont = $('#' + container); + var box = cont.parents(".box").first(); + var boxId = box.attr('id'); + if (boxId) { + var state = getBoxState(boxId); + if (state == 'closed') { + console.log('Will not draw columnChart(' + URL + ') because ' + boxId + ' is closed.'); + return; + } + } + + options = options || {}; $.getJSON(URL).done(function (data) { diff --git a/public/js/ff/firefly.js b/public/js/ff/firefly.js index 3130714722..cedeaf41f3 100644 --- a/public/js/ff/firefly.js +++ b/public/js/ff/firefly.js @@ -96,19 +96,5 @@ function currencySelect(e) { return false; - - //var code = target.data('code'); - //var fieldType = target.data('field'); - //var menu = $('.' + fieldType + 'CurrencyDropdown'); - // - //var symbolHolder = $('#' + fieldType + 'CurrentSymbol'); - //symbolHolder.text(symbol); - //$('input[name="' + fieldType + '_currency_id"]').val(id); - // - // close dropdown (hack hack) - //menu.click(); - - - //return false; } diff --git a/resources/views/accounts/index.twig b/resources/views/accounts/index.twig index a1b0377c75..2310652b71 100644 --- a/resources/views/accounts/index.twig +++ b/resources/views/accounts/index.twig @@ -15,7 +15,7 @@
-
+

{{ subTitle }}

diff --git a/resources/views/layout/default.twig b/resources/views/layout/default.twig index 16ee742cef..eadf79b317 100644 --- a/resources/views/layout/default.twig +++ b/resources/views/layout/default.twig @@ -195,6 +195,7 @@ + {% block scripts %}{% endblock %} diff --git a/resources/views/reports/default/year.twig b/resources/views/reports/default/year.twig index f8d4040337..85f951869c 100644 --- a/resources/views/reports/default/year.twig +++ b/resources/views/reports/default/year.twig @@ -8,7 +8,7 @@
-
+

{{ 'incomeVsExpenses'|_ }}

@@ -18,7 +18,7 @@
-
+

{{ 'incomeVsExpenses'|_ }}

@@ -61,42 +61,17 @@
- - - - {% for category in categories %}
-
+

{{ 'category'|_ }} {{ category.name }}

+ + +
+ +
-
+

{{ 'budget'|_ }} {{ budget.name }}

+ + +
+ +