source: Dev/branches/rest-dojo-ui/client/dojox/wire/TextAdapter.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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