1758560e567fcf267c423600a79fa5f8eb46aa8b.svn-base 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. if (!dojo._hasResource["dojox.wire.ml.Data"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojox.wire.ml.Data"] = true;
  6. dojo.provide("dojox.wire.ml.Data");
  7. dojo.provide("dojox.wire.ml.DataProperty");
  8. dojo.require("dijit._Widget");
  9. dojo.require("dijit._Container");
  10. dojo.require("dojox.wire.ml.util");
  11. dojo.declare("dojox.wire.ml.Data", [dijit._Widget, dijit._Container], {
  12. // summary:
  13. // A widget for a data object
  14. // description:
  15. // This widget represents an object with '_properties' property.
  16. // If child 'DataProperty' widgets exist, they are used to initialize
  17. // propertiy values of '_properties' object.
  18. startup : function() {
  19. // summary:
  20. // Call _initializeProperties()
  21. // description:
  22. // See _initializeProperties().
  23. this._initializeProperties();
  24. },
  25. _initializeProperties : function(/* Boolean */reset) {
  26. // summary:
  27. // Initialize a data object
  28. // description:
  29. // If this widget has child DataProperty widgets, their getValue()
  30. // methods are called and set the return value to a property
  31. // specified by 'name' attribute of the child widgets.
  32. // reset:
  33. // A boolean to reset current properties
  34. if (!this._properties || reset) {
  35. this._properties = {};
  36. }
  37. var children = this.getChildren();
  38. for (var i in children) {
  39. var child = children[i];
  40. if ((child instanceof dojox.wire.ml.DataProperty) && child.name) {
  41. this.setPropertyValue(child.name, child.getValue());
  42. }
  43. }
  44. },
  45. getPropertyValue : function(/* String */property) {
  46. // summary:
  47. // Return a property value
  48. // description:
  49. // This method returns the value of a property, specified with
  50. // 'property' argument, in '_properties' object.
  51. // property:
  52. // A property name
  53. // returns:
  54. // A property value
  55. return this._properties[property]; // anything
  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. dojo.declare("dojox.wire.ml.DataProperty",
  71. [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
  76. // parent
  77. // Data widget.
  78. // 'type' attribute specifies one of "string", "number",
  79. // "boolean",
  80. // "array", "object" and "element" (DOM Element)
  81. // (default to "string").
  82. // If 'type' is "array" or "object", child DataProperty widgets
  83. // are
  84. // used to initialize the array elements or the object
  85. // properties.
  86. // name:
  87. // A property name
  88. // type:
  89. // A property type name
  90. // value:
  91. // A property value
  92. name : "",
  93. type : "",
  94. value : "",
  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)
  125. && 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)
  135. && child.name) {
  136. value.setPropertyValue(child.name, child
  137. .getValue());
  138. }
  139. }
  140. }
  141. }
  142. return value; // anything
  143. }
  144. });
  145. }