Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / widgets / grid / RowSelectionModel.js
diff --git a/source/widgets/grid/RowSelectionModel.js b/source/widgets/grid/RowSelectionModel.js
deleted file mode 100644 (file)
index 3a0c80b..0000000
+++ /dev/null
@@ -1,487 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- @class Ext.grid.RowSelectionModel\r
- * @extends Ext.grid.AbstractSelectionModel\r
- * The default SelectionModel used by {@link Ext.grid.GridPanel}.\r
- * It supports multiple selections and keyboard selection/navigation. The objects stored\r
- * as selections and returned by {@link #getSelected}, and {@link #getSelections} are\r
- * the {@link Ext.data.Record Record}s which provide the data for the selected rows.\r
- * @constructor\r
- * @param {Object} config\r
- */\r
-Ext.grid.RowSelectionModel = function(config){\r
-    Ext.apply(this, config);\r
-    this.selections = new Ext.util.MixedCollection(false, function(o){\r
-        return o.id;\r
-    });\r
-\r
-    this.last = false;\r
-    this.lastActive = false;\r
-\r
-    this.addEvents(\r
-        /**\r
-            * @event selectionchange\r
-            * Fires when the selection changes\r
-            * @param {SelectionModel} this\r
-            */\r
-           "selectionchange",\r
-        /**\r
-            * @event beforerowselect\r
-            * Fires when a row is being selected, return false to cancel.\r
-            * @param {SelectionModel} this\r
-            * @param {Number} rowIndex The index to be selected\r
-            * @param {Boolean} keepExisting False if other selections will be cleared\r
-            * @param {Record} record The record to be selected\r
-            */\r
-           "beforerowselect",\r
-        /**\r
-            * @event rowselect\r
-            * Fires when a row is selected.\r
-            * @param {SelectionModel} this\r
-            * @param {Number} rowIndex The selected index\r
-            * @param {Ext.data.Record} r The selected record\r
-            */\r
-           "rowselect",\r
-        /**\r
-            * @event rowdeselect\r
-            * Fires when a row is deselected.\r
-            * @param {SelectionModel} this\r
-            * @param {Number} rowIndex\r
-            * @param {Record} record\r
-            */\r
-           "rowdeselect"\r
-    );\r
-\r
-    Ext.grid.RowSelectionModel.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.grid.RowSelectionModel, Ext.grid.AbstractSelectionModel,  {\r
-    /**\r
-     * @cfg {Boolean} singleSelect\r
-     * True to allow selection of only one row at a time (defaults to false)\r
-     */\r
-    singleSelect : false,\r
-\r
-       /**\r
-        * @cfg {Boolean} moveEditorOnEnter\r
-        * False to turn off moving the editor to the next cell when the enter key is pressed\r
-        */\r
-    // private\r
-    initEvents : function(){\r
-\r
-        if(!this.grid.enableDragDrop && !this.grid.enableDrag){\r
-            this.grid.on("rowmousedown", this.handleMouseDown, this);\r
-        }else{ // allow click to work like normal\r
-            this.grid.on("rowclick", function(grid, rowIndex, e) {\r
-                if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {\r
-                    this.selectRow(rowIndex, false);\r
-                    grid.view.focusRow(rowIndex);\r
-                }\r
-            }, this);\r
-        }\r
-\r
-        this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {\r
-            "up" : function(e){\r
-                if(!e.shiftKey || this.singleSelect){\r
-                    this.selectPrevious(false);\r
-                }else if(this.last !== false && this.lastActive !== false){\r
-                    var last = this.last;\r
-                    this.selectRange(this.last,  this.lastActive-1);\r
-                    this.grid.getView().focusRow(this.lastActive);\r
-                    if(last !== false){\r
-                        this.last = last;\r
-                    }\r
-                }else{\r
-                    this.selectFirstRow();\r
-                }\r
-            },\r
-            "down" : function(e){\r
-                if(!e.shiftKey || this.singleSelect){\r
-                    this.selectNext(false);\r
-                }else if(this.last !== false && this.lastActive !== false){\r
-                    var last = this.last;\r
-                    this.selectRange(this.last,  this.lastActive+1);\r
-                    this.grid.getView().focusRow(this.lastActive);\r
-                    if(last !== false){\r
-                        this.last = last;\r
-                    }\r
-                }else{\r
-                    this.selectFirstRow();\r
-                }\r
-            },\r
-            scope: this\r
-        });\r
-\r
-        var view = this.grid.view;\r
-        view.on("refresh", this.onRefresh, this);\r
-        view.on("rowupdated", this.onRowUpdated, this);\r
-        view.on("rowremoved", this.onRemove, this);\r
-    },\r
-\r
-    // private\r
-    onRefresh : function(){\r
-        var ds = this.grid.store, index;\r
-        var s = this.getSelections();\r
-        this.clearSelections(true);\r
-        for(var i = 0, len = s.length; i < len; i++){\r
-            var r = s[i];\r
-            if((index = ds.indexOfId(r.id)) != -1){\r
-                this.selectRow(index, true);\r
-            }\r
-        }\r
-        if(s.length != this.selections.getCount()){\r
-            this.fireEvent("selectionchange", this);\r
-        }\r
-    },\r
-\r
-    // private\r
-    onRemove : function(v, index, r){\r
-        if(this.selections.remove(r) !== false){\r
-            this.fireEvent('selectionchange', this);\r
-        }\r
-    },\r
-\r
-    // private\r
-    onRowUpdated : function(v, index, r){\r
-        if(this.isSelected(r)){\r
-            v.onRowSelect(index);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Select records.\r
-     * @param {Array} records The records to select\r
-     * @param {Boolean} keepExisting (optional) True to keep existing selections\r
-     */\r
-    selectRecords : function(records, keepExisting){\r
-        if(!keepExisting){\r
-            this.clearSelections();\r
-        }\r
-        var ds = this.grid.store;\r
-        for(var i = 0, len = records.length; i < len; i++){\r
-            this.selectRow(ds.indexOf(records[i]), true);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Gets the number of selected rows.\r
-     * @return {Number}\r
-     */\r
-    getCount : function(){\r
-        return this.selections.length;\r
-    },\r
-\r
-    /**\r
-     * Selects the first row in the grid.\r
-     */\r
-    selectFirstRow : function(){\r
-        this.selectRow(0);\r
-    },\r
-\r
-    /**\r
-     * Select the last row.\r
-     * @param {Boolean} keepExisting (optional) True to keep existing selections\r
-     */\r
-    selectLastRow : function(keepExisting){\r
-        this.selectRow(this.grid.store.getCount() - 1, keepExisting);\r
-    },\r
-\r
-    /**\r
-     * Selects the row immediately following the last selected row.\r
-     * @param {Boolean} keepExisting (optional) True to keep existing selections\r
-     * @return {Boolean} True if there is a next row, else false\r
-     */\r
-    selectNext : function(keepExisting){\r
-        if(this.hasNext()){\r
-            this.selectRow(this.last+1, keepExisting);\r
-            this.grid.getView().focusRow(this.last);\r
-                       return true;\r
-        }\r
-               return false;\r
-    },\r
-\r
-    /**\r
-     * Selects the row that precedes the last selected row.\r
-     * @param {Boolean} keepExisting (optional) True to keep existing selections\r
-     * @return {Boolean} True if there is a previous row, else false\r
-     */\r
-    selectPrevious : function(keepExisting){\r
-        if(this.hasPrevious()){\r
-            this.selectRow(this.last-1, keepExisting);\r
-            this.grid.getView().focusRow(this.last);\r
-                       return true;\r
-        }\r
-               return false;\r
-    },\r
-\r
-    /**\r
-     * Returns true if there is a next record to select\r
-     * @return {Boolean}\r
-     */\r
-    hasNext : function(){\r
-        return this.last !== false && (this.last+1) < this.grid.store.getCount();\r
-    },\r
-\r
-    /**\r
-     * Returns true if there is a previous record to select\r
-     * @return {Boolean}\r
-     */\r
-    hasPrevious : function(){\r
-        return !!this.last;\r
-    },\r
-\r
-\r
-    /**\r
-     * Returns the selected records\r
-     * @return {Array} Array of selected records\r
-     */\r
-    getSelections : function(){\r
-        return [].concat(this.selections.items);\r
-    },\r
-\r
-    /**\r
-     * Returns the first selected record.\r
-     * @return {Record}\r
-     */\r
-    getSelected : function(){\r
-        return this.selections.itemAt(0);\r
-    },\r
-\r
-    /**\r
-     * Calls the passed function with each selection. If the function returns false, iteration is\r
-     * stopped and this function returns false. Otherwise it returns true.\r
-     * @param {Function} fn\r
-     * @param {Object} scope (optional)\r
-     * @return {Boolean} true if all selections were iterated\r
-     */\r
-    each : function(fn, scope){\r
-        var s = this.getSelections();\r
-        for(var i = 0, len = s.length; i < len; i++){\r
-            if(fn.call(scope || this, s[i], i) === false){\r
-                return false;\r
-            }\r
-        }\r
-        return true;\r
-    },\r
-\r
-    /**\r
-     * Clears all selections.\r
-     */\r
-    clearSelections : function(fast){\r
-        if(this.isLocked()) return;\r
-        if(fast !== true){\r
-            var ds = this.grid.store;\r
-            var s = this.selections;\r
-            s.each(function(r){\r
-                this.deselectRow(ds.indexOfId(r.id));\r
-            }, this);\r
-            s.clear();\r
-        }else{\r
-            this.selections.clear();\r
-        }\r
-        this.last = false;\r
-    },\r
-\r
-\r
-    /**\r
-     * Selects all rows.\r
-     */\r
-    selectAll : function(){\r
-        if(this.isLocked()) return;\r
-        this.selections.clear();\r
-        for(var i = 0, len = this.grid.store.getCount(); i < len; i++){\r
-            this.selectRow(i, true);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Returns True if there is a selection.\r
-     * @return {Boolean}\r
-     */\r
-    hasSelection : function(){\r
-        return this.selections.length > 0;\r
-    },\r
-\r
-    /**\r
-     * Returns True if the specified row is selected.\r
-     * @param {Number/Record} record The record or index of the record to check\r
-     * @return {Boolean}\r
-     */\r
-    isSelected : function(index){\r
-        var r = typeof index == "number" ? this.grid.store.getAt(index) : index;\r
-        return (r && this.selections.key(r.id) ? true : false);\r
-    },\r
-\r
-    /**\r
-     * Returns True if the specified record id is selected.\r
-     * @param {String} id The id of record to check\r
-     * @return {Boolean}\r
-     */\r
-    isIdSelected : function(id){\r
-        return (this.selections.key(id) ? true : false);\r
-    },\r
-\r
-    // private\r
-    handleMouseDown : function(g, rowIndex, e){\r
-        if(e.button !== 0 || this.isLocked()){\r
-            return;\r
-        };\r
-        var view = this.grid.getView();\r
-        if(e.shiftKey && !this.singleSelect && this.last !== false){\r
-            var last = this.last;\r
-            this.selectRange(last, rowIndex, e.ctrlKey);\r
-            this.last = last; // reset the last\r
-            view.focusRow(rowIndex);\r
-        }else{\r
-            var isSelected = this.isSelected(rowIndex);\r
-            if(e.ctrlKey && isSelected){\r
-                this.deselectRow(rowIndex);\r
-            }else if(!isSelected || this.getCount() > 1){\r
-                this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);\r
-                view.focusRow(rowIndex);\r
-            }\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Selects multiple rows.\r
-     * @param {Array} rows Array of the indexes of the row to select\r
-     * @param {Boolean} keepExisting (optional) True to keep existing selections (defaults to false)\r
-     */\r
-    selectRows : function(rows, keepExisting){\r
-        if(!keepExisting){\r
-            this.clearSelections();\r
-        }\r
-        for(var i = 0, len = rows.length; i < len; i++){\r
-            this.selectRow(rows[i], true);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Selects a range of rows. All rows in between startRow and endRow are also selected.\r
-     * @param {Number} startRow The index of the first row in the range\r
-     * @param {Number} endRow The index of the last row in the range\r
-     * @param {Boolean} keepExisting (optional) True to retain existing selections\r
-     */\r
-    selectRange : function(startRow, endRow, keepExisting){\r
-        if(this.isLocked()) return;\r
-        if(!keepExisting){\r
-            this.clearSelections();\r
-        }\r
-        if(startRow <= endRow){\r
-            for(var i = startRow; i <= endRow; i++){\r
-                this.selectRow(i, true);\r
-            }\r
-        }else{\r
-            for(var i = startRow; i >= endRow; i--){\r
-                this.selectRow(i, true);\r
-            }\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Deselects a range of rows. All rows in between startRow and endRow are also deselected.\r
-     * @param {Number} startRow The index of the first row in the range\r
-     * @param {Number} endRow The index of the last row in the range\r
-     */\r
-    deselectRange : function(startRow, endRow, preventViewNotify){\r
-        if(this.isLocked()) return;\r
-        for(var i = startRow; i <= endRow; i++){\r
-            this.deselectRow(i, preventViewNotify);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Selects a row.\r
-     * @param {Number} row The index of the row to select\r
-     * @param {Boolean} keepExisting (optional) True to keep existing selections\r
-     */\r
-    selectRow : function(index, keepExisting, preventViewNotify){\r
-        if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || this.isSelected(index)) return;\r
-        var r = this.grid.store.getAt(index);\r
-        if(r && this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){\r
-            if(!keepExisting || this.singleSelect){\r
-                this.clearSelections();\r
-            }\r
-            this.selections.add(r);\r
-            this.last = this.lastActive = index;\r
-            if(!preventViewNotify){\r
-                this.grid.getView().onRowSelect(index);\r
-            }\r
-            this.fireEvent("rowselect", this, index, r);\r
-            this.fireEvent("selectionchange", this);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Deselects a row.\r
-     * @param {Number} row The index of the row to deselect\r
-     */\r
-    deselectRow : function(index, preventViewNotify){\r
-        if(this.isLocked()) return;\r
-        if(this.last == index){\r
-            this.last = false;\r
-        }\r
-        if(this.lastActive == index){\r
-            this.lastActive = false;\r
-        }\r
-        var r = this.grid.store.getAt(index);\r
-        if(r){\r
-            this.selections.remove(r);\r
-            if(!preventViewNotify){\r
-                this.grid.getView().onRowDeselect(index);\r
-            }\r
-            this.fireEvent("rowdeselect", this, index, r);\r
-            this.fireEvent("selectionchange", this);\r
-        }\r
-    },\r
-\r
-    // private\r
-    restoreLast : function(){\r
-        if(this._last){\r
-            this.last = this._last;\r
-        }\r
-    },\r
-\r
-    // private\r
-    acceptsNav : function(row, col, cm){\r
-        return !cm.isHidden(col) && cm.isCellEditable(col, row);\r
-    },\r
-\r
-    // private\r
-    onEditorKey : function(field, e){\r
-        var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;\r
-        var shift = e.shiftKey;\r
-        if(k == e.TAB){\r
-            e.stopEvent();\r
-            ed.completeEdit();\r
-            if(shift){\r
-                newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);\r
-            }else{\r
-                newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);\r
-            }\r
-        }else if(k == e.ENTER){\r
-            e.stopEvent();\r
-            ed.completeEdit();\r
-                       if(this.moveEditorOnEnter !== false){\r
-                               if(shift){\r
-                                       newCell = g.walkCells(ed.row - 1, ed.col, -1, this.acceptsNav, this);\r
-                               }else{\r
-                                       newCell = g.walkCells(ed.row + 1, ed.col, 1, this.acceptsNav, this);\r
-                               }\r
-                       }\r
-        }else if(k == e.ESC){\r
-            ed.cancelEdit();\r
-        }\r
-        if(newCell){\r
-            g.startEditing(newCell[0], newCell[1]);\r
-        }\r
-    }\r
-});
\ No newline at end of file