remove debugging code
[roojs1] / Roo / grid / CellSelectionModel.js
index 679b9d2..95364f8 100644 (file)
@@ -48,7 +48,22 @@ Roo.grid.CellSelectionModel = function(config){
                <li>o.cell: An array of [rowIndex, columnIndex]</li>
                </ul>
             */
-           "selectionchange" : true
+           "selectionchange" : true,
+        /**
+            * @event tabend
+            * Fires when the tab (or enter) was pressed on the last editable cell
+            * You can use this to trigger add new row.
+            * @param {SelectionModel} this
+            */
+           "tabend" : true,
+         /**
+            * @event beforeeditnext
+            * Fires before the next editable sell is made active
+            * You can use this to skip to another cell or fire the tabend
+            *    if you set cell to false
+            * @param {Object} eventdata object : { cell : [ row, col ] } 
+            */
+           "beforeeditnext" : true
     });
     Roo.grid.CellSelectionModel.superclass.constructor.call(this);
 };
@@ -182,11 +197,9 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
             return g.walkCells(row, col, step, sm.isSelectable,  sm);
         };
         var k = e.getKey(), r = s.cell[0], c = s.cell[1];
-        var newCell, forward=false;
+        var newCell;
 
-        if (this.enter_is_tab && k == e.ENTER) {
-            k = e.TAB;
-        }
+      
 
         switch(k){
             case e.TAB:
@@ -198,13 +211,11 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
                     newCell = walk(r, c-1, -1);
                 } else {
                     newCell = walk(r, c+1, 1);
-                    forward = true;
                 }
                 break;
             
             case e.DOWN:
                newCell = walk(r+1, c, 1);
-                forward = true;
                 break;
             
             case e.UP:
@@ -213,7 +224,6 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
             
             case e.RIGHT:
                 newCell = walk(r, c+1, 1);
-                forward = true;
                 break;
             
             case e.LEFT:
@@ -235,10 +245,6 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
             this.select(newCell[0], newCell[1]);
             e.stopEvent();
             
-        } else if (forward) {
-            // tabbed past last
-            this.fireEvent('tabend');
-            
         }
     },
 
@@ -257,34 +263,50 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
      */
     onEditorKey : function(field, e){
         
-        var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
+        var k = e.getKey(),
+            newCell,
+            g = this.grid,
+            ed = g.activeEditor,
+            forward = false;
         ///Roo.log('onEditorKey' + k);
-        if (!ed) {
-            
-            
-            
+        
+        
+        if (this.enter_is_tab && k == e.ENTER) {
+            k = e.TAB;
         }
+        
         if(k == e.TAB){
             if(e.shiftKey){
                 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
             }else{
                 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
+                forward = true;
             }
             
             e.stopEvent();
             
-        }else if(k == e.ENTER &&  !e.ctrlKey){
+        } else if(k == e.ENTER &&  !e.ctrlKey){
             ed.completeEdit();
             e.stopEvent();
             newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
-        }else if(k == e.ESC){
+        
+               } else if(k == e.ESC){
             ed.cancelEdit();
         }
-        
-        
+               
+        if (newCell) {
+            var ecall = { cell : newCell, forward : forward };
+            this.fireEvent('beforeeditnext', ecall );
+            newCell = ecall.cell;
+                       forward = ecall.forward;
+        }
+               
         if(newCell){
             //Roo.log('next cell after edit');
             g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
+        } else if (forward) {
+            // tabbed past last
+            this.fireEvent.defer(100, this, ['tabend',this]);
         }
     }
 });
\ No newline at end of file