grid column picker cleanup
authorBill Erickson <berick@esilibrary.com>
Wed, 28 Mar 2012 15:25:02 +0000 (11:25 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 28 Mar 2012 15:25:02 +0000 (11:25 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js

index 34ea285..0b4c2b1 100644 (file)
@@ -32,6 +32,7 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
         USER_PERSIST_SETTING : 'ui.grid_columns',
 
         constructor : function (authtoken, persistKey, grid, structure) {
+            var _this = this;
             this.grid = grid;
             this.persistKey = this.USER_PERSIST_SETTING+'.'+persistKey;
             this.authtoken = authtoken || openils.User.authtoken;
@@ -41,10 +42,15 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
             this.dialog = this.buildDialog();
             this.dialogTable = this.dialog.containerNode.getElementsByTagName('tbody')[0];
 
-            // replace me
-            this.onSortChange = function(list) {console.log('onSortChange : ' + list)}
+            // replace: called after any sort changes
+            this.onSortChange = function(list) {console.log('onSortChange()')}
+            // replace:  called after user settings are first retrieved
+            this.onLoad = function(opts) {console.log('onLoad()')};
+
+            // internal onload handler
+            this.loaded = false;
+            this._onLoad = function(opts) {_this.loaded = true; _this.onLoad(opts)};
 
-            var _this = this;
             this.grid.onHeaderContextMenu = function(e) { 
                 _this.build();
                 _this.dialog.show(); 
@@ -187,7 +193,7 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
                 // this must be added after its parent node is inserted into the DOM.
                 var ns = new dijit.form.NumberSpinner(
                     {   constraints : {min : 0, places : 0}, 
-                        value : 0,
+                        value : cell._sort,
                         style : 'width:4em',
                         name : 'sort'
                     }, ipt3
@@ -333,9 +339,6 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
             this.structure[0].cells[0] = displayCells;
             this.grid.setStructure(this.structure);
             this.grid.update();
-
-            if (this.setting.sort && this.setting.sort.length > 0 && this.onSortChange)
-                this.onSortChange(this.buildSortList());
         },
 
         load : function() {
@@ -347,13 +350,16 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
                 var _this = this;
                 openils.Util.addOnLoad(function() {
                     _this.authtoken = openils.User.authtoken;
-                    _this.load()
+                    _this.load();
                 }); 
                 return;
             }
 
-            if(this.setting)
-                return this.loadColsFromSetting(this.setting);
+            if(this.setting) {
+                this.loadColsFromSetting(this.setting);
+                this._onLoad({sortFields : this.buildSortList()});
+                return;
+            }
 
             fieldmapper.standardRequest(
                 ['open-ils.actor', 'open-ils.actor.patron.settings.retrieve'],
@@ -367,6 +373,7 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
                             _this.grid.setStructure(_this.structure);
                             _this.grid.update();
                         }
+                        _this._onLoad({sortFields : _this.buildSortList()});
                     }
                 }
             );