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