2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.wire._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.wire._base"] = true;
|
|
|
3 |
dojo.provide("dojox.wire._base");
|
|
|
4 |
|
|
|
5 |
dojox.wire._defaultWireClass = "dojox.wire.Wire";
|
|
|
6 |
|
|
|
7 |
dojox.wire._wireClasses = {
|
|
|
8 |
"attribute": "dojox.wire.DataWire",
|
|
|
9 |
"path": "dojox.wire.XmlWire",
|
|
|
10 |
"children": "dojox.wire.CompositeWire",
|
|
|
11 |
"columns": "dojox.wire.TableAdapter",
|
|
|
12 |
"nodes": "dojox.wire.TreeAdapter",
|
|
|
13 |
"segments": "dojox.wire.TextAdapter"
|
|
|
14 |
};
|
|
|
15 |
|
|
|
16 |
dojox.wire.register = function(/*Function||String*/wireClass, /*String*/key){
|
|
|
17 |
// summary:
|
|
|
18 |
// Register a Wire class
|
|
|
19 |
// desription:
|
|
|
20 |
// The specified Wire class or a class name is registered with
|
|
|
21 |
// a key property of arguments to create a Wire
|
|
|
22 |
// wireClass:
|
|
|
23 |
// A class or full qualified class name
|
|
|
24 |
// key:
|
|
|
25 |
// A key property of arguments to create a Wire
|
|
|
26 |
if(!wireClass || !key){
|
|
|
27 |
return; //undefined
|
|
|
28 |
}
|
|
|
29 |
if(dojox.wire._wireClasses[key]){ // key already in use
|
|
|
30 |
return; //undefined
|
|
|
31 |
}
|
|
|
32 |
dojox.wire._wireClasses[key] = wireClass;
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
dojox.wire._getClass = function(/*String*/name){
|
|
|
36 |
// summary:
|
|
|
37 |
// Returns a class
|
|
|
38 |
// description:
|
|
|
39 |
// The class is loaded by dojo.require() and returned
|
|
|
40 |
// by dojo.getObject().
|
|
|
41 |
// name:
|
|
|
42 |
// A class name
|
|
|
43 |
// returns:
|
|
|
44 |
// A class
|
|
|
45 |
dojo["require"](name); // use dojo["require"] instead of dojo.require to avoid a build problem
|
|
|
46 |
return dojo.getObject(name); //Function
|
|
|
47 |
};
|
|
|
48 |
|
|
|
49 |
dojox.wire.create = function(/*Object*/args){
|
|
|
50 |
// summary:
|
|
|
51 |
// Create a Wire from arguments
|
|
|
52 |
// description:
|
|
|
53 |
// If 'args' specifies 'wireClass', it is used as a class or full
|
|
|
54 |
// qualified class name to create a Wire with 'args' as arguments.
|
|
|
55 |
// Otherwise, a Wire class is determined by other proeprties of 'args'
|
|
|
56 |
// checking if 'args' specifies a key property for a Wire class.
|
|
|
57 |
// If no key property found, the default Wire class is used.
|
|
|
58 |
// args:
|
|
|
59 |
// Arguments to create a Wire
|
|
|
60 |
// returns:
|
|
|
61 |
// A Wire
|
|
|
62 |
if(!args){
|
|
|
63 |
args = {};
|
|
|
64 |
}
|
|
|
65 |
var wireClass = args.wireClass;
|
|
|
66 |
if(wireClass){
|
|
|
67 |
if(dojo.isString(wireClass)){
|
|
|
68 |
wireClass = dojox.wire._getClass(wireClass);
|
|
|
69 |
}
|
|
|
70 |
}else{
|
|
|
71 |
for(var key in args){
|
|
|
72 |
if(!args[key]){
|
|
|
73 |
continue;
|
|
|
74 |
}
|
|
|
75 |
wireClass = dojox.wire._wireClasses[key];
|
|
|
76 |
if(wireClass){
|
|
|
77 |
if(dojo.isString(wireClass)){
|
|
|
78 |
wireClass = dojox.wire._getClass(wireClass);
|
|
|
79 |
dojox.wire._wireClasses[key] = wireClass;
|
|
|
80 |
}
|
|
|
81 |
break;
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
if(!wireClass){
|
|
|
86 |
if(dojo.isString(dojox.wire._defaultWireClass)){
|
|
|
87 |
dojox.wire._defaultWireClass = dojox.wire._getClass(dojox.wire._defaultWireClass);
|
|
|
88 |
}
|
|
|
89 |
wireClass = dojox.wire._defaultWireClass;
|
|
|
90 |
}
|
|
|
91 |
return new wireClass(args); //Object
|
|
|
92 |
};
|
|
|
93 |
|
|
|
94 |
dojox.wire.isWire = function(/*Object*/wire){
|
|
|
95 |
// summary:
|
|
|
96 |
// Check if an object is a Wire
|
|
|
97 |
// description:
|
|
|
98 |
// If the specified object is a Wire, true is returned.
|
|
|
99 |
// Otherwise, false is returned.
|
|
|
100 |
// wire:
|
|
|
101 |
// An object to check
|
|
|
102 |
// returns:
|
|
|
103 |
// True if the object is a Wire, otherwise false
|
|
|
104 |
return (wire && wire._wireClass); //Boolean
|
|
|
105 |
};
|
|
|
106 |
|
|
|
107 |
dojox.wire.transfer = function(/*Wire||Object*/source, /*Wire||Object*/target, /*Object?*/defaultObject, /*Object?*/defaultTargetObject){
|
|
|
108 |
// summary:
|
|
|
109 |
// Transfer a source value to a target value
|
|
|
110 |
// description:
|
|
|
111 |
// If 'source' and/or 'target' are not Wires, Wires are created with
|
|
|
112 |
// them as arguments.
|
|
|
113 |
// A value is got through the source Wire and set through the target
|
|
|
114 |
// Wire.
|
|
|
115 |
// 'defaultObject' is passed to Wires as a default root object.
|
|
|
116 |
// If 'defaultTargetObject' is specified, it is passed to the target
|
|
|
117 |
// Wire as a default root object, instead of 'defaultObject'.
|
|
|
118 |
// source:
|
|
|
119 |
// A Wire or arguments to create a Wire for a source value
|
|
|
120 |
// target:
|
|
|
121 |
// A Wire or arguments to create a Wire for a target value
|
|
|
122 |
// defaultObject:
|
|
|
123 |
// defaultTargetObject;
|
|
|
124 |
// Optional default root objects passed to Wires
|
|
|
125 |
if(!source || !target){
|
|
|
126 |
return; //undefined
|
|
|
127 |
}
|
|
|
128 |
if(!dojox.wire.isWire(source)){
|
|
|
129 |
source = dojox.wire.create(source);
|
|
|
130 |
}
|
|
|
131 |
if(!dojox.wire.isWire(target)){
|
|
|
132 |
target = dojox.wire.create(target);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
var value = source.getValue(defaultObject);
|
|
|
136 |
target.setValue(value, (defaultTargetObject || defaultObject));
|
|
|
137 |
};
|
|
|
138 |
|
|
|
139 |
dojox.wire.connect = function(/*Object*/trigger, /*Wire||Object*/source, /*Wire||Object*/target){
|
|
|
140 |
// summary:
|
|
|
141 |
// Transfer a source value to a target value on a trigger event or
|
|
|
142 |
// topic
|
|
|
143 |
// description:
|
|
|
144 |
// If 'trigger' specifies 'topic', the topic is subscribed to transer
|
|
|
145 |
// a value on the topic.
|
|
|
146 |
// Otherwise, the event specified to 'event' of 'trigger' is listened
|
|
|
147 |
// to transfer a value.
|
|
|
148 |
// On the specified event or topic, transfer() is called with
|
|
|
149 |
// 'source', 'target' and the arguments of the event or topic (as
|
|
|
150 |
// default root objects).
|
|
|
151 |
// trigger:
|
|
|
152 |
// An event or topic to trigger a transfer
|
|
|
153 |
// source:
|
|
|
154 |
// A Wire or arguments to create a Wire for a source value
|
|
|
155 |
// target:
|
|
|
156 |
// A Wire or arguments to create a Wire for a target value
|
|
|
157 |
// returns:
|
|
|
158 |
// A connection handle for disconnect()
|
|
|
159 |
if(!trigger || !source || !target){
|
|
|
160 |
return; //undefined
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
var connection = {topic: trigger.topic};
|
|
|
164 |
if(trigger.topic){
|
|
|
165 |
connection.handle = dojo.subscribe(trigger.topic, function(){
|
|
|
166 |
dojox.wire.transfer(source, target, arguments);
|
|
|
167 |
});
|
|
|
168 |
}else if(trigger.event){
|
|
|
169 |
connection.handle = dojo.connect(trigger.scope, trigger.event, function(){
|
|
|
170 |
dojox.wire.transfer(source, target, arguments);
|
|
|
171 |
});
|
|
|
172 |
}
|
|
|
173 |
return connection; //Object
|
|
|
174 |
};
|
|
|
175 |
|
|
|
176 |
dojox.wire.disconnect = function(/*Object*/connection){
|
|
|
177 |
// summary:
|
|
|
178 |
// Remove a connection or subscription for transfer
|
|
|
179 |
// description:
|
|
|
180 |
// If 'handle' has 'topic', the topic is unsubscribed.
|
|
|
181 |
// Otherwise, the listener to an event is removed.
|
|
|
182 |
// connection:
|
|
|
183 |
// A connection handle returned by connect()
|
|
|
184 |
if(!connection || !connection.handle){
|
|
|
185 |
return; //undefined
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
if(connection.topic){
|
|
|
189 |
dojo.unsubscribe(connection.handle);
|
|
|
190 |
}else{
|
|
|
191 |
dojo.disconnect(connection.handle);
|
|
|
192 |
}
|
|
|
193 |
};
|
|
|
194 |
|
|
|
195 |
}
|