source: Dev/branches/rest-dojo-ui/client/dojox/wire/ml/Transfer.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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