implemented select/deselect all. removed some debugging. disable sort when clicking...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 2 Apr 2009 21:25:45 +0000 (21:25 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 2 Apr 2009 21:25:45 +0000 (21:25 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12768 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/AutoGrid.js

index 24c413b..e2f1d63 100644 (file)
@@ -25,6 +25,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
 
             startup : function() {
                 this.selectionMode = 'single';
+                this.sequence = openils.widget.AutoGrid.sequence++;
+                openils.widget.AutoGrid.gridCache[this.sequence] = this;
                 this.inherited(arguments);
                 this.initAutoEnv();
                 this.setStructure(this._compileStructure());
@@ -35,8 +37,19 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                     this._applyEditOnEnter();
                 else if(this.singleEditStyle) 
                     this._applySingleEditStyle();
-                this.sequence = openils.widget.AutoGrid.sequence++;
-                openils.widget.AutoGrid.gridCache[this.sequence] = this;
+
+                if(!this.hideSelector) {
+                    var header = this.layout.cells[0].view.getHeaderCellNode(0);
+                    var self = this;
+                    header.onclick = function() { self.toggleSelectAll(); }
+                }
+            },
+
+            /* Don't allow sorting on the selector column */
+            canSort : function(rowIdx) {
+                if(rowIdx == 1 && !this.hideSelector)
+                    return false;
+                return true;
             },
 
             _compileStructure : function() {
@@ -63,10 +76,11 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                         field : '+selector',
                         get : function(rowIdx, item) { return self._buildRowSelectInput(rowIdx, item); },
                         width : this.selectorWidth,
-                        name : '&#x2713;'
+                        name : '&#x2713'
                     });
                 }
 
+
                 if(!this.fieldOrder) {
                     /* no order defined, start with any explicit grid fields */
                     for(var e in existing) {
@@ -108,8 +122,19 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                 return [{cells: [fields]}];
             },
 
+            toggleSelectAll : function() {
+                var selected = this.getSelectedRows();
+                for(var i = 0; i < this.rowCount; i++) {
+                    if(selected[0])
+                        this.deSelectRow(i);
+                    else
+                        this.selectRow(i);
+                }
+            },
+
             getSelectedRows : function() {
-                var rows = []; dojo.forEach(
+                var rows = []; 
+                dojo.forEach(
                     dojo.query('[name=autogrid.selector]', this.domNode),
                     function(input) {
                         if(input.checked)
@@ -193,10 +218,6 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
 
                 dojo.connect(this, 'onKeyDown',
                     function(e) {
-                        if(dojo.keys.UP_ARROW) {
-                            console.log("up arrow");
-                            console.log(this.getSelectedRows() + ' : ' + this.focus.rowIndex);
-                        }
                         if(e.keyCode == dojo.keys.ENTER) {
                             this.selection.deselectAll();
                             this.selection.select(this.focus.rowIndex);