2150 |
mathias |
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("dijit.form.CheckBox");
|
|
|
9 |
dojo.require("dijit.form.TextBox");
|
|
|
10 |
dojo.require("dijit.form.NumberSpinner");
|
|
|
11 |
dojo.require("dijit.form.NumberTextBox");
|
|
|
12 |
dojo.require("dijit.form.CurrencyTextBox");
|
|
|
13 |
dojo.require("dijit.form.Slider");
|
|
|
14 |
dojo.require("dijit.Editor");
|
|
|
15 |
|
|
|
16 |
dojo.declare("dojox.grid.editors.Dijit", dojox.grid.editors.base, {
|
|
|
17 |
editorClass: "dijit.form.TextBox",
|
|
|
18 |
constructor: function(inCell){
|
|
|
19 |
this.editor = null;
|
|
|
20 |
this.editorClass = dojo.getObject(this.cell.editorClass || this.editorClass);
|
|
|
21 |
},
|
|
|
22 |
format: function(inDatum, inRowIndex){
|
|
|
23 |
this.needFormatNode(inDatum, inRowIndex);
|
|
|
24 |
return "<div></div>";
|
|
|
25 |
},
|
|
|
26 |
getValue: function(inRowIndex){
|
|
|
27 |
return this.editor.getValue();
|
|
|
28 |
},
|
|
|
29 |
setValue: function(inRowIndex, inValue){
|
|
|
30 |
if(this.editor&&this.editor.setValue){
|
|
|
31 |
this.editor.setValue(inValue);
|
|
|
32 |
}else{
|
|
|
33 |
this.inherited(arguments);
|
|
|
34 |
}
|
|
|
35 |
},
|
|
|
36 |
getEditorProps: function(inDatum){
|
|
|
37 |
return dojo.mixin({}, this.cell.editorProps||{}, {
|
|
|
38 |
constraints: dojo.mixin({}, this.cell.constraint) || {}, //TODO: really just for ValidationTextBoxes
|
|
|
39 |
value: inDatum
|
|
|
40 |
});
|
|
|
41 |
},
|
|
|
42 |
createEditor: function(inNode, inDatum, inRowIndex){
|
|
|
43 |
return new this.editorClass(this.getEditorProps(inDatum), inNode);
|
|
|
44 |
|
|
|
45 |
},
|
|
|
46 |
attachEditor: function(inNode, inDatum, inRowIndex){
|
|
|
47 |
inNode.appendChild(this.editor.domNode);
|
|
|
48 |
this.setValue(inRowIndex, inDatum);
|
|
|
49 |
},
|
|
|
50 |
formatNode: function(inNode, inDatum, inRowIndex){
|
|
|
51 |
if(!this.editorClass){
|
|
|
52 |
return inDatum;
|
|
|
53 |
}
|
|
|
54 |
if(!this.editor){
|
|
|
55 |
this.editor = this.createEditor.apply(this, arguments);
|
|
|
56 |
}else{
|
|
|
57 |
this.attachEditor.apply(this, arguments);
|
|
|
58 |
}
|
|
|
59 |
this.sizeEditor.apply(this, arguments);
|
|
|
60 |
this.cell.grid.rowHeightChanged(inRowIndex);
|
|
|
61 |
this.focus();
|
|
|
62 |
},
|
|
|
63 |
sizeEditor: function(inNode, inDatum, inRowIndex){
|
|
|
64 |
var
|
|
|
65 |
p = this.cell.getNode(inRowIndex),
|
|
|
66 |
box = dojo.contentBox(p);
|
|
|
67 |
dojo.marginBox(this.editor.domNode, {w: box.w});
|
|
|
68 |
},
|
|
|
69 |
focus: function(inRowIndex, inNode){
|
|
|
70 |
if(this.editor){
|
|
|
71 |
setTimeout(dojo.hitch(this.editor, function(){
|
|
|
72 |
dojox.grid.fire(this, "focus");
|
|
|
73 |
}), 0);
|
|
|
74 |
}
|
|
|
75 |
},
|
|
|
76 |
_finish: function(inRowIndex){
|
|
|
77 |
this.inherited(arguments);
|
|
|
78 |
dojox.grid.removeNode(this.editor.domNode);
|
|
|
79 |
}
|
|
|
80 |
});
|
|
|
81 |
|
|
|
82 |
dojo.declare("dojox.grid.editors.ComboBox", dojox.grid.editors.Dijit, {
|
|
|
83 |
editorClass: "dijit.form.ComboBox",
|
|
|
84 |
getEditorProps: function(inDatum){
|
|
|
85 |
var items=[];
|
|
|
86 |
dojo.forEach(this.cell.options, function(o){
|
|
|
87 |
items.push({name: o, value: o});
|
|
|
88 |
});
|
|
|
89 |
var store = new dojo.data.ItemFileReadStore({data: {identifier:"name", items: items}});
|
|
|
90 |
return dojo.mixin({}, this.cell.editorProps||{}, {
|
|
|
91 |
value: inDatum,
|
|
|
92 |
store: store
|
|
|
93 |
});
|
|
|
94 |
},
|
|
|
95 |
getValue: function(){
|
|
|
96 |
var e = this.editor;
|
|
|
97 |
// make sure to apply the displayed value
|
|
|
98 |
e.setDisplayedValue(e.getDisplayedValue());
|
|
|
99 |
return e.getValue();
|
|
|
100 |
}
|
|
|
101 |
});
|
|
|
102 |
|
|
|
103 |
dojo.declare("dojox.grid.editors.DateTextBox", dojox.grid.editors.Dijit, {
|
|
|
104 |
editorClass: "dijit.form.DateTextBox",
|
|
|
105 |
setValue: function(inRowIndex, inValue){
|
|
|
106 |
if(this.editor){
|
|
|
107 |
this.editor.setValue(new Date(inValue));
|
|
|
108 |
}else{
|
|
|
109 |
this.inherited(arguments);
|
|
|
110 |
}
|
|
|
111 |
},
|
|
|
112 |
getEditorProps: function(inDatum){
|
|
|
113 |
return dojo.mixin(this.inherited(arguments), {
|
|
|
114 |
value: new Date(inDatum)
|
|
|
115 |
});
|
|
|
116 |
}
|
|
|
117 |
});
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
dojo.declare("dojox.grid.editors.CheckBox", dojox.grid.editors.Dijit, {
|
|
|
121 |
editorClass: "dijit.form.CheckBox",
|
|
|
122 |
getValue: function(){
|
|
|
123 |
return this.editor.checked;
|
|
|
124 |
}
|
|
|
125 |
});
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
dojo.declare("dojox.grid.editors.Editor", dojox.grid.editors.Dijit, {
|
|
|
129 |
editorClass: "dijit.Editor",
|
|
|
130 |
getEditorProps: function(inDatum){
|
|
|
131 |
return dojo.mixin({}, this.cell.editorProps||{}, {
|
|
|
132 |
height: this.cell.editorHeight || "100px"
|
|
|
133 |
});
|
|
|
134 |
},
|
|
|
135 |
createEditor: function(inNode, inDatum, inRowIndex){
|
|
|
136 |
// editor needs its value set after creation
|
|
|
137 |
var editor = new this.editorClass(this.getEditorProps(inDatum), inNode);
|
|
|
138 |
editor.setValue(inDatum);
|
|
|
139 |
return editor;
|
|
|
140 |
},
|
|
|
141 |
formatNode: function(inNode, inDatum, inRowIndex){
|
|
|
142 |
this.inherited(arguments);
|
|
|
143 |
// FIXME: seem to need to reopen the editor and display the toolbar
|
|
|
144 |
var e = this.editor;
|
|
|
145 |
e.open();
|
|
|
146 |
if(this.cell.editorToolbar){
|
|
|
147 |
dojo.place(e.toolbar.domNode, e.editingArea, "before");
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
});
|
|
|
151 |
|
|
|
152 |
}
|