adding an indented group selector. some of this may be abstracted out to a generic...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 25 Nov 2008 04:51:19 +0000 (04:51 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 25 Nov 2008 04:51:19 +0000 (04:51 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11327 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/PermGrpFilteringSelect.js [new file with mode: 0644]

diff --git a/Open-ILS/web/js/dojo/openils/widget/PermGrpFilteringSelect.js b/Open-ILS/web/js/dojo/openils/widget/PermGrpFilteringSelect.js
new file mode 100644 (file)
index 0000000..00e4229
--- /dev/null
@@ -0,0 +1,73 @@
+if(!dojo._hasResource["openils.widget.PermGrpFilteringSelect"]){
+    dojo._hasResource["openils.widget.PermGrpFilteringSelect"] = true;
+    dojo.provide("openils.widget.PermGrpFilteringSelect");
+    dojo.require("dijit.form.FilteringSelect");
+    dojo.require('dojo.data.ItemFileReadStore');
+    dojo.require('openils.Util');
+
+    dojo.declare(
+        "openils.widget.PermGrpFilteringSelect", [dijit.form.FilteringSelect], 
+        {
+            fetchGroups : function(onload) {
+
+                if(this.groupTree) 
+                    return onload();
+                var self = this;
+
+                fieldmapper.standardRequest(
+                    ['open-ils.actor', 'open-ils.actor.groups.tree.retrieve'],
+                    {   async: true,
+                        oncomplete: function(r) {
+                            self.groupTree = openils.Util.readResponse(r);
+                            onload();
+                        }
+                    }
+                );
+            },
+
+            flatten : function(node) {
+                if(!node) {
+                    node = this.groupTree;
+                    this.groupMap = {};
+                }
+                this.groupMap[node.id()] = node;
+                for(var idx in node.children())
+                    this.flatten(node.children()[idx]);
+            },
+            
+            drawGroups : function() {
+                var self = this;
+                this.fetchGroups(function(){self._drawGroups()});
+            },
+
+            _drawGroups : function(node, depth, list) {
+                if(!node) { 
+                    node = this.groupTree; 
+                    list = []; 
+                    depth = 0; 
+                }
+
+                lpad = 6 * depth;
+                var data = pgt.toStoreData([node]).items[0];
+                data._label = '<div style="padding-left:'+lpad+'px;">' + node.name() + '</div>';
+                list.push(data);
+
+                for(var idx in node.children()) 
+                    this._drawGroups(node.children()[idx], depth + 1, list);
+
+                if(depth == 0) {
+                    var construct = {data : {identifier : 'id', items: list}};
+                    this.store = new dojo.data.ItemFileReadStore(construct);
+                    this.startup();
+                }
+            },
+
+            _getMenuLabelFromItem : function(item) {
+                return {
+                    html: true,
+                    label: item._label
+                };
+            }
+        }
+    );
+}