mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Use localStorage rather than sessionStorage for storing user prefs
- Also create some helper functions
This commit is contained in:
parent
cf2abb4130
commit
3c98cd87a7
@ -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);
|
||||
}
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user