1 if(!dojo._hasResource["dojox.grid._data.editors"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.grid._data.editors"] = true;
3 dojo.provide("dojox.grid._data.editors");
4 dojo.provide("dojox.grid.editors");
6 dojo.declare("dojox.grid.editors.Base", null, {
8 // base grid editor class. Other grid editors should inherited from this class.
9 constructor: function(inCell){
14 _formatPending: false,
15 format: function(inDatum, inRowIndex){
17 // formats the cell for editing
22 // returns: string of html to place in grid cell
25 needFormatNode: function(inDatum, inRowIndex){
26 this._formatPending = true;
27 dojox.grid.whenIdle(this, "_formatNode", inDatum, inRowIndex);
29 cancelFormatNode: function(){
30 this._formatPending = false;
33 _formatNode: function(inDatum, inRowIndex){
34 if(this._formatPending){
35 this._formatPending = false;
36 // make cell selectable
37 dojo.setSelectable(this.cell.grid.domNode, true);
38 this.formatNode(this.getNode(inRowIndex), inDatum, inRowIndex);
42 getNode: function(inRowIndex){
43 return (this.cell.getNode(inRowIndex) || 0).firstChild || 0;
45 formatNode: function(inNode, inDatum, inRowIndex){
47 // format the editing dom node. Use when editor is a widget.
49 // dom node for the editor
56 dojox.grid.whenIdle(this, "focus", inRowIndex, inNode);
58 this.focus(inRowIndex, inNode);
61 dispatchEvent: function(m, e){
67 getValue: function(inRowIndex){
69 // returns value entered into editor
74 return this.getNode(inRowIndex)[this._valueProp];
76 setValue: function(inRowIndex, inValue){
78 // set the value of the grid editor
83 var n = this.getNode(inRowIndex);
85 n[this._valueProp] = inValue
88 focus: function(inRowIndex, inNode){
90 // focus the grid editor
95 dojox.grid.focusSelectNode(inNode || this.getNode(inRowIndex));
97 save: function(inRowIndex){
102 this.value = this.value || this.getValue(inRowIndex);
103 //console.log("save", this.value, inCell.index, inRowIndex);
105 restore: function(inRowIndex){
107 // restore editor state
110 this.setValue(inRowIndex, this.value);
111 //console.log("restore", this.value, inCell.index, inRowIndex);
114 _finish: function(inRowIndex){
116 // called when editing is completed to clean up editor
119 dojo.setSelectable(this.cell.grid.domNode, false);
120 this.cancelFormatNode(this.cell);
123 apply: function(inRowIndex){
125 // apply edit from cell editor
128 this.cell.applyEdit(this.getValue(inRowIndex), inRowIndex);
129 this._finish(inRowIndex);
131 cancel: function(inRowIndex){
136 this.cell.cancelEdit(inRowIndex);
137 this._finish(inRowIndex);
140 dojox.grid.editors.base = dojox.grid.editors.Base; // back-compat
142 dojo.declare("dojox.grid.editors.Input", dojox.grid.editors.Base, {
144 // grid cell editor that provides a standard text input box
145 constructor: function(inCell){
146 this.keyFilter = this.keyFilter || this.cell.keyFilter;
149 // optional regex for disallowing keypresses
151 format: function(inDatum, inRowIndex){
152 this.needFormatNode(inDatum, inRowIndex);
153 return '<input class="dojoxGrid-input" type="text" value="' + inDatum + '">';
155 formatNode: function(inNode, inDatum, inRowIndex){
156 this.inherited(arguments);
157 // FIXME: feels too specific for this interface
158 this.cell.registerOnBlur(inNode, inRowIndex);
162 var key = String.fromCharCode(e.charCode);
163 if(key.search(this.keyFilter) == -1){
168 _finish: function(inRowIndex){
169 this.inherited(arguments);
170 var n = this.getNode(inRowIndex);
172 dojox.grid.fire(n, "blur");
176 dojox.grid.editors.input = dojox.grid.editors.Input; // back compat
178 dojo.declare("dojox.grid.editors.Select", dojox.grid.editors.Input, {
180 // grid cell editor that provides a standard select
181 // options: text of each item
182 // values: value for each item
183 // returnIndex: editor returns only the index of the selected option and not the value
184 constructor: function(inCell){
185 this.options = this.options || this.cell.options;
186 this.values = this.values || this.cell.values || this.options;
188 format: function(inDatum, inRowIndex){
189 this.needFormatNode(inDatum, inRowIndex);
190 var h = [ '<select class="dojoxGrid-select">' ];
191 for (var i=0, o, v; ((o=this.options[i]) !== undefined)&&((v=this.values[i]) !== undefined); i++){
192 h.push("<option", (inDatum==v ? ' selected' : ''), ' value="' + v + '"', ">", o, "</option>");
197 getValue: function(inRowIndex){
198 var n = this.getNode(inRowIndex);
200 var i = n.selectedIndex, o = n.options[i];
201 return this.cell.returnIndex ? i : o.value || o.innerHTML;
205 dojox.grid.editors.select = dojox.grid.editors.Select; // back compat
207 dojo.declare("dojox.grid.editors.AlwaysOn", dojox.grid.editors.Input, {
209 // grid cell editor that is always on, regardless of grid editing state
211 // flag to use editor to format grid cell regardless of editing state.
213 _formatNode: function(inDatum, inRowIndex){
214 this.formatNode(this.getNode(inRowIndex), inDatum, inRowIndex);
216 applyStaticValue: function(inRowIndex){
217 var e = this.cell.grid.edit;
218 e.applyCellEdit(this.getValue(inRowIndex), this.cell, inRowIndex);
219 e.start(this.cell, inRowIndex, true);
222 dojox.grid.editors.alwaysOn = dojox.grid.editors.AlwaysOn; // back-compat
224 dojo.declare("dojox.grid.editors.Bool", dojox.grid.editors.AlwaysOn, {
226 // grid cell editor that provides a standard checkbox that is always on
227 _valueProp: "checked",
228 format: function(inDatum, inRowIndex){
229 return '<input class="dojoxGrid-input" type="checkbox"' + (inDatum ? ' checked="checked"' : '') + ' style="width: auto" />';
231 doclick: function(e){
232 if(e.target.tagName == 'INPUT'){
233 this.applyStaticValue(e.rowIndex);
237 dojox.grid.editors.bool = dojox.grid.editors.Bool; // back-compat