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