TextAdapter.js 2.4 KB

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