Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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