TableAdapter.js 2.7 KB

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