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");
19 dojo.require("dojo.data.ItemFileWriteStore");
22 "openils.widget.FilteringTreeSelect", [dijit.form.FilteringSelect], {
25 parentField : 'parent',
27 childField : 'children',
31 construct : function(args) {
32 if (args && args.dijitArgs && args.dijitArgs.onChange) {
33 dojo.connect(this, 'onChange', args.dijitArgs.onChange);
37 startup : function() {
38 this.tree = (typeof this.tree == 'string') ?
39 dojox.jsonPath.query(window, '$.' + this.tree, {evalType:"RESULT"}) : this.tree;
41 console.log("openils.widget.FilteringTreeSelect: Tree needed!");
44 if(!dojo.isArray(this.tree)) this.tree = [this.tree];
45 this.className = this.tree[0].classname;
48 dojo.forEach(this.tree, function(node) { self._makeNodeList(node); });
49 if(this.dataList.length > 0) {
50 var storeData = fieldmapper[this.className].initStoreData();
51 storeData.items = this.dataList;
52 this.store = new dojo.data.ItemFileWriteStore({data:storeData});
54 this.inherited(arguments);
56 if(this.dataList.length > 0 && this.disableQuery)
60 _setDisabled : function() {
64 query : this.disableQuery,
65 onItem : function(item) { item._disabled = 'true'; }
68 // disallow selecting of disabled items
70 dojo.connect(this, 'onChange',
73 self.store.fetchItemByIdentity({
75 onItem : function(item) {
76 if(item._disabled == 'true')
77 self.attr('value', '');
84 // Compile the tree down to a depth-first list of dojo data items
85 _makeNodeList : function(node, depth) {
87 var storeItem = node.toStoreItem();
88 storeItem._depth = depth++;
89 this.dataList.push(storeItem);
91 for(var i in node[this.childField]())
92 this._makeNodeList(node[this.childField]()[i], depth);
95 // For each item, find the depth at display time by searching up the tree.
96 _getMenuLabelFromItem : function(item) {
98 var style = 'padding-left:'+ (item._depth * this.defaultPad) +'px;';
100 if(item._disabled == 'true') // TODO: external CSS
101 style += 'background-color:#CCC;cursor:wait';
105 label: '<div style="'+style+'">' + this.store.getValue(item, this.labelAttr) + '</div>'