Boxes will try to remember their state and auto-collapse.

This commit is contained in:
James Cole 2016-04-29 09:47:47 +02:00
parent 14b94a5bd2
commit b714eaac06
6 changed files with 90 additions and 49 deletions

61
public/js/ff/boxes.js Normal file
View File

@ -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';
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -15,7 +15,7 @@
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box" id="account-index-{{ what }}">
<div class="box-header with-border">
<h3 class="box-title">{{ subTitle }}</h3>

View File

@ -195,6 +195,7 @@
</script>
<script type="text/javascript" src="js/ff/firefly.js"></script>
<script type="text/javascript" src="js/ff/boxes.js"></script>
<script type="text/javascript" src="js/ff/help.js"></script>
{% block scripts %}{% endblock %}

View File

@ -8,7 +8,7 @@
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-12">
<div class="box">
<div class="box" id="year-inc-exp">
<div class="box-header with-border">
<h3 class="box-title">{{ 'incomeVsExpenses'|_ }}</h3>
</div>
@ -18,7 +18,7 @@
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="box">
<div class="box" id="year-inc-exp-sum">
<div class="box-header with-border">
<h3 class="box-title">{{ 'incomeVsExpenses'|_ }}</h3>
</div>
@ -61,42 +61,17 @@
</div>
</div>
<!--
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'categories_spent_in_year'|_ }}</h3>
</div>
<div class="box-body">
<canvas height="400" id="categories-spent-in-period" style="width:100%;height:400px;"></canvas>
</div>
</div>
</div>
</div>
-->
<!--
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'categories_earned_in_year'|_ }}</h3>
</div>
<div class="box-body">
<canvas height="400" id="categories-earned-in-period" style="width:100%;height:400px;"></canvas>
</div>
</div>
</div>
</div>
-->
{% for category in categories %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box" id="year-cat-{{ category.id }}">
<div class="box-header with-border">
<h3 class="box-title">{{ 'category'|_ }} {{ category.name }}</h3>
<!-- ACTIONS MENU -->
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div>
<div class="box-body">
<canvas height="400" id="categories_{{ category.id }}" class="category_year_chart" data-category="{{ category.id }}"
@ -110,9 +85,14 @@
{% for budget in budgets %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box" id="year-budget-{{ budget.id }}">
<div class="box-header with-border">
<h3 class="box-title">{{ 'budget'|_ }} {{ budget.name }}</h3>
<!-- ACTIONS MENU -->
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div>
<div class="box-body">
<canvas height="400" id="budgets_{{ budget.id }}" class="budget_year_chart" data-budget="{{ budget.id }}"