TableAdapter.js 3.1 KB

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