]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/grid/_data/editors.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / grid / _data / editors.js
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");
5
6 dojo.declare("dojox.grid.editors.Base", null, {
7         // summary:
8         //      base grid editor class. Other grid editors should inherited from this class.
9         constructor: function(inCell){
10                 this.cell = inCell;
11         },
12         //private
13         _valueProp: "value",
14         _formatPending: false,
15         format: function(inDatum, inRowIndex){
16                 // summary:
17                 //      formats the cell for editing
18                 // inDatum: anything
19                 //      cell data to edit
20                 // inRowIndex: int
21                 //      grid row index
22                 // returns: string of html to place in grid cell
23         },
24         //protected
25         needFormatNode: function(inDatum, inRowIndex){
26                 this._formatPending = true;
27                 dojox.grid.whenIdle(this, "_formatNode", inDatum, inRowIndex);
28         },
29         cancelFormatNode: function(){
30                 this._formatPending = false;
31         },
32         //private
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);
39                 }
40         },
41         //protected
42         getNode: function(inRowIndex){
43                 return (this.cell.getNode(inRowIndex) || 0).firstChild || 0;
44         },
45         formatNode: function(inNode, inDatum, inRowIndex){
46                 // summary:
47                 //      format the editing dom node. Use when editor is a widget.
48                 // inNode: dom node
49                 // dom node for the editor
50                 // inDatum: anything
51                 //      cell data to edit
52                 // inRowIndex: int
53                 //      grid row index
54                 if(dojo.isIE){
55                         // IE sux bad
56                         dojox.grid.whenIdle(this, "focus", inRowIndex, inNode);
57                 }else{
58                         this.focus(inRowIndex, inNode);
59                 }
60         },
61         dispatchEvent: function(m, e){
62                 if(m in this){
63                         return this[m](e);
64                 }
65         },
66         //public
67         getValue: function(inRowIndex){
68                 // summary:
69                 //      returns value entered into editor
70                 // inRowIndex: int
71                 // grid row index
72                 // returns:
73                 //      value of editor
74                 return this.getNode(inRowIndex)[this._valueProp];
75         },
76         setValue: function(inRowIndex, inValue){
77                 // summary:
78                 //      set the value of the grid editor
79                 // inRowIndex: int
80                 // grid row index
81                 // inValue: anything
82                 //      value of editor
83                 var n = this.getNode(inRowIndex);
84                 if(n){
85                         n[this._valueProp] = inValue
86                 };
87         },
88         focus: function(inRowIndex, inNode){
89                 // summary:
90                 //      focus the grid editor
91                 // inRowIndex: int
92                 // grid row index
93                 // inNode: dom node
94                 //      editor node
95                 dojox.grid.focusSelectNode(inNode || this.getNode(inRowIndex));
96         },
97         save: function(inRowIndex){
98                 // summary:
99                 //      save editor state
100                 // inRowIndex: int
101                 // grid row index
102                 this.value = this.value || this.getValue(inRowIndex);
103                 //console.log("save", this.value, inCell.index, inRowIndex);
104         },
105         restore: function(inRowIndex){
106                 // summary:
107                 //      restore editor state
108                 // inRowIndex: int
109                 // grid row index
110                 this.setValue(inRowIndex, this.value);
111                 //console.log("restore", this.value, inCell.index, inRowIndex);
112         },
113         //protected
114         _finish: function(inRowIndex){
115                 // summary:
116                 //      called when editing is completed to clean up editor
117                 // inRowIndex: int
118                 // grid row index
119                 dojo.setSelectable(this.cell.grid.domNode, false);
120                 this.cancelFormatNode(this.cell);
121         },
122         //public
123         apply: function(inRowIndex){
124                 // summary:
125                 //      apply edit from cell editor
126                 // inRowIndex: int
127                 // grid row index
128                 this.cell.applyEdit(this.getValue(inRowIndex), inRowIndex);
129                 this._finish(inRowIndex);
130         },
131         cancel: function(inRowIndex){
132                 // summary:
133                 //      cancel cell edit
134                 // inRowIndex: int
135                 // grid row index
136                 this.cell.cancelEdit(inRowIndex);
137                 this._finish(inRowIndex);
138         }
139 });
140 dojox.grid.editors.base = dojox.grid.editors.Base; // back-compat
141
142 dojo.declare("dojox.grid.editors.Input", dojox.grid.editors.Base, {
143         // summary
144         // grid cell editor that provides a standard text input box
145         constructor: function(inCell){
146                 this.keyFilter = this.keyFilter || this.cell.keyFilter;
147         },
148         // keyFilter: object
149         // optional regex for disallowing keypresses
150         keyFilter: null,
151         format: function(inDatum, inRowIndex){
152                 this.needFormatNode(inDatum, inRowIndex);
153                 return '<input class="dojoxGrid-input" type="text" value="' + inDatum + '">';
154         },
155         formatNode: function(inNode, inDatum, inRowIndex){
156                 this.inherited(arguments);
157                 // FIXME: feels too specific for this interface
158                 this.cell.registerOnBlur(inNode, inRowIndex);
159         },
160         doKey: function(e){
161                 if(this.keyFilter){
162                         var key = String.fromCharCode(e.charCode);
163                         if(key.search(this.keyFilter) == -1){
164                                 dojo.stopEvent(e);
165                         }
166                 }
167         },
168         _finish: function(inRowIndex){
169                 this.inherited(arguments);
170                 var n = this.getNode(inRowIndex);
171                 try{
172                         dojox.grid.fire(n, "blur");
173                 }catch(e){}
174         }
175 });
176 dojox.grid.editors.input = dojox.grid.editors.Input; // back compat
177
178 dojo.declare("dojox.grid.editors.Select", dojox.grid.editors.Input, {
179         // summary:
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;
187         },
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>");
193                 }
194                 h.push('</select>');
195                 return h.join('');
196         },
197         getValue: function(inRowIndex){
198                 var n = this.getNode(inRowIndex);
199                 if(n){
200                         var i = n.selectedIndex, o = n.options[i];
201                         return this.cell.returnIndex ? i : o.value || o.innerHTML;
202                 }
203         }
204 });
205 dojox.grid.editors.select = dojox.grid.editors.Select; // back compat
206
207 dojo.declare("dojox.grid.editors.AlwaysOn", dojox.grid.editors.Input, {
208         // summary:
209         // grid cell editor that is always on, regardless of grid editing state
210         // alwaysOn: boolean
211         // flag to use editor to format grid cell regardless of editing state.
212         alwaysOn: true,
213         _formatNode: function(inDatum, inRowIndex){
214                 this.formatNode(this.getNode(inRowIndex), inDatum, inRowIndex);
215         },
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);
220         }
221 });
222 dojox.grid.editors.alwaysOn = dojox.grid.editors.AlwaysOn; // back-compat
223
224 dojo.declare("dojox.grid.editors.Bool", dojox.grid.editors.AlwaysOn, {
225         // summary:
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" />';
230         },
231         doclick: function(e){
232                 if(e.target.tagName == 'INPUT'){
233                         this.applyStaticValue(e.rowIndex);
234                 }
235         }
236 });
237 dojox.grid.editors.bool = dojox.grid.editors.Bool; // back-compat
238
239 }