try and get ctrl-enter to add a clear all
[roojs1] / Roo / ViewPanel.js
index 0351802..7ca1e2e 100644 (file)
  * Fork - LGPL
  * <script type="text/javascript">
  */
+
 /**
- * @class Roo.grid.EditorGrid
- * @extends Roo.grid.Grid
- * Class for creating and editable grid.
- * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered - 
- * The container MUST have some type of size defined for the grid to fill. The container will be 
- * automatically set to position relative if it isn't already.
- * @param {Object} dataSource The data model to bind to
- * @param {Object} colModel The column model with info about this grid's columns
+ * @class Roo.GridPanel
+ * @extends Roo.ContentPanel
+ * @constructor
+ * Create a new GridPanel.
+ * @param {Roo.grid.Grid} grid The grid for this panel
+ * @param {String/Object} config A string to set only the panel's title, or a config object
  */
-Roo.ViewPanel = function(container, config){
-    Roo.ViewPanel.superclass.constructor.call(this, container, config);
-    this.getGridEl().addClass("xedit-grid");
-
-    if(!this.selModel){
-        this.selModel = new Roo.grid.CellSelectionModel();
+Roo.ViewPanel = function(el, config){
+     
+    this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
+        {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
+        
+    this.wrapper.dom.appendChild(el.dom);
+    
+    Roo.ViewPanel.superclass.constructor.call(this, this.wrapper, config);
+    
+    if(this.toolbar){
+        this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
     }
-
-    this.activeEditor = null;
-
-       this.addEvents({
-           /**
-            * @event beforeedit
-            * Fires before cell editing is triggered. The edit event object has the following properties <br />
-            * <ul style="padding:5px;padding-left:16px;">
-            * <li>grid - This grid</li>
-            * <li>record - The record being edited</li>
-            * <li>field - The field name being edited</li>
-            * <li>value - The value for the field being edited.</li>
-            * <li>row - The grid row index</li>
-            * <li>column - The grid column index</li>
-            * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
-            * </ul>
-            * @param {Object} e An edit event (see above for description)
-            */
-           "beforeedit" : true,
-           /**
-            * @event afteredit
-            * Fires after a cell is edited. <br />
-            * <ul style="padding:5px;padding-left:16px;">
-            * <li>grid - This grid</li>
-            * <li>record - The record being edited</li>
-            * <li>field - The field name being edited</li>
-            * <li>value - The value being set</li>
-            * <li>originalValue - The original value for the field, before the edit.</li>
-            * <li>row - The grid row index</li>
-            * <li>column - The grid column index</li>
-            * </ul>
-            * @param {Object} e An edit event (see above for description)
-            */
-           "afteredit" : true,
-           /**
-            * @event validateedit
-            * Fires after a cell is edited, but before the value is set in the record. 
-         * You can use this to modify the value being set in the field, Return false
-            * to cancel the change. The edit event object has the following properties <br />
-            * <ul style="padding:5px;padding-left:16px;">
-         * <li>editor - This editor</li>
-            * <li>grid - This grid</li>
-            * <li>record - The record being edited</li>
-            * <li>field - The field name being edited</li>
-            * <li>value - The value being set</li>
-            * <li>originalValue - The original value for the field, before the edit.</li>
-            * <li>row - The grid row index</li>
-            * <li>column - The grid column index</li>
-            * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
-            * </ul>
-            * @param {Object} e An edit event (see above for description)
-            */
-           "validateedit" : true
-       });
-    this.on("bodyscroll", this.stopEditing,  this);
-    this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick,  this);
+    // xtype created footer. - not sure if will work as we normally have to render first..
+    if (this.footer && !this.footer.el && this.footer.xtype) {
+        
+        this.footer.container = this.wrapper.el; // this.getView().getFooterPanel(true);
+        this.footer.dataSource = this.view.store;
+        this.footer = Roo.factory(this.footer, Roo);
+        
+    }
+    //??? create teh view???
+    
+    //grid.monitorWindowResize = false; // turn off autosizing
+    //grid.autoHeight = false;
+    //grid.autoWidth = false;
+    //this.grid = grid;
+    //this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
 };
 
-Roo.extend(Roo.ViewPanel, Roo.grid.Grid, {
+Roo.extend(Roo.ViewPanel, Roo.ContentPanel, {
+    
+    autoCreate : true,
+    getId : function(){
+        return this.view.id;
+    },
+    
     /**
-     * @cfg {Number} clicksToEdit
-     * The number of clicks on a cell required to display the cell's editor (defaults to 2)
+     * Returns the grid for this panel
+     * @return {Roo.grid.Grid} 
      */
-    clicksToEdit: 2,
-
-    // private
-    isEditor : true,
-    // private
-    trackMouseOver: false, // causes very odd FF errors
-
-    onCellDblClick : function(g, row, col){
-        this.startEditing(row, col);
+    getGrid : function(){
+        return this.view;    
     },
-
-    onEditComplete : function(ed, value, startValue){
-        this.editing = false;
-        this.activeEditor = null;
-        ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
-        var r = ed.record;
-        var field = this.colModel.getDataIndex(ed.col);
-        var e = {
-            grid: this,
-            record: r,
-            field: field,
-            originalValue: startValue,
-            value: value,
-            row: ed.row,
-            column: ed.col,
-            cancel:false,
-            editor: ed
-        };
-        var cell = Roo.get(this.view.getCell(ed.row,ed.col))
-        cell.show();
-          
-        if(String(value) !== String(startValue)){
-            
-            if(this.fireEvent("validateedit", e) !== false && !e.cancel){
-                r.set(field, e.value);
-                // if we are dealing with a combo box..
-                // then we also set the 'name' colum to be the displayField
-                if (ed.field.displayField && ed.field.name) {
-                    r.set(ed.field.name, ed.field.el.dom.value);
-                }
-                
-                delete e.cancel; //?? why!!!
-                this.fireEvent("afteredit", e);
-            }
-        } else {
-            this.fireEvent("afteredit", e); // always fire it!
+    
+    setSize : function(width, height){
+        if(!this.ignoreResize(width, height)){
+            var grid = this.grid;
+            var size = this.adjustForComponents(width, height);
+            grid.getGridEl().setSize(size.width, size.height);
+            grid.autoSize();
         }
-        this.view.focusCell(ed.row, ed.col);
     },
-
-    /**
-     * Starts editing the specified for the specified row/column
-     * @param {Number} rowIndex
-     * @param {Number} colIndex
-     */
-    startEditing : function(row, col){
-        this.stopEditing();
-        if(this.colModel.isCellEditable(col, row)){
-            this.view.ensureVisible(row, col, true);
-          
-            var r = this.dataSource.getAt(row);
-            var field = this.colModel.getDataIndex(col);
-            var cell = Roo.get(this.view.getCell(row,col));
-            var e = {
-                grid: this,
-                record: r,
-                field: field,
-                value: r.data[field],
-                row: row,
-                column: col,
-                cancel:false 
-            };
-            if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
-                this.editing = true;
-                var ed = this.colModel.getCellEditor(col, row);
-                
-                if (!ed) {
-                    return;
-                }
-                if(!ed.rendered){
-                    ed.render(ed.parentEl || document.body);
-                }
-                ed.field.reset();
-               
-                cell.hide();
-                
-                (function(){ // complex but required for focus issues in safari, ie and opera
-                    ed.row = row;
-                    ed.col = col;
-                    ed.record = r;
-                    ed.on("complete",   this.onEditComplete,        this,       {single: true});
-                    ed.on("specialkey", this.selModel.onEditorKey,  this.selModel);
-                    this.activeEditor = ed;
-                    var v = r.data[field];
-                    ed.startEdit(this.view.getCell(row, col), v);
-                    // combo's with 'displayField and name set
-                    if (ed.field.displayField && ed.field.name) {
-                        ed.field.el.dom.value = r.data[ed.field.name];
-                    }
-                    
-                    
-                }).defer(50, this);
-            }
-        }
+    
+    beforeSlide : function(){
+        this.grid.getView().scroller.clip();
     },
-        
-    /**
-     * Stops any active editing
-     */
-    stopEditing : function(){
-        if(this.activeEditor){
-            this.activeEditor.completeEdit();
-        }
-        this.activeEditor = null;
+    
+    afterSlide : function(){
+        this.grid.getView().scroller.unclip();
     },
-       
-        /**
-     * Called to get grid's drag proxy text, by default returns this.ddText.
-     * @return {String}
-     */
-    getDragDropText : function(){
-        var count = this.selModel.getSelectedCell() ? 1 : 0;
-        return String.format(this.ddText, count, count == 1 ? '' : 's');
+    
+    destroy : function(){
+        this.grid.destroy();
+        delete this.grid;
+        Roo.GridPanel.superclass.destroy.call(this); 
     }
-       
 });
\ No newline at end of file