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',
30 startup : function() {
31 this.tree = (typeof this.tree == 'string') ?
32 dojox.jsonPath.query(window, '$.' + this.tree, {evalType:"RESULT"}) : this.tree;
34 console.log("openils.widget.FilteringTreeSelect: Tree needed!");
37 if(!dojo.isArray(this.tree)) this.tree = [this.tree];
38 this.className = this.tree[0].classname;
41 dojo.forEach(this.tree, function(node) { self._makeNodeList(node); });
42 if(this.dataList.length > 0) {
43 var storeData = fieldmapper[this.className].initStoreData();
44 storeData.items = this.dataList;
45 this.store = new dojo.data.ItemFileReadStore({data:storeData});
47 this.inherited(arguments);
49 if(this.dataList.length > 0 && this.disableQuery)
53 _setDisabled : function() {
57 query : this.disableQuery,
58 onItem : function(item) { item._disabled = 'true'; }
61 // disallow selecting of disabled items
63 dojo.connect(this, 'onChange',
66 self.store.fetchItemByIdentity({
68 onItem : function(item) {
69 if(item._disabled == 'true')
70 self.attr('value', '');
77 // Compile the tree down to a depth-first list of dojo data items
78 _makeNodeList : function(node, depth) {
80 var storeItem = node.toStoreItem();
81 storeItem._depth = depth++;
82 this.dataList.push(storeItem);
84 for(var i in node[this.childField]())
85 this._makeNodeList(node[this.childField]()[i], depth);
88 // For each item, find the depth at display time by searching up the tree.
89 _getMenuLabelFromItem : function(item) {
91 var style = 'padding-left:'+ (item._depth * this.defaultPad) +'px;';
93 if(item._disabled == 'true') // TODO: external CSS
94 style += 'background-color:#CCC;cursor:wait';
98 label: '<div style="'+style+'">' + this.store.getValue(item, this.labelAttr) + '</div>'