Merge pull request #266 from SchrodingersGat/side-bar-improvements

Side bar improvements
This commit is contained in:
Oliver 2019-05-09 00:43:57 +10:00 committed by GitHub
commit b41ff3c42a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -22,6 +22,10 @@ from rest_framework import views
class TreeSerializer(views.APIView):
""" JSON View for serializing a Tree object.
Turns a 'tree' model into a JSON object compatible with bootstrap-treview.
Ref: https://github.com/jonmiles/bootstrap-treeview
"""
def itemToJson(self, item):

View File

@ -14,6 +14,11 @@
color: #ffcc00;
}
/* CSS overrides for treeview */
.expand-icon {
font-size: 11px;
}
/* Force select2 elements in modal forms to be full width */
.select-full-width {
width: 100%;

View File

@ -11,6 +11,29 @@ function loadTree(url, tree, data) {
data: response.tree,
enableLinks: true
});
var saved_exp = sessionStorage.getItem('inventree-sidenav-expanded-items').split(",");
// Automatically expand the desired notes
for (var q = 0; q < saved_exp.length; q++) {
$(tree).treeview('expandNode', parseInt(saved_exp[q]));
}
// Setup a callback whenever a node is toggled
$(tree).on('nodeExpanded nodeCollapsed', function(event, data) {
// Record the entire list of expanded items
var expanded = $(tree).treeview('getExpanded');
var exp = [];
for (var i = 0; i < expanded.length; i++) {
exp.push(expanded[i].nodeId);
}
// Save the expanded nodes
sessionStorage.setItem('inventree-sidenav-expanded-items', exp);
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
@ -24,6 +47,8 @@ function openSideNav() {
document.getElementById("inventree-content").style.marginLeft = "270px";
sessionStorage.setItem('inventree-sidenav-state', 'open');
}
function closeSideNav() {