3 <input jsId='ftree' dojoType="openils.widget.FilteringTreeSelect" searchAttr='shortname' labelAttr='shortname' tree='myTree'/>
7 var tree = new openils.widget.FilteringTreeSelect(null, parentDiv);
8 tree.searchAttr = 'shortname';
9 tree.labelAttr = 'shortname';
10 tree.parentField = 'parent_ou';
11 tree1.tree = fieldmapper.aou.globalOrgTree;
16 if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){
17 dojo.provide("openils.widget.FilteringTreeSelect");
18 dojo.require("dijit.form.FilteringSelect");
21 "openils.widget.FilteringTreeSelect", [dijit.form.FilteringSelect], {
24 parentField : 'parent',
26 childField : 'children',
29 startup : function() {
30 this.tree = (typeof this.tree == 'string') ?
31 dojox.jsonPath.query(window, '$.' + this.tree, {evalType:"RESULT"}) : this.tree;
33 console.log("openils.widget.FilteringTreeSelect: Tree needed!");
36 if(!dojo.isArray(this.tree)) this.tree = [this.tree];
39 dojo.forEach(this.tree, function(node) { self._makeNodeList(node); });
40 this.store = new dojo.data.ItemFileReadStore(
41 {data:fieldmapper[this.dataList[0].classname].toStoreData(this.dataList)});
42 this.inherited(arguments);
45 // Compile the tree down to a depth-first list of nodes
46 _makeNodeList : function(node) {
47 this.dataList.push(node);
48 for(var i in node[this.childField]())
49 this._makeNodeList(node[this.childField]()[i]);
52 // For each item, find the depth at display time by searching up the tree.
53 _getMenuLabelFromItem : function(item) {
54 var pad = -this.defaultPad;
57 function processItem(list) {
58 if(!list.length) return;
60 pad += self.defaultPad;
61 var parentId = self.store.getValue(pitem, self.parentField);
62 self.store.fetch({onComplete:processItem, query:{id:''+parentId}});
68 label: '<div style="padding-left:'+pad+'px;">' +
69 this.store.getValue(item, this.labelAttr) + '</div>'