[open-ils-commits] r14259 - in branches/rel_1_6_0/Open-ILS/web/js/dojo: fieldmapper openils/widget (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Oct 5 12:12:25 EDT 2009


Author: erickson
Date: 2009-10-05 12:12:22 -0400 (Mon, 05 Oct 2009)
New Revision: 14259

Modified:
   branches/rel_1_6_0/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js
   branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
Log:
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

Modified: branches/rel_1_6_0/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js
===================================================================
--- branches/rel_1_6_0/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js	2009-10-05 16:12:14 UTC (rev 14258)
+++ branches/rel_1_6_0/Open-ILS/web/js/dojo/fieldmapper/OrgUtils.js	2009-10-05 16:12:22 UTC (rev 14259)
@@ -53,6 +53,9 @@
 			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;

Modified: branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
===================================================================
--- branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js	2009-10-05 16:12:14 UTC (rev 14258)
+++ branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js	2009-10-05 16:12:22 UTC (rev 14259)
@@ -34,40 +34,33 @@
                     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>'
                 }
             }



More information about the open-ils-commits mailing list