[483] | 1 | dojo.provide("dojox.wire.TableAdapter"); |
---|
| 2 | |
---|
| 3 | dojo.require("dojox.wire.CompositeWire"); |
---|
| 4 | |
---|
| 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 | |
---|
| 19 | _wireClass: "dojox.wire.TableAdapter", |
---|
| 20 | |
---|
| 21 | constructor: function(/*Object*/ args){ |
---|
| 22 | // summary: |
---|
| 23 | // Initialize properties |
---|
| 24 | // description: |
---|
| 25 | // If object properties or array elements specified in 'columns' |
---|
| 26 | // property are not Wires, Wires are created from them as |
---|
| 27 | // arguments, with 'parent' property set to this Wire instance. |
---|
| 28 | // args: |
---|
| 29 | // Arguments to initialize properties: |
---|
| 30 | // |
---|
| 31 | // - columns: An object or array containing child Wires for column values |
---|
| 32 | this._initializeChildren(this.columns); |
---|
| 33 | }, |
---|
| 34 | |
---|
| 35 | _getValue: function(/*Array*/object){ |
---|
| 36 | // summary: |
---|
| 37 | // Return an array of table row value (object or array) |
---|
| 38 | // description: |
---|
| 39 | // This method iterates over an array specified to 'object' |
---|
| 40 | // argument and calls getValue() method of the child Wires with |
---|
| 41 | // each element of the array to get a row object or array. |
---|
| 42 | // Finally, an array with the row objects or arrays are retuned. |
---|
| 43 | // object: |
---|
| 44 | // A root array |
---|
| 45 | // returns: |
---|
| 46 | // An array of table row value |
---|
| 47 | if(!object || !this.columns){ |
---|
| 48 | return object; //Array |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | var array = object; |
---|
| 52 | if(!dojo.isArray(array)){ |
---|
| 53 | array = [array]; |
---|
| 54 | } |
---|
| 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 | |
---|
| 64 | _setValue: function(/*Array*/object, /*Array*/value){ |
---|
| 65 | // summary: |
---|
| 66 | // Not supported |
---|
| 67 | throw new Error("Unsupported API: " + this._wireClass + "._setValue"); |
---|
| 68 | }, |
---|
| 69 | |
---|
| 70 | _getRow: function(/*Object||Array*/object){ |
---|
| 71 | // summary: |
---|
| 72 | // Return an array or object for a table row |
---|
| 73 | // description: |
---|
| 74 | // This method calls getValue() method of the child Wires to |
---|
| 75 | // create a row object or array. |
---|
| 76 | // returns: |
---|
| 77 | // An array or object for a table row |
---|
| 78 | var row = (dojo.isArray(this.columns) ? [] : {}); // array or object |
---|
| 79 | for(var c in this.columns){ |
---|
| 80 | row[c] = this.columns[c].getValue(object); |
---|
| 81 | } |
---|
| 82 | return row; //Array||Object |
---|
| 83 | } |
---|
| 84 | }); |
---|