TextAdapter.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.wire.TextAdapter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.wire.TextAdapter"] = true;
  8. dojo.provide("dojox.wire.TextAdapter");
  9. dojo.require("dojox.wire.CompositeWire");
  10. dojo.declare("dojox.wire.TextAdapter", dojox.wire.CompositeWire, {
  11. // summary:
  12. // A composite Wire for a concatenated text
  13. // description:
  14. // This class has multiple child Wires for text segment values.
  15. // Wires in 'segments' property are used to get text segments and
  16. // values are concatenated with an optional delimiter string 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, Wires
  24. // are created from them as arguments, with 'parent' property set
  25. // to this Wire instance.
  26. // args:
  27. // Arguments to initialize properties
  28. // segments:
  29. // An array containing child Wires for text segment values
  30. // delimiter:
  31. // A delimiter string
  32. this._initializeChildren(this.segments);
  33. if(!this.delimiter){
  34. this.delimiter = "";
  35. }
  36. },
  37. _getValue: function(/*Object||Array*/object){
  38. // summary:
  39. // Return a concatenated text
  40. // description:
  41. // This method calls getValue() method of the child Wires wuth
  42. // 'object' argument and concatenate the values with 'delimiter'
  43. // property to return.
  44. // arg:
  45. // A root object
  46. // returns:
  47. // A concatinated text
  48. if(!object || !this.segments){
  49. return object; //Object||Array
  50. }
  51. var text = "";
  52. for(var i in this.segments){
  53. var segment = this.segments[i].getValue(object);
  54. text = this._addSegment(text, segment);
  55. }
  56. return text; //String
  57. },
  58. _setValue: function(/*Object||Array*/object, /*String*/value){
  59. // summary:
  60. // Not supported
  61. throw new Error("Unsupported API: " + this._wireClass + "._setValue");
  62. },
  63. _addSegment: function(/*String*/text, /*String*/segment){
  64. // summary:
  65. // Return a concatenated text
  66. // description:
  67. // This method add a text segment specified to 'segment' argument
  68. // to a base text specified to 'text', with 'delimiter' property.
  69. // text:
  70. // A base text
  71. // segment:
  72. // A text segment to add
  73. // returns:
  74. // A concatinated text
  75. if(!segment){
  76. return text; //String
  77. }else if(!text){
  78. return segment; //String
  79. }else{
  80. return text + this.delimiter + segment; //String
  81. }
  82. }
  83. });
  84. }