7baecdaaf47e5fc075f880f22d28f5496750fda2.svn-base 3.3 KB

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