Debian Codegraph @

dojox/wire/ml/Transfer.js

raw symbols SCIP
1 dojo.provide("dojox.wire.ml.Transfer");
2
3 dojo.require("dijit._Widget");
4 dojo.require("dijit._Container");
5 dojo.require("dojox.wire._base");
6 dojo.require("dojox.wire.ml.Action");
7
8 dojo.declare("dojox.wire.ml.Transfer", dojox.wire.ml.Action, {
9 // summary:
10 // A widget to transfer values through source and target Wires
11 // description:
12 // This widget represents a controller task to transfer a value from
13 // a source to a target, through a source and a target Wires, when
14 // an event (a function) or a topic is issued.
15 // If this widget has child ChildWire widgets, their _addWire()
16 // methods are called to add Wire arguments to a source or a target
17 // Wire.
18
19 // source:
20 // A source object and/or property
21 source: "",
22
23 // sourceStore:
24 // A data store for a source data item
25 sourceStore: "",
26
27 // sourceAttribute:
28 // An attribute of a source data item
29 sourceAttribute: "",
30
31 // sourcePath:
32 // A simplified XPath to a source property of an XML element
33 sourcePath: "",
34
35 // type:
36 // A type of the value to be transferred
37 type: "",
38
39 // converter:
40 // A class name of a converter for the value to be transferred
41 converter: "",
42
43 // target:
44 // A target object and/or property
45 target: "",
46
47 // targetStore:
48 // A data store for a target data item
49 targetStore: "",
50
51 // targetAttribute:
52 // An attribute of a target data item
53 targetAttribute: "",
54
55 // targetPath:
56 // A simplified XPath to a target property of an XML element
57 targetPath: "",
58
59 delimiter: "",
60
61 _run: function(){
62 // summary:
63 // Transfer a value from a source to a target
64 // description:
65 // First, Wires for a source and a target are created from attributes.
66 // Then, a value is obtained by getValue() of the source Wire is set
67 // by setValue() of the target Wire.
68 // The arguments to this method is passed to getValue() and setValue()
69 // of Wires, so that they can be used to identify the root objects off
70 // the arguments.
71 var sourceWire = this._getWire("source");
72 var targetWire = this._getWire("target");
73 dojox.wire.transfer(sourceWire, targetWire, arguments);
74 },
75
76 _getWire: function(/*String*/which){
77 // summary:
78 // Build Wire arguments from attributes
79 // description:
80 // Arguments object for a source or a target Wire, specified by
81 // 'which' argument, are build from corresponding attributes,
82 // including '*Store' (for 'dataStore'), '*Attribute'
83 // (for 'attribute), '*Path' (for 'path'), 'type' and 'converter'.
84 // 'source' or 'target' attribute is parsed as:
85 // | "object_id.property_name[.sub_property_name...]"
86 // If 'source' or 'target' starts with "arguments", 'object'
87 // argument for a Wire is set to null, so that the root object is
88 // given as an event or topic arguments.
89 // If this widget has child ChildWire widgets with a corresponding
90 // 'which' attribute, their _addWire() methods are called to add
91 // additional Wire arguments and nested Wire is created,
92 // specifying the Wire defined by this widget to 'object' argument.
93 // which:
94 // Which Wire arguments to build, "source" or "target"
95 // returns:
96 // Wire arguments object
97 var args = undefined;
98 if(which == "source"){
99 args = {
100 object: this.source,
101 dataStore: this.sourceStore,
102 attribute: this.sourceAttribute,
103 path: this.sourcePath,
104 type: this.type,
105 converter: this.converter
106 };
107 }else{ // "target"
108 args = {
109 object: this.target,
110 dataStore: this.targetStore,
111 attribute: this.targetAttribute,
112 path: this.targetPath
113 };
114 }
115 if(args.object){
116 if(args.object.length >= 9 && args.object.substring(0, 9) == "arguments"){
117 args.property = args.object.substring(9);
118 args.object = null;
119 }else{
120 var i = args.object.indexOf('.');
121 if(i < 0){
122 args.object = dojox.wire.ml._getValue(args.object);
123 }else{
124 args.property = args.object.substring(i + 1);
125 args.object = dojox.wire.ml._getValue(args.object.substring(0, i));
126 }
127 }
128 }
129 if(args.dataStore){
130 args.dataStore = dojox.wire.ml._getValue(args.dataStore);
131 }
132 var childArgs = undefined;
133 var children = this.getChildren();
134 for(var i in children){
135 var child = children[i];
136 if(child instanceof dojox.wire.ml.ChildWire && child.which == which){
137 if(!childArgs){
138 childArgs = {};
139 }
140 child._addWire(this, childArgs);
141 }
142 }
143 if(childArgs){ // make nested Wires
144 childArgs.object = dojox.wire.create(args);
145 childArgs.dataStore = args.dataStore;
146 args = childArgs;
147 }
148 return args; //Object
149 }
150 });
151
152 dojo.declare("dojox.wire.ml.ChildWire", dijit._Widget, {
153 // summary:
154 // A widget to add a child wire
155 // description:
156 // Attributes of this widget are used to add a child Wire to
157 // a composite Wire of the parent Transfer widget.
158 // which:
159 // Which Wire to add a child Wire, "source" or "target", default to
160 // "source"
161 // object:
162 // A root object for the value
163 // property:
164 // A property for the value
165 // type:
166 // A type of the value
167 // converter:
168 // A class name of a converter for the value
169 // attribute:
170 // A data item attribute for the value
171 // path:
172 // A simplified XPath for the value
173 // name:
174 // A composite property name
175 which: "source",
176 object: "",
177 property: "",
178 type: "",
179 converter: "",
180 attribute: "",
181 path: "",
182 name: "",
183
184 _addWire: function(/*Transfer*/parent, /*Object*/args){
185 // summary:
186 // Add a child Wire to Wire arguments
187 // description:
188 // If 'name' attribute is specified, a child Wire is added as
189 // the named property of 'children' object of 'args'.
190 // Otherwise, a child Wire is added to 'children' array of 'args'.
191 // parent:
192 // A parent Transfer widget
193 // args:
194 // Wire arguments
195 if(this.name){ // object
196 if(!args.children){
197 args.children = {};
198 }
199 args.children[this.name] = this._getWire(parent);
200 }else{ // array
201 if(!args.children){
202 args.children = [];
203 }
204 args.children.push(this._getWire(parent));
205 }
206 },
207
208 _getWire: function(/*Transfer*/parent){
209 // summary:
210 // Build child Wire arguments from attributes
211 // description:
212 // Arguments object for a child Wire are build from attributes,
213 // including 'object', 'property', 'type', 'converter',
214 // 'attribute' and 'path'.
215 // parent:
216 // A parent Transfer widget
217 // returns:
218 // Wire arguments object
219 return {
220 object: (this.object ? dojox.wire.ml._getValue(this.object) : undefined),
221 property: this.property,
222 type: this.type,
223 converter: this.converter,
224 attribute: this.attribute,
225 path: this.path
226 }; //Object
227 }
228 });
229
230 dojo.declare("dojox.wire.ml.ColumnWire", dojox.wire.ml.ChildWire, {
231 // summary:
232 // A widget to add a column wire
233 // description:
234 // Attributes of this widget are used to add a column Wire to
235 // a TableAdapter of the parent Transfer widget.
236 // column:
237 // A column name
238 column: "",
239
240 _addWire: function(/*Transfer*/parent, /*Object*/args){
241 // summary:
242 // Add a column Wire to Wire arguments
243 // description:
244 // If 'column' attribute is specified, a column Wire is added as
245 // the named property of 'columns' object of 'args'.
246 // Otherwise, a column Wire is added to 'columns' array of 'args'.
247 // parent:
248 // A parent Transfer widget
249 // args:
250 // Wire arguments
251 if(this.column){ // object
252 if(!args.columns){
253 args.columns = {};
254 }
255 args.columns[this.column] = this._getWire(parent);
256 }else{ // array
257 if(!args.columns){
258 args.columns = [];
259 }
260 args.columns.push(this._getWire(parent));
261 }
262 }
263 });
264
265 dojo.declare("dojox.wire.ml.NodeWire", [dojox.wire.ml.ChildWire, dijit._Container], {
266 // summary:
267 // A widget to add node wires
268 // description:
269 // Attributes of this widget are used to add node Wires to
270 // a TreeAdapter of the parent Transfer widget.
271 // titleProperty:
272 // A property for the node title
273 // titleAttribute:
274 // A data item attribute for the node title
275 // titlePath:
276 // A simplified XPath for the node title
277 titleProperty: "",
278 titleAttribute: "",
279 titlePath: "",
280
281 _addWire: function(/*Transfer*/parent, /*Object*/args){
282 // summary:
283 // Add node Wires to Wire arguments
284 // description:
285 // Node Wires are added to 'nodes' array of 'args'.
286 // parent:
287 // A parent Transfer widget
288 // args:
289 // Wire arguments
290 if(!args.nodes){
291 args.nodes = [];
292 }
293 args.nodes.push(this._getWires(parent));
294 },
295
296 _getWires: function(/*Transfer*/parent){
297 // summary:
298 // Build node Wires arguments from attributes
299 // description:
300 // Arguments object for 'node' Wire are build from attributes,
301 // including 'object', 'property', 'type', 'converter',
302 // 'attribute' and 'path'.
303 // Arguments object for 'title' Wire are build from another set of
304 // attributes, 'titleProperty', 'titleAttribute' and 'titlePath'.
305 // If this widget has child NodeWire widgets, their _getWires()
306 // methods are called recursively to build 'children' array of
307 // 'args'.
308 // parent:
309 // A parent Transfer widget
310 // returns:
311 // Wire arguments object
312 var args = {
313 node: this._getWire(parent),
314 title: {
315 type: "string",
316 property: this.titleProperty,
317 attribute: this.titleAttribute,
318 path: this.titlePath
319 }
320 };
321 var childArgs = [];
322 var children = this.getChildren();
323 for(var i in children){
324 var child = children[i];
325 if(child instanceof dojox.wire.ml.NodeWire){
326 childArgs.push(child._getWires(parent));
327 }
328 }
329 if(childArgs.length > 0){
330 args.children = childArgs;
331 }
332 return args; //Object
333 }
334 });
335
336 dojo.declare("dojox.wire.ml.SegmentWire", dojox.wire.ml.ChildWire, {
337 // summary:
338 // A widget to add a segment wire
339 // description:
340 // Attributes of this widget are used to add a segment Wire to
341 // a TextAdapter of the parent Transfer widget.
342
343 _addWire: function(/*Transfer*/parent, /*Object*/args){
344 // summary:
345 // Add a segment Wire to Wire arguments
346 // description:
347 // A segment Wire is added to 'segments' array of 'args'.
348 // If 'parent' has 'delimiter' attribute, it is used for
349 // 'delimiter' property of 'args'.
350 // parent:
351 // A parent Transfer widget
352 // args:
353 // Wire arguments
354 if(!args.segments){
355 args.segments = [];
356 }
357 args.segments.push(this._getWire(parent));
358 if(parent.delimiter && !args.delimiter){
359 args.delimiter = parent.delimiter;
360 }
361 }
362 });