[open-ils-commits] r10763 - in trunk/Open-ILS/web: js/dojo/openils vandelay vandelay/inc

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Oct 6 11:11:40 EDT 2008


Author: erickson
Date: 2008-10-06 11:11:38 -0400 (Mon, 06 Oct 2008)
New Revision: 10763

Modified:
   trunk/Open-ILS/web/js/dojo/openils/GridColumnPicker.js
   trunk/Open-ILS/web/vandelay/inc/queue.xml
   trunk/Open-ILS/web/vandelay/vandelay.js
Log:
implemented column persistence via user setting.  only update grid layout when necessary to keep column widths accross pages

Modified: trunk/Open-ILS/web/js/dojo/openils/GridColumnPicker.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/GridColumnPicker.js	2008-10-06 13:47:59 UTC (rev 10762)
+++ trunk/Open-ILS/web/js/dojo/openils/GridColumnPicker.js	2008-10-06 15:11:38 UTC (rev 10763)
@@ -14,19 +14,29 @@
  * ---------------------------------------------------------------------------
  */
 
+dojo.require('openils.User');
+dojo.require('openils.Event');
+dojo.require('fieldmapper.Fieldmapper');
+
 if(!dojo._hasResource["openils.GridColumnPicker"]) {
     dojo._hasResource["openils.GridColumnPicker"] = true;
     dojo.provide('openils.GridColumnPicker');
     dojo.declare('openils.GridColumnPicker', null, {
 
-        constructor : function (dialog, grid) {
+        USER_PERSIST_SETTING : 'ui.grid_columns',
+
+        constructor : function (dialog, grid, structure, authtoken, persistId) {
             this.dialog = dialog;
             this.grid = grid;
-            this.structure = grid.structure;
+            this.structure = structure;
             this.dialogTable = dialog.domNode.getElementsByTagName('tbody')[0];
             this.baseCellList = this.structure[0].cells[0].slice();
             this.build();
             this.grid.model.fields.get(0).sort = false;
+            this.authtoken = authtoken;
+            this.savedColums = null;
+            this.persistId = persistId;
+            this.setting = null;
         },
 
         // builds the column-picker dialog table
@@ -47,6 +57,7 @@
 
             for(var i = 0; i < cells.length; i++) {
                 // setting table.innerHTML breaks stuff, so do it the hard way
+                var cell = cells[i];
                 tr = document.createElement('tr');
                 tr.setAttribute('picker', 'picker');
                 td1 = document.createElement('td');
@@ -56,15 +67,25 @@
                 ipt = document.createElement('input');
                 ipt.setAttribute('type', 'checkbox');
                 ipt.setAttribute('checked', 'checked');
-                ipt.setAttribute('ident', cells[i].field+''+cells[i].name);
+                ipt.setAttribute('ident', cell.field+''+cell.name);
                 ipt.setAttribute('name', 'selector');
 
                 ipt2 = document.createElement('input');
                 ipt2.setAttribute('type', 'checkbox');
-                ipt2.setAttribute('ident', cells[i].field+''+cells[i].name);
+                ipt2.setAttribute('ident', cell.field+''+cell.name);
                 ipt2.setAttribute('name', 'width');
 
-                td1.appendChild(document.createTextNode(cells[i].name));
+                if(this.setting) {
+                    // set the UI based on the loaded settings
+                    if(this._arrayHas(this.setting.columns, cell.field)) {
+                        if(this._arrayHas(this.setting.auto, cell.field))
+                            ipt2.setAttribute('checked', 'checked');
+                    } else {
+                        ipt.removeAttribute('checked');
+                    }
+                }
+
+                td1.appendChild(document.createTextNode(cell.name));
                 td2.appendChild(ipt);
                 td3.appendChild(ipt2);
                 tr.appendChild(td1);
@@ -78,7 +99,7 @@
         },
 
         // update the grid based on the items selected in the picker dialog
-        update : function() {
+        update : function(persist) {
             var newCellList = [];
             var rows = dojo.query('[picker=picker]', this.dialogTable);
 
@@ -104,6 +125,8 @@
             this.structure[0].cells[0] = newCellList;
             this.grid.setStructure(this.structure);
             this.grid.update();
+
+            if(persist) this.persist();
         },
 
         _selectableCellList : function() {
@@ -119,7 +142,79 @@
 
         // save me as a user setting
         persist : function() {
-        }
+            var cells = this.structure[0].cells[0];
+            var list = [];
+            var autos = [];
+            for(var i = 0; i < cells.length; i++) {
+                var cell = cells[i];
+                if(cell.selectableColumn) {
+                    list.push(cell.field);
+                    if(cell.width == 'auto')
+                        autos.push(cell.field);
+                }
+            }
+            var setting = {};
+            setting[this.USER_PERSIST_SETTING+'.'+this.persistId] = {'columns':list, 'auto':autos};
+            fieldmapper.standardRequest(
+                ['open-ils.actor', 'open-ils.actor.patron.settings.update'],
+                {   async: true,
+                    params: [this.authtoken, null, setting],
+                    oncomplete: function(r) {
+                        var stat = r.recv().content();
+                        if(e = openils.Event.parse(stat))
+                            return alert(e);
+                    }
+                }
+            );
+        }, 
+
+        _arrayHas : function(arr, val) {
+            for(var i = 0; arr && i < arr.length; i++) {
+                if(arr[i] == val)
+                    return true;
+            }
+            return false;
+        },
+
+        _loadColsFromSetting : function(setting) {
+            this.setting = setting;
+            var newCellList = [];
+            for(var j = 0; j < this.baseCellList.length; j++) {
+                var cell = this.baseCellList[j];
+                if(cell.selectableColumn) {
+                    if(this._arrayHas(setting.columns, cell.field)) {
+                        newCellList.push(cell);
+                        if(this._arrayHas(setting.auto, cell.field))
+                            cell.width = 'auto';
+                        else delete cell.width;
+                    }
+                }  else { // if it's not selectable, always show it
+                    newCellList.push(cell); 
+                }
+            }
+
+            this.build();
+            this.structure[0].cells[0] = newCellList;
+            this.grid.setStructure(this.structure);
+            this.grid.update();
+        },
+
+        load : function() {
+            var picker = this;
+            fieldmapper.standardRequest(
+                ['open-ils.actor', 'open-ils.actor.patron.settings.retrieve'],
+                {   async: true,
+                    params: [this.authtoken, null, this.USER_PERSIST_SETTING+'.'+this.persistId],
+                    oncomplete: function(r) {
+                        var set = r.recv().content();
+                        if(e = openils.Event.parse(set))
+                            return alert(e)
+                        if(set) 
+                            picker._loadColsFromSetting(set);
+                    }
+                }
+            );
+        },
     });
 }
 

Modified: trunk/Open-ILS/web/vandelay/inc/queue.xml
===================================================================
--- trunk/Open-ILS/web/vandelay/inc/queue.xml	2008-10-06 13:47:59 UTC (rev 10762)
+++ trunk/Open-ILS/web/vandelay/inc/queue.xml	2008-10-06 15:11:38 UTC (rev 10763)
@@ -27,13 +27,17 @@
     <div dojoType="dijit.Dialog" jsId='vlQueueGridColumePickerDialog' title="Column Picker" execute="alert(2);">
         <table class='form_table'>
             <thead>
-                <tr><th width='33%'>&vandelay.column;</th><th width='33%'>&vandelay.display;</th><th width='33%'>&vandelay.auto.width;</th></tr>
+                <tr><th width='33%'>&vandelay.column;</th>
+                <th width='33%'>&vandelay.display;</th>
+                <th width='33%'>&vandelay.auto.width;</th></tr>
             </thead>
             <tbody>
                 <tr>
                     <td colspan='3' align='center'>
                         <button jsId='vlQueueGridColumnPickerButton' 
-                            onclick='vlQueueGridColumePickerDialog.hide();vlQueueGridColumePicker.update();' 
+                            onclick='
+                                vlQueueGridColumePickerDialog.hide();
+                                vlQueueGridColumePicker.update(true);'
                             dojoType='dijit.form.Button'>&vandelay.done;</button>
                     </td>
                 </tr>

Modified: trunk/Open-ILS/web/vandelay/vandelay.js
===================================================================
--- trunk/Open-ILS/web/vandelay/vandelay.js	2008-10-06 13:47:59 UTC (rev 10762)
+++ trunk/Open-ILS/web/vandelay/vandelay.js	2008-10-06 15:11:38 UTC (rev 10763)
@@ -565,17 +565,15 @@
     var store = new dojo.data.ItemFileReadStore({data:storeData});
     var model = new dojox.grid.data.DojoData(
         null, store, {rowsPerPage: 100, clientSort: true, query:{id:'*'}});
-
     vlQueueGrid.setModel(model);
-    if(vlQueueGridColumePicker) 
-        vlQueueGrid.setStructure(vlQueueGridColumePicker.structure);
-    else
-        vlQueueGrid.setStructure(vlQueueGridLayout);
-    vlQueueGrid.update();
 
-    if(!vlQueueGridColumePicker) {
+    if(vlQueueGridColumePicker) {
+        vlQueueGrid.update();
+    } else {
         vlQueueGridColumePicker = 
-            new openils.GridColumnPicker(vlQueueGridColumePickerDialog, vlQueueGrid);
+            new openils.GridColumnPicker(vlQueueGridColumePickerDialog, 
+                vlQueueGrid, vlQueueGridLayout, authtoken, 'vandelay.queue');
+        vlQueueGridColumePicker.load();
     }
 }
 



More information about the open-ils-commits mailing list