From: erickson Date: Fri, 23 Jan 2009 15:26:02 +0000 (+0000) Subject: Not sure why, but this version of FilteringTreeSelect uses the correct field when... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e5aae05dce269b918c67ddc3dfe1724a140bb89e;p=Evergreen.git Not sure why, but this version of FilteringTreeSelect uses the correct field when calculating the value of a stored item git-svn-id: svn://svn.open-ils.org/ILS/trunk@11926 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js index f71dc43a35..48424d085a 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js +++ b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js @@ -1,71 +1,72 @@ /* EXAMPLES: -
-
+ -The tree attribute is expected to be a tree-shaped pile of OpenSRF objects. +--- OR -- + +var tree = new openils.widget.FilteringTreeSelect(null, parentDiv); +tree.searchAttr = 'shortname'; +tree.labelAttr = 'shortname'; +tree.parentField = 'parent_ou'; +tree1.tree = fieldmapper.aou.globalOrgTree; +tree1.startup(); */ if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){ dojo.provide("openils.widget.FilteringTreeSelect"); dojo.require("dijit.form.FilteringSelect"); - dojo.require('dojo.data.ItemFileReadStore'); - dojo.require('openils.Util'); - dojo.require("dojox.jsonPath"); dojo.declare( - "openils.widget.FilteringTreeSelect", [dijit.form.ComboBox], - { + "openils.widget.FilteringTreeSelect", [dijit.form.FilteringSelect], { - defaultPad : 6, - childField : 'children', + defaultPad : 10, parentField : 'parent', - valueField : '', - tree : "", - options : [], - values : [], - - startup : function () { - this.labelAttr = '_label'; // force it - this.labelType = 'html'; // force it + labelAttr : 'name', + childField : 'children', + tree : null, - this._tree = (typeof this.tree == 'string') ? + startup : function() { + this.tree = (typeof this.tree == 'string') ? dojox.jsonPath.query(window, '$.' + this.tree, {evalType:"RESULT"}) : this.tree; - if (!dojo.isArray(this._tree)) this._tree = [ this._tree ]; - - this._datalist = []; - if (!this.valueField) this.valueField = this._tree[0].Identifier; - if (!this.searchAttr) this.searchAttr = this.valueField; - - var self = this; - this._tree.forEach( function (node) { self._add_items( node, 0 ); } ); - - this.store = new dojo.data.ItemFileReadStore({ - data : { - identifier : this.valueField, - label : this.labelAttr, - items : this._datalist - } - }); - + if(!this.tree) { + console.log("openils.widget.FilteringTreeSelect: Tree needed!"); + return; + } + var list = this._makeNodeList(this.tree); + this.store = new dojo.data.ItemFileReadStore( + {data:fieldmapper[list[0].classname].toStoreData(list)}); this.inherited(arguments); }, - _add_items : function ( node, depth ) { - var lpad = this.defaultPad * depth++; - - var data = node.toStoreItem(); - data._label = '
' + node[this.searchAttr]() + '
'; + // Compile the tree down to a dept-first list of nodes + _makeNodeList : function(node, list) { + if(!list) list = []; + list.push(node); + for(var i in node[this.childField]()) + this._makeNodeList(node[this.childField]()[i], list); + return list; + }, - this._datalist.push( data ); + // For each item, find the depth at display time by searching up the tree. + _getMenuLabelFromItem : function(item) { + var pad = -this.defaultPad; + var self = this; - var kids = node[this.childField](); - for (var j in kids) { - this._add_items( kids[j], depth ); + 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 null; + return { + html: true, + label: '
' + + this.store.getValue(item, this.labelAttr) + '
' + } } } );