summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js
Unidiff
Diffstat (limited to 'frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js182
1 files changed, 182 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js b/frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js
new file mode 100644
index 0000000..c1cb240
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js
@@ -0,0 +1,182 @@
1
2/**
3 @class YAHOO.ext.grid.EditorSelectionModel
4 * Extends {@link YAHOO.ext.grid.DefaultSelectionModel} to enable cell navigation. <br><br>
5 @extends YAHOO.ext.grid.DefaultSelectionModel
6 @constructor
7 */
8YAHOO.ext.grid.EditorSelectionModel = function(){
9 YAHOO.ext.grid.EditorSelectionModel.superclass.constructor.call(this);
10 /** Number of clicks to activate a cell (for editing) - valid values are 1 or 2
11 * @type Number */
12 this.clicksToActivateCell = 1;
13 this.events['cellactivate'] = new YAHOO.util.CustomEvent('cellactivate');
14};
15
16YAHOO.extendX(YAHOO.ext.grid.EditorSelectionModel, YAHOO.ext.grid.DefaultSelectionModel);
17
18YAHOO.ext.grid.EditorSelectionModel.prototype.disableArrowNavigation = false;
19YAHOO.ext.grid.EditorSelectionModel.prototype.controlForArrowNavigation = false;
20
21/** @ignore */
22YAHOO.ext.grid.EditorSelectionModel.prototype.initEvents = function(){
23 this.grid.addListener("cellclick", this.onCellClick, this, true);
24 this.grid.addListener("celldblclick", this.onCellDblClick, this, true);
25 this.grid.addListener("keydown", this.keyDown, this, true);
26};
27
28YAHOO.ext.grid.EditorSelectionModel.prototype.onCellClick = function(grid, rowIndex, colIndex){
29 if(this.clicksToActivateCell == 1){
30 var row = this.grid.getRow(rowIndex);
31 var cell = row.childNodes[colIndex];
32 if(cell){
33 this.activate(row, cell);
34 }
35 }
36};
37
38YAHOO.ext.grid.EditorSelectionModel.prototype.activate = function(row, cell){
39 this.fireEvent('cellactivate', this, row, cell);
40 this.grid.doEdit(row, cell);
41};
42
43YAHOO.ext.grid.EditorSelectionModel.prototype.onCellDblClick = function(grid, rowIndex, colIndex){
44 if(this.clicksToActivateCell == 2){
45 var row = this.grid.getRow(rowIndex);
46 var cell = row.childNodes[colIndex];
47 if(cell){
48 this.activate(row, cell);
49 }
50 }
51};
52
53/** @ignore */
54YAHOO.ext.grid.EditorSelectionModel.prototype.setRowState = function(row, selected){
55 YAHOO.ext.grid.EditorSelectionModel.superclass.setRowState.call(this, row, false, false);
56};
57/** @ignore */
58YAHOO.ext.grid.EditorSelectionModel.prototype.focusRow = function(row, selected){
59};
60
61YAHOO.ext.grid.EditorSelectionModel.prototype.getEditorCellAfter = function(cell, spanRows){
62 var g = this.grid;
63 var next = g.getCellAfter(cell);
64 while(next && !g.colModel.isCellEditable(next.columnIndex)){
65 next = g.getCellAfter(next);
66 }
67 if(!next && spanRows){
68 var row = g.getRowAfter(g.getRowFromChild(cell));
69 if(row){
70 next = g.getFirstCell(row);
71 if(!g.colModel.isCellEditable(next.columnIndex)){
72 next = this.getEditorCellAfter(next);
73 }
74 }
75 }
76 return next;
77};
78
79YAHOO.ext.grid.EditorSelectionModel.prototype.getEditorCellBefore = function(cell, spanRows){
80 var g = this.grid;
81 var prev = g.getCellBefore(cell);
82 while(prev && !g.colModel.isCellEditable(prev.columnIndex)){
83 prev = g.getCellBefore(prev);
84 }
85 if(!prev && spanRows){
86 var row = g.getRowBefore(g.getRowFromChild(cell));
87 if(row){
88 prev = g.getLastCell(row);
89 if(!g.colModel.isCellEditable(prev.columnIndex)){
90 prev = this.getEditorCellBefore(prev);
91 }
92 }
93 }
94 return prev;
95};
96
97YAHOO.ext.grid.EditorSelectionModel.prototype.allowArrowNav = function(e){
98 return (!this.disableArrowNavigation && (!this.controlForArrowNavigation || e.ctrlKey));
99}
100/** @ignore */
101YAHOO.ext.grid.EditorSelectionModel.prototype.keyDown = function(e){
102 var g = this.grid, cm = g.colModel, cell = g.getEditingCell();
103 if(!cell) return;
104 var newCell;
105 switch(e.browserEvent.keyCode){
106 case e.TAB:
107 if(e.shiftKey){
108 newCell = this.getEditorCellBefore(cell, true);
109 }else{
110 newCell = this.getEditorCellAfter(cell, true);
111 }
112 e.preventDefault();
113 break;
114 case e.DOWN:
115 if(this.allowArrowNav(e)){
116 var next = g.getRowAfter(g.getRowFromChild(cell));
117 if(next){
118 newCell = next.childNodes[cell.columnIndex];
119 }
120 }
121 break;
122 case e.UP:
123 if(this.allowArrowNav(e)){
124 var prev = g.getRowBefore(g.getRowFromChild(cell));
125 if(prev){
126 newCell = prev.childNodes[cell.columnIndex];
127 }
128 }
129 break;
130 case e.RETURN:
131 if(e.shiftKey){
132 var prev = g.getRowBefore(g.getRowFromChild(cell));
133 if(prev){
134 newCell = prev.childNodes[cell.columnIndex];
135 }
136 }else{
137 var next = g.getRowAfter(g.getRowFromChild(cell));
138 if(next){
139 newCell = next.childNodes[cell.columnIndex];
140 }
141 }
142 break;
143 case e.RIGHT:
144 if(this.allowArrowNav(e)){
145 newCell = this.getEditorCellAfter(cell);
146 }
147 break;
148 case e.LEFT:
149 if(this.allowArrowNav(e)){
150 newCell = this.getEditorCellBefore(cell);
151 }
152 break;
153 };
154 if(newCell){
155 this.activate(g.getRowFromChild(newCell), newCell);
156 e.stopEvent();
157 }
158};
159
160/**
161 * @class YAHOO.ext.grid.EditorAndSelectionModel
162 */
163YAHOO.ext.grid.EditorAndSelectionModel = function(){
164 YAHOO.ext.grid.EditorAndSelectionModel.superclass.constructor.call(this);
165 this.events['cellactivate'] = new YAHOO.util.CustomEvent('cellactivate');
166};
167
168YAHOO.extendX(YAHOO.ext.grid.EditorAndSelectionModel, YAHOO.ext.grid.DefaultSelectionModel);
169
170YAHOO.ext.grid.EditorAndSelectionModel.prototype.initEvents = function(){
171 YAHOO.ext.grid.EditorAndSelectionModel.superclass.initEvents.call(this);
172 this.grid.addListener("celldblclick", this.onCellDblClick, this, true);
173};
174
175YAHOO.ext.grid.EditorAndSelectionModel.prototype.onCellDblClick = function(grid, rowIndex, colIndex){
176 var row = this.grid.getRow(rowIndex);
177 var cell = row.childNodes[colIndex];
178 if(cell){
179 this.fireEvent('cellactivate', this, row, cell);
180 this.grid.doEdit(row, cell);
181 }
182};