From ba97b6fd8725a8e46a6e9bb222977a3e1855f71a Mon Sep 17 00:00:00 2001 From: erickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Mon, 5 Oct 2009 16:11:54 +0000 Subject: [PATCH] make ndoe depth calculation more efficient and run at startup time to speed up display for large trees (e.g. org trees). throw exception when an org unit is retrieved that does not exist, since this cryptic error pops up from time to time during development git-svn-id: svn://svn.open-ils.org/ILS/trunk@14257 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js | 3 +++ .../js/dojo/openils/widget/FilteringTreeSelect.js | 31 +++++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js b/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js index c201fabb26..5b81cf30fd 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js +++ b/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js @@ -53,6 +53,9 @@ if(!dojo._hasResource["fieldmapper.OrgUtils"]){ return fieldmapper.aou.OrgCache[id].org; var o = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_unit.retrieve'],[null,id]); + if(!(o && o.id)) { + throw new Error("fieldmapper.aou.LoadOrg(): No org unit found with ID " + id); + } o.children = fieldmapper.aou.OrgCache[o.id()].children; fieldmapper.aou.OrgCache[o.id()] = { loaded : true, org : o }; return o; diff --git a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js index 7adc6510a4..ac5fe1af48 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js +++ b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js @@ -34,40 +34,33 @@ if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){ return; } if(!dojo.isArray(this.tree)) this.tree = [this.tree]; + this.className = this.tree[0].classname; this.dataList = []; var self = this; dojo.forEach(this.tree, function(node) { self._makeNodeList(node); }); if(this.dataList.length > 0) { - this.store = new dojo.data.ItemFileReadStore( - {data:fieldmapper[this.dataList[0].classname].toStoreData(this.dataList)}); + var storeData = fieldmapper[this.className].initStoreData(); + storeData.items = this.dataList; + this.store = new dojo.data.ItemFileReadStore({data:storeData}); } this.inherited(arguments); }, - // Compile the tree down to a depth-first list of nodes - _makeNodeList : function(node) { - this.dataList.push(node); + // Compile the tree down to a depth-first list of dojo data items + _makeNodeList : function(node, depth) { + if(!depth) depth = 0; + var storeItem = node.toStoreItem(); + storeItem._depth = depth++; + this.dataList.push(storeItem); for(var i in node[this.childField]()) - this._makeNodeList(node[this.childField]()[i]); + this._makeNodeList(node[this.childField]()[i], depth); }, // For each item, find the depth at display time by searching up the tree. _getMenuLabelFromItem : function(item) { - var pad = -this.defaultPad; - var self = this; - - function processItem(list) { - if(!list.length) return; - var pitem = list[0]; - pad += self.defaultPad; - var parentId = self.store.getValue(pitem, self.parentField); - self.store.fetch({onComplete:processItem, query:{id:''+parentId}}); - } - processItem([item]); - return { html: true, - label: '<div style="padding-left:'+pad+'px;">' + + label: '<div style="padding-left:'+ (item._depth * this.defaultPad) +'px;">' + this.store.getValue(item, this.labelAttr) + '</div>' } } -- 2.11.0