Debian Codegraph @

dojox/wire/ml/Data.js

raw symbols SCIP
1 dojo.provide("dojox.wire.ml.Data");
2
3 dojo.require("dijit._Widget");
4 dojo.require("dijit._Container");
5 dojo.require("dojox.wire.ml.util");
6
7 dojo.declare("dojox.wire.ml.Data", [dijit._Widget, dijit._Container], {
8 // summary:
9 // A widget for a data object
10 // description:
11 // This widget represents an object with '_properties' property.
12 // If child 'DataProperty' widgets exist, they are used to initialize
13 // propertiy values of '_properties' object.
14
15 startup: function(){
16 // summary:
17 // Call _initializeProperties()
18 // description:
19 // See _initializeProperties().
20 this._initializeProperties();
21 },
22
23 _initializeProperties: function(/*Boolean*/reset){
24 // summary:
25 // Initialize a data object
26 // description:
27 // If this widget has child DataProperty widgets, their getValue()
28 // methods are called and set the return value to a property
29 // specified by 'name' attribute of the child widgets.
30 // reset:
31 // A boolean to reset current properties
32 if(!this._properties || reset){
33 this._properties = {};
34 }
35 var children = this.getChildren();
36 for(var i in children){
37 var child = children[i];
38 if((child instanceof dojox.wire.ml.DataProperty) && child.name){
39 this.setPropertyValue(child.name, child.getValue());
40 }
41 }
42 },
43
44 getPropertyValue: function(/*String*/property){
45 // summary:
46 // Return a property value
47 // description:
48 // This method returns the value of a property, specified with
49 // 'property' argument, in '_properties' object.
50 // property:
51 // A property name
52 // returns:
53 // A property value
54 return this._properties[property]; //anything
55 },
56
57 setPropertyValue: function(/*String*/property, /*anything*/value){
58 // summary:
59 // Store a property value
60 // description:
61 // This method stores 'value' as a property, specified with
62 // 'property' argument, in '_properties' object.
63 // property:
64 // A property name
65 // value:
66 // A property value
67 this._properties[property] = value;
68 }
69 });
70
71 dojo.declare("dojox.wire.ml.DataProperty", [dijit._Widget, dijit._Container], {
72 // summary:
73 // A widget to define a data property
74 // description:
75 // Attributes of this widget are used to add a property to the parent
76 // Data widget.
77 // 'type' attribute specifies one of "string", "number", "boolean",
78 // "array", "object" and "element" (DOM Element)
79 // (default to "string").
80 // If 'type' is "array" or "object", child DataProperty widgets are
81 // used to initialize the array elements or the object properties.
82 // name:
83 // A property name
84 // type:
85 // A property type name
86 // value:
87 // A property value
88 name: "",
89 type: "",
90 value: "",
91
92 _getValueAttr: function(){
93 return this.getValue();
94 },
95
96 getValue: function(){
97 // summary:
98 // Returns a property value
99 // description:
100 // If 'type' is specified, 'value' attribute is converted to
101 // the specified type and returned.
102 // Otherwise, 'value' attribute is returned as is.
103 // returns:
104 // A property value
105 var value = this.value;
106 if(this.type){
107 if(this.type == "number"){
108 value = parseInt(value);
109 }else if(this.type == "boolean"){
110 value = (value == "true");
111 }else if(this.type == "array"){
112 value = [];
113 var children = this.getChildren();
114 for(var i in children){
115 var child = children[i];
116 if(child instanceof dojox.wire.ml.DataProperty){
117 value.push(child.getValue());
118 }
119 }
120 }else if(this.type == "object"){
121 value = {};
122 var children = this.getChildren();
123 for(var i in children){
124 var child = children[i];
125 if((child instanceof dojox.wire.ml.DataProperty) && child.name){
126 value[child.name] = child.getValue();
127 }
128 }
129 }else if(this.type == "element"){
130 value = new dojox.wire.ml.XmlElement(value);
131 var children = this.getChildren();
132 for(var i in children){
133 var child = children[i];
134 if((child instanceof dojox.wire.ml.DataProperty) && child.name){
135 value.setPropertyValue(child.name, child.getValue());
136 }
137 }
138 }
139 }
140 return value; //anything
141 }
142 });