1 if(!dojo._hasResource["dojox.grid._data.dijitEditors"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.grid._data.dijitEditors"] = true;
3 dojo.provide("dojox.grid._data.dijitEditors");
4 dojo.require("dojox.grid._data.editors");
5 dojo.require("dijit.form.DateTextBox");
6 dojo.require("dijit.form.TimeTextBox");
7 dojo.require("dijit.form.ComboBox");
8 dojo.require("dojo.data.ItemFileReadStore");
9 dojo.require("dijit.form.CheckBox");
10 dojo.require("dijit.form.TextBox");
11 dojo.require("dijit.form.NumberSpinner");
12 dojo.require("dijit.form.NumberTextBox");
13 dojo.require("dijit.form.CurrencyTextBox");
14 dojo.require("dijit.form.Slider");
15 dojo.require("dijit.Editor");
17 dojo.declare("dojox.grid.editors.Dijit", dojox.grid.editors.base, {
18 editorClass: "dijit.form.TextBox",
19 constructor: function(inCell){
21 this.editorClass = dojo.getObject(this.cell.editorClass || this.editorClass);
23 format: function(inDatum, inRowIndex){
24 this.needFormatNode(inDatum, inRowIndex);
27 getValue: function(inRowIndex){
28 return this.editor.getValue();
30 setValue: function(inRowIndex, inValue){
31 if(this.editor&&this.editor.setValue){
32 this.editor.setValue(inValue);
34 this.inherited(arguments);
37 getEditorProps: function(inDatum){
38 return dojo.mixin({}, this.cell.editorProps||{}, {
39 constraints: dojo.mixin({}, this.cell.constraint) || {}, //TODO: really just for ValidationTextBoxes
43 createEditor: function(inNode, inDatum, inRowIndex){
44 return new this.editorClass(this.getEditorProps(inDatum), inNode);
47 attachEditor: function(inNode, inDatum, inRowIndex){
48 inNode.appendChild(this.editor.domNode);
49 this.setValue(inRowIndex, inDatum);
51 formatNode: function(inNode, inDatum, inRowIndex){
52 if(!this.editorClass){
56 this.editor = this.createEditor.apply(this, arguments);
58 this.attachEditor.apply(this, arguments);
60 this.sizeEditor.apply(this, arguments);
61 this.cell.grid.rowHeightChanged(inRowIndex);
64 sizeEditor: function(inNode, inDatum, inRowIndex){
66 p = this.cell.getNode(inRowIndex),
67 box = dojo.contentBox(p);
68 dojo.marginBox(this.editor.domNode, {w: box.w});
70 focus: function(inRowIndex, inNode){
72 setTimeout(dojo.hitch(this.editor, function(){
73 dojox.grid.fire(this, "focus");
77 _finish: function(inRowIndex){
78 this.inherited(arguments);
79 dojox.grid.removeNode(this.editor.domNode);
83 dojo.declare("dojox.grid.editors.ComboBox", dojox.grid.editors.Dijit, {
84 editorClass: "dijit.form.ComboBox",
85 getEditorProps: function(inDatum){
87 dojo.forEach(this.cell.options, function(o){
88 items.push({name: o, value: o});
90 var store = new dojo.data.ItemFileReadStore({data: {identifier:"name", items: items}});
91 return dojo.mixin({}, this.cell.editorProps||{}, {
98 // make sure to apply the displayed value
99 e.setDisplayedValue(e.getDisplayedValue());
104 dojo.declare("dojox.grid.editors.DateTextBox", dojox.grid.editors.Dijit, {
105 editorClass: "dijit.form.DateTextBox",
106 setValue: function(inRowIndex, inValue){
108 this.editor.setValue(new Date(inValue));
110 this.inherited(arguments);
113 getEditorProps: function(inDatum){
114 return dojo.mixin(this.inherited(arguments), {
115 value: new Date(inDatum)
121 dojo.declare("dojox.grid.editors.CheckBox", dojox.grid.editors.Dijit, {
122 editorClass: "dijit.form.CheckBox",
123 getValue: function(){
124 return this.editor.checked;
126 setValue: function(inRowIndex, inValue){
127 if(this.editor&&this.editor.setAttribute){
128 this.editor.setAttribute("checked", inValue);
130 this.inherited(arguments);
133 sizeEditor: function(inNode, inDatum, inRowIndex){
139 dojo.declare("dojox.grid.editors.Editor", dojox.grid.editors.Dijit, {
140 editorClass: "dijit.Editor",
141 getEditorProps: function(inDatum){
142 return dojo.mixin({}, this.cell.editorProps||{}, {
143 height: this.cell.editorHeight || "100px"
146 createEditor: function(inNode, inDatum, inRowIndex){
147 // editor needs its value set after creation
148 var editor = new this.editorClass(this.getEditorProps(inDatum), inNode);
149 dojo.connect(editor, 'onLoad', dojo.hitch(this, 'populateEditor'));
152 formatNode: function(inNode, inDatum, inRowIndex){
153 this.content = inDatum;
154 this.inherited(arguments);
156 // FIXME: seem to need to reopen the editor and display the toolbar
159 if(this.cell.editorToolbar){
160 dojo.place(e.toolbar.domNode, e.editingArea, "before");
164 populateEditor: function(){
165 this.editor.setValue(this.content);
166 this.editor.placeCursorAtEnd();