2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.wire.TextAdapter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.wire.TextAdapter"] = true;
|
|
|
3 |
dojo.provide("dojox.wire.TextAdapter");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.wire.CompositeWire");
|
|
|
6 |
|
|
|
7 |
dojo.declare("dojox.wire.TextAdapter", dojox.wire.CompositeWire, {
|
|
|
8 |
// summary:
|
|
|
9 |
// A composite Wire for a concatenated text
|
|
|
10 |
// description:
|
|
|
11 |
// This class has multiple child Wires for text segment values.
|
|
|
12 |
// Wires in 'segments' property are used to get text segments and
|
|
|
13 |
// values are concatenated with an optional delimiter string specified
|
|
|
14 |
// to 'delimiter' property.
|
|
|
15 |
|
|
|
16 |
_wireClass: "dojox.wire.TextAdapter",
|
|
|
17 |
|
|
|
18 |
constructor: function(/*Object*/args){
|
|
|
19 |
// summary:
|
|
|
20 |
// Initialize properties
|
|
|
21 |
// description:
|
|
|
22 |
// If array elements specified in 'segments' are not Wires, Wires
|
|
|
23 |
// are created from them as arguments, with 'parent' property set
|
|
|
24 |
// to this Wire instance.
|
|
|
25 |
// args:
|
|
|
26 |
// Arguments to initialize properties
|
|
|
27 |
// segments:
|
|
|
28 |
// An array containing child Wires for text segment values
|
|
|
29 |
// delimiter:
|
|
|
30 |
// A delimiter string
|
|
|
31 |
this._initializeChildren(this.segments);
|
|
|
32 |
if(!this.delimiter){
|
|
|
33 |
this.delimiter = "";
|
|
|
34 |
}
|
|
|
35 |
},
|
|
|
36 |
|
|
|
37 |
_getValue: function(/*Object||Array*/object){
|
|
|
38 |
// summary:
|
|
|
39 |
// Return a concatenated text
|
|
|
40 |
// description:
|
|
|
41 |
// This method calls getValue() method of the child Wires wuth
|
|
|
42 |
// 'object' argument and concatenate the values with 'delimiter'
|
|
|
43 |
// property to return.
|
|
|
44 |
// arg:
|
|
|
45 |
// A root object
|
|
|
46 |
// returns:
|
|
|
47 |
// A concatinated text
|
|
|
48 |
if(!object || !this.segments){
|
|
|
49 |
return object; //Object||Array
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
var text = "";
|
|
|
53 |
for(var i in this.segments){
|
|
|
54 |
var segment = this.segments[i].getValue(object);
|
|
|
55 |
text = this._addSegment(text, segment);
|
|
|
56 |
}
|
|
|
57 |
return text; //String
|
|
|
58 |
},
|
|
|
59 |
|
|
|
60 |
_setValue: function(/*Object||Array*/object, /*String*/value){
|
|
|
61 |
// summary:
|
|
|
62 |
// Not supported
|
|
|
63 |
throw new Error("Unsupported API: " + this._wireClass + "._setValue");
|
|
|
64 |
},
|
|
|
65 |
|
|
|
66 |
_addSegment: function(/*String*/text, /*String*/segment){
|
|
|
67 |
// summary:
|
|
|
68 |
// Return a concatenated text
|
|
|
69 |
// description:
|
|
|
70 |
// This method add a text segment specified to 'segment' argument
|
|
|
71 |
// to a base text specified to 'text', with 'delimiter' property.
|
|
|
72 |
// text:
|
|
|
73 |
// A base text
|
|
|
74 |
// segment:
|
|
|
75 |
// A text segment to add
|
|
|
76 |
// returns:
|
|
|
77 |
// A concatinated text
|
|
|
78 |
if(!segment){
|
|
|
79 |
return text; //String
|
|
|
80 |
}else if(!text){
|
|
|
81 |
return segment; //String
|
|
|
82 |
}else{
|
|
|
83 |
return text + this.delimiter + segment; //String
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
});
|
|
|
87 |
|
|
|
88 |
}
|