author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/YUI-extensions/grid/EditorSelectionModel.js | 182 |
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 | */ | ||
8 | YAHOO.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 | |||
16 | YAHOO.extendX(YAHOO.ext.grid.EditorSelectionModel, YAHOO.ext.grid.DefaultSelectionModel); | ||
17 | |||
18 | YAHOO.ext.grid.EditorSelectionModel.prototype.disableArrowNavigation = false; | ||
19 | YAHOO.ext.grid.EditorSelectionModel.prototype.controlForArrowNavigation = false; | ||
20 | |||
21 | /** @ignore */ | ||
22 | YAHOO.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 | |||
28 | YAHOO.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 | |||
38 | YAHOO.ext.grid.EditorSelectionModel.prototype.activate = function(row, cell){ | ||
39 | this.fireEvent('cellactivate', this, row, cell); | ||
40 | this.grid.doEdit(row, cell); | ||
41 | }; | ||
42 | |||
43 | YAHOO.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 */ | ||
54 | YAHOO.ext.grid.EditorSelectionModel.prototype.setRowState = function(row, selected){ | ||
55 | YAHOO.ext.grid.EditorSelectionModel.superclass.setRowState.call(this, row, false, false); | ||
56 | }; | ||
57 | /** @ignore */ | ||
58 | YAHOO.ext.grid.EditorSelectionModel.prototype.focusRow = function(row, selected){ | ||
59 | }; | ||
60 | |||
61 | YAHOO.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 | |||
79 | YAHOO.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 | |||
97 | YAHOO.ext.grid.EditorSelectionModel.prototype.allowArrowNav = function(e){ | ||
98 | return (!this.disableArrowNavigation && (!this.controlForArrowNavigation || e.ctrlKey)); | ||
99 | } | ||
100 | /** @ignore */ | ||
101 | YAHOO.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 | */ | ||
163 | YAHOO.ext.grid.EditorAndSelectionModel = function(){ | ||
164 | YAHOO.ext.grid.EditorAndSelectionModel.superclass.constructor.call(this); | ||
165 | this.events['cellactivate'] = new YAHOO.util.CustomEvent('cellactivate'); | ||
166 | }; | ||
167 | |||
168 | YAHOO.extendX(YAHOO.ext.grid.EditorAndSelectionModel, YAHOO.ext.grid.DefaultSelectionModel); | ||
169 | |||
170 | YAHOO.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 | |||
175 | YAHOO.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 | }; | ||