created new grid column picker that uses new dojo 1.2 capabilities for built-in colum...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 26 Dec 2008 18:49:17 +0000 (18:49 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 26 Dec 2008 18:49:17 +0000 (18:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11681 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 628fffb..947601f 100644 (file)
@@ -19,6 +19,7 @@ dojo.require('openils.Event');
 dojo.require('fieldmapper.Fieldmapper');
 
 if(!dojo._hasResource["openils.GridColumnPicker"]) {
+    console.log("DEPRECATED! Use openils.widget.GridColumnPicker instead.");
     dojo._hasResource["openils.GridColumnPicker"] = true;
     dojo.provide('openils.GridColumnPicker');
     dojo.declare('openils.GridColumnPicker', null, {
diff --git a/Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js b/Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js
new file mode 100644 (file)
index 0000000..e0866c0
--- /dev/null
@@ -0,0 +1,88 @@
+/* ---------------------------------------------------------------------------
+ * Copyright (C) 2008  Georgia Public Library Service
+ * Bill Erickson <erickson@esilibrary.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * ---------------------------------------------------------------------------
+ */
+
+
+/**
+ * Create a new menu that can be used as a grid column picker.  This version
+ * takes advantage of Dojo's 1.2 headerMenu attribute for selecting which
+ * columns to display.  As columns are chosen, they are updated on the server
+ * with user settings.
+ */
+
+if(!dojo._hasResource['openils.widget.GridColumnPicker']) {
+    dojo.provide('openils.widget.GridColumnPicker');
+    dojo.require('dijit.Menu');
+    dojo.require('fieldmapper.Fieldmapper');
+    dojo.require('openils.Util');
+
+    dojo.declare(
+        'openils.widget.GridColumnPicker',
+        [dijit.Menu],
+        {
+
+            USER_PERSIST_SETTING : 'ui.grid_columns',
+
+            init : function(grid, persistPrefix, authtoken) {
+
+                this.grid = grid;
+                this.persistPrefix = persistPrefix
+                this.authtoken = authtoken;
+                this.cells = this.grid.structure[0].cells[0];
+                var self = this;
+
+                dojo.forEach(this.getChildren(),
+                    function(child) {
+                        for(var i in self.cells) {
+                            var name = self.cells[i].name;
+                            if(name == child.attr('label')) {
+                                child.field = {label:name, ident:self.cells[i].field};
+                                break;
+                            }   
+                        }
+                    }
+                );
+            },
+
+            onClose : function() {
+                this.inherited('onClose',arguments);
+                this.persist();
+            },
+
+            persist : function() {
+                var selected = [];
+                var autoFields = [];
+                dojo.forEach(this.getChildren(),
+                    function(child) {
+                        if(child.checked) {
+                            selected.push(child.field.ident)
+                        }
+                    }
+                );
+                var setting = {};
+                setting[this.USER_PERSIST_SETTING+'.'+this.persistPrefix] = {'columns':selected, 'auto':autoFields};
+                fieldmapper.standardRequest(
+                    ['open-ils.actor', 'open-ils.actor.patron.settings.update'],
+                    {   async: true,
+                        params: [this.authtoken, null, setting],
+                        oncomplete: function(r) {
+                            openils.Util.readResponse(r);
+                        }
+                    }
+                );
+            } 
+        }
+    );
+}