mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-13 05:08:10 +00:00
Boxes will try to remember their state and auto-collapse.
This commit is contained in:
61
public/js/ff/boxes.js
Normal file
61
public/js/ff/boxes.js
Normal 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';
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user