Diffstat (limited to 'frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js new file mode 100644 index 0000000..7c51a48 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js | |||
@@ -0,0 +1,91 @@ | |||
1 | /** | ||
2 | * @class YAHOO.ext.grid.CellEditor | ||
3 | * Base class for all EditorGrid editors | ||
4 | */ | ||
5 | YAHOO.ext.grid.CellEditor = function(element){ | ||
6 | this.colIndex = null; | ||
7 | this.rowIndex = null; | ||
8 | this.grid = null; | ||
9 | this.editing = false; | ||
10 | this.originalValue = null; | ||
11 | this.element = getEl(element, true); | ||
12 | this.element.addClass('ygrid-editor'); | ||
13 | this.element.dom.tabIndex = 1; | ||
14 | this.initialized = false; | ||
15 | this.callback = null; | ||
16 | }; | ||
17 | |||
18 | YAHOO.ext.grid.CellEditor.prototype = { | ||
19 | init : function(grid, bodyElement, callback){ | ||
20 | // there's no way for the grid to know if multiple columns | ||
21 | // share the same editor so it will try to initialize the | ||
22 | // same one over and over | ||
23 | if(this.initialized) return; | ||
24 | this.initialized = true; | ||
25 | this.callback = callback; | ||
26 | this.grid = grid; | ||
27 | bodyElement.appendChild(this.element.dom); | ||
28 | this.initEvents(); | ||
29 | }, | ||
30 | |||
31 | initEvents : function(){ | ||
32 | var stopOnEnter = function(e){ | ||
33 | if(e.browserEvent.keyCode == e.RETURN){ | ||
34 | this.stopEditing(true); | ||
35 | }else if(e.browserEvent.keyCode == e.ESC){ | ||
36 | this.setValue(this.originalValue); | ||
37 | this.stopEditing(true); | ||
38 | } | ||
39 | } | ||
40 | this.element.mon('keydown', stopOnEnter, this, true); | ||
41 | this.element.on('blur', this.stopEditing, this, true); | ||
42 | }, | ||
43 | |||
44 | startEditing : function(value, row, cell){ | ||
45 | this.originalValue = value; | ||
46 | this.rowIndex = row.rowIndex; | ||
47 | this.colIndex = cell.columnIndex; | ||
48 | this.cell = cell; | ||
49 | this.setValue(value); | ||
50 | var cellbox = getEl(cell, true).getBox(); | ||
51 | this.fitToCell(cellbox); | ||
52 | this.editing = true; | ||
53 | this.show(); | ||
54 | }, | ||
55 | |||
56 | stopEditing : function(focusCell){ | ||
57 | if(this.editing){ | ||
58 | this.editing = false; | ||
59 | var newValue = this.getValue(); | ||
60 | this.hide(); | ||
61 | //if(focusCell){try{this.cell.focus();}catch(e){}}; // try to give the cell focus so keyboard nav still works | ||
62 | if(this.originalValue != newValue){ | ||
63 | this.callback(newValue, this.rowIndex, this.colIndex); | ||
64 | } | ||
65 | } | ||
66 | }, | ||
67 | |||
68 | setValue : function(value){ | ||
69 | this.element.dom.value = value; | ||
70 | }, | ||
71 | |||
72 | getValue : function(){ | ||
73 | return this.element.dom.value; | ||
74 | }, | ||
75 | |||
76 | fitToCell : function(box){ | ||
77 | this.element.setBox(box, true); | ||
78 | }, | ||
79 | |||
80 | show : function(){ | ||
81 | this.element.show(); | ||
82 | this.element.focus(); | ||
83 | }, | ||
84 | |||
85 | hide : function(){ | ||
86 | try{ | ||
87 | this.element.dom.blur(); | ||
88 | }catch(e){} | ||
89 | this.element.hide(); | ||
90 | } | ||
91 | }; | ||