source: Dev/branches/rest-dojo-ui/client/dojox/wire/CompositeWire.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: 3.0 KB
Line 
1dojo.provide("dojox.wire.CompositeWire");
2
3dojo.require("dojox.wire._base");
4dojo.require("dojox.wire.Wire");
5
6dojo.declare("dojox.wire.CompositeWire", dojox.wire.Wire, {
7        //      summary:
8        //              A Wire for composite values in object or array
9        //      description:
10        //              This class has multiple child Wires for object properties or array
11        //              elements.
12        //              When an object with Wires is specified to 'children' property, they
13        //              are used to get or set an object with property values.
14        //              When an array of Wiares is specified to 'children' property, they
15        //              are used to get or set an array with element values.
16       
17        _wireClass: "dojox.wire.CompositeWire",
18
19        constructor: function(/*Object*/args){
20                //      summary:
21                //              Initialize properties
22                //      description:
23                //              If object properties or array elements specified in 'children'
24                //              property are not Wires, Wires are created from them as
25                //              arguments, with 'parent' property set to this Wire instance.
26                //      args:
27                //              Arguments to initialize properties
28                //              children:
29                //                      An object or array containing child Wires
30                this._initializeChildren(this.children);
31        },
32        _getValue: function(/*Object||Array*/object){
33                //      summary:
34                //              Return an object with property values or an array with element
35                //              values
36                //      description:
37                //              This method calls getValue() method of the child Wires with
38                //              'object' argument and returns an object with the values as
39                //              properties or an arary of the values as elements.
40                //      object:
41                //              A root object
42                //      returns:
43                //              An object or array with values
44                if(!object || !this.children){
45                        return object; //Object||Array
46                }
47
48                var value = (dojo.isArray(this.children) ? [] : {}); // array or object
49                for(var c in this.children){
50                        value[c] = this.children[c].getValue(object);
51                }
52                return value;//Object||Array
53        },
54
55        _setValue: function(/*Object||Array*/object, /*Object||Array*/value){
56                //      summary:
57                //              Set an object properties or an array elements to an object
58                //      desription:
59                //              This method calls setValues() method of the child Wires with
60                //              a corresponding property or element in 'value' argument and
61                //              'object' argument.
62                //      object:
63                //              A root object
64                //      value:
65                //              An object or array with values to set
66                //      returns:
67                //              'object'
68                if(!object || !this.children){
69                        return object; //Object||Array
70                }
71
72                for(var c in this.children){
73                        this.children[c].setValue(value[c], object);
74                }
75                return object; //Object||Array
76        },
77
78        _initializeChildren: function(/*Object||Array*/children){
79                //      summary:
80                //              Initialize child Wires
81                //      description:
82                //              If object properties or array elements specified in 'children'
83                //              argument are not Wires, Wires are created from them as
84                //              arguments, with 'parent' property set to this Wire instance.
85                //      children:
86                //              An object or array containing child Wires
87                if(!children){
88                        return; //undefined
89                }
90
91                for(var c in children){
92                        var child = children[c];
93                        child.parent = this;
94                        if(!dojox.wire.isWire(child)){
95                                children[c] = dojox.wire.create(child);
96                        }
97                }
98        }
99});
Note: See TracBrowser for help on using the repository browser.