CompositeWire.js 3.1 KB

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