make ndoe depth calculation more efficient and run at startup time to speed up displa...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Oct 2009 16:12:22 +0000 (16:12 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Oct 2009 16:12:22 +0000 (16:12 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_0@14259 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js
Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js

index c201fab..5b81cf3 100644 (file)
@@ -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;
index 7adc651..ac5fe1a 100644 (file)
@@ -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>'
                 }
             }