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