[open-ils-commits] r11735 - trunk/Open-ILS/web/js/dojo/openils/widget
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jan 2 16:34:49 EST 2009
Author: miker
Date: 2009-01-02 16:34:45 -0500 (Fri, 02 Jan 2009)
New Revision: 11735
Added:
trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
Log:
(untested) generic filtering, tree-indenting combobox
Added: trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js (rev 0)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js 2009-01-02 21:34:45 UTC (rev 11735)
@@ -0,0 +1,67 @@
+/* EXAMPLES:
+
+<div dojoType="openils.widget.FilteringTreeSelect" tree="orgTree" parentField="parent_ou" nameField="shortname"/>
+<div dojoType="openils.widget.FilteringTreeSelect" tree="grpTree"/>
+
+The tree attribute is expected to be a tree-shaped pile of OpenSRF objects.
+
+*/
+
+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],
+ {
+
+ defaultPad : 6,
+ childField : 'children',
+ parentField : 'parent',
+ nameField : 'name',
+ valueField : '',
+ tree : "",
+ options : [],
+ values : [],
+
+ startup : function () {
+ this._tree = dojox.jsonPath.query(window, '$.' + this.tree, {evalType:"RESULT"});
+ this._datalist = [];
+ if (!this.valueField) this.valueField = this._tree.Identifier;
+
+ this._add_items( this._tree, 0 );
+
+ var construct = {data : {identifier : this.valueField, items: this.datalist}};
+ this.store = new dojo.data.ItemFileReadStore(construct);
+
+ this.inherited(arguments);
+ },
+
+ _add_items : function ( node, depth ) {
+ var lpad = this.defaultPad * depth++;
+
+ var data = node.toStoreData();
+ data._label = '<div style="padding-left:'+lpad+'px;">' + node[this.nameField]() + '</div>';
+
+ this._datalist.push( data );
+
+ var kids = node[this.childField]();
+ for (var j in kids) {
+ this._add_items( kids[j], depth );
+ }
+
+ return null;
+ },
+
+ _getMenuLabelFromItem : function(item) {
+ return {
+ html: true,
+ label: item._label
+ };
+ }
+ }
+ );
+}
More information about the open-ils-commits
mailing list