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