f7716d1dac784d7e6cced09e32216fe5f87e2d2b.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. if (!dojo._hasResource["dojox.wire.TextAdapter"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.wire.TextAdapter"] = true;
  6. dojo.provide("dojox.wire.TextAdapter");
  7. dojo.require("dojox.wire.CompositeWire");
  8. dojo.declare("dojox.wire.TextAdapter", dojox.wire.CompositeWire, {
  9. // summary:
  10. // A composite Wire for a concatenated text
  11. // description:
  12. // This class has multiple child Wires for text segment values.
  13. // Wires in 'segments' property are used to get text segments
  14. // and
  15. // values are concatenated with an optional delimiter string
  16. // specified
  17. // to 'delimiter' property.
  18. _wireClass : "dojox.wire.TextAdapter",
  19. constructor : function(/* Object */args) {
  20. // summary:
  21. // Initialize properties
  22. // description:
  23. // If array elements specified in 'segments' are not Wires,
  24. // Wires
  25. // are created from them as arguments, with 'parent'
  26. // property set
  27. // to this Wire instance.
  28. // args:
  29. // Arguments to initialize properties
  30. // segments:
  31. // An array containing child Wires for text segment values
  32. // delimiter:
  33. // A delimiter string
  34. this._initializeChildren(this.segments);
  35. if (!this.delimiter) {
  36. this.delimiter = "";
  37. }
  38. },
  39. _getValue : function(/* Object||Array */object) {
  40. // summary:
  41. // Return a concatenated text
  42. // description:
  43. // This method calls getValue() method of the child Wires
  44. // wuth
  45. // 'object' argument and concatenate the values with
  46. // 'delimiter'
  47. // property to return.
  48. // arg:
  49. // A root object
  50. // returns:
  51. // A concatinated text
  52. if (!object || !this.segments) {
  53. return object; // Object||Array
  54. }
  55. var text = "";
  56. for (var i in this.segments) {
  57. var segment = this.segments[i].getValue(object);
  58. text = this._addSegment(text, segment);
  59. }
  60. return text; // String
  61. },
  62. _setValue : function(/* Object||Array */object, /* String */value) {
  63. // summary:
  64. // Not supported
  65. throw new Error("Unsupported API: " + this._wireClass
  66. + "._setValue");
  67. },
  68. _addSegment : function(/* String */text, /* String */segment) {
  69. // summary:
  70. // Return a concatenated text
  71. // description:
  72. // This method add a text segment specified to 'segment'
  73. // argument
  74. // to a base text specified to 'text', with 'delimiter'
  75. // property.
  76. // text:
  77. // A base text
  78. // segment:
  79. // A text segment to add
  80. // returns:
  81. // A concatinated text
  82. if (!segment) {
  83. return text; // String
  84. } else if (!text) {
  85. return segment; // String
  86. } else {
  87. return text + this.delimiter + segment; // String
  88. }
  89. }
  90. });
  91. }