| 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 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
startup: function(){ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
this._initializeProperties(); |
| 21 |
}, |
| 22 |
|
| 23 |
_initializeProperties: function(reset){ |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 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(property){ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
return this._properties[property]; |
| 55 |
}, |
| 56 |
|
| 57 |
setPropertyValue: function(property, value){ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
this._properties[property] = value; |
| 68 |
} |
| 69 |
}); |
| 70 |
|
| 71 |
dojo.declare("dojox.wire.ml.DataProperty", [dijit._Widget, dijit._Container], { |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
name: "", |
| 89 |
type: "", |
| 90 |
value: "", |
| 91 |
|
| 92 |
_getValueAttr: function(){ |
| 93 |
return this.getValue(); |
| 94 |
}, |
| 95 |
|
| 96 |
getValue: function(){ |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 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; |
| 141 |
} |
| 142 |
}); |