Use localStorage rather than sessionStorage for storing user prefs

- Also create some helper functions
This commit is contained in:
Oliver Walters 2019-09-19 23:29:03 +10:00
parent cf2abb4130
commit 3c98cd87a7
3 changed files with 49 additions and 6 deletions

View File

@ -136,4 +136,47 @@ function imageHoverIcon(url) {
`;
return html;
}
function inventreeSave(name, value) {
/*
* Save a key:value pair to local storage
*/
var key = "inventree-" + name;
localStorage.setItem(key, value);
}
function inventreeLoad(name) {
/*
* Retrieve a key:value pair from local storage
*/
var key = "inventree-" + name;
return localStorage.getItem(key);
}
function inventreeLoadInt(name) {
/*
* Retrieve a value from local storage, and attempt to cast to integer
*/
var data = inventreeLoad(name);
return parseInt(data, 10);
}
function inventreeLoadFloat(name) {
var data = inventreeLoad(name);
return parseFloat(data);
}
function inventreeDel(name) {
var key = 'inventree-' + name;
localStorage.removeItem(key);
}

View File

@ -67,16 +67,16 @@
{% block js_ready %}
{{ block.super }}
if (sessionStorage.getItem("inventree-show-part-categories")) {
if (inventreeLoadInt("show-part-cats") == 1) {
$("#collapse-item-categories").collapse('show');
}
$("#collapse-item-categories").on('shown.bs.collapse', function() {
sessionStorage.setItem('inventree-show-part-categories', 1);
inventreeSave('show-part-cats', 1);
});
$("#collapse-item-categories").on('hidden.bs.collapse', function() {
sessionStorage.removeItem('inventree-show-part-categories');
inventreeDel('show-part-cats');
});
$("#cat-create").click(function() {

View File

@ -55,16 +55,16 @@
{% block js_ready %}
{{ block.super }}
if (sessionStorage.getItem("inventree-show-part-locations")) {
if (inventreeLoadInt("show-part-locs") == 1) {
$("#collapse-item-locations").collapse('show');
}
$("#collapse-item-locations").on('shown.bs.collapse', function() {
sessionStorage.setItem('inventree-show-part-locations', 1);
inventreeSave('show-part-locs', 1);
});
$("#collapse-item-locations").on('hidden.bs.collapse', function() {
sessionStorage.removeItem('inventree-show-part-locations');
inventreeDel('show-part-locs');
});
$("#stock-export").click(function() {