| | 1 | dojo.provide("dojox.wireml.Transfer"); |
| | 2 | dojo.provide("dojox.wireml.ChildWire"); |
| | 3 | dojo.provide("dojox.wireml.ColumnWire"); |
| | 4 | dojo.provide("dojox.wireml.NodeWire"); |
| | 5 | dojo.provide("dojox.wireml.SegmentWire"); |
| | 6 | |
| | 7 | dojo.require("dijit.base.Widget"); |
| | 8 | dojo.require("dijit.base.Container"); |
| | 9 | dojo.require("dojox.wire.common"); |
| | 10 | dojo.require("dojox.wireml.Action"); |
| | 11 | |
| | 12 | dojo.declare("dojox.wireml.Transfer", |
| | 13 | dojox.wireml.Action, { |
| | 14 | // summary: |
| | 15 | // A widget to transfer values through source and target Wires |
| | 16 | // description: |
| | 17 | // This widget represents a controller task to transfer a value from |
| | 18 | // a source to a target, through a source and a target Wires, when |
| | 19 | // an event (a function) or a topic is issued. |
| | 20 | // If this widget has child ChildWire widgets, their _addWire() |
| | 21 | // methods are called to add Wire arguments to a source or a target |
| | 22 | // Wire. |
| | 23 | // source: |
| | 24 | // A source object and/or property |
| | 25 | // sourceStore: |
| | 26 | // A data store for a source data item |
| | 27 | // sourceAttribute: |
| | 28 | // An attribute of a source data item |
| | 29 | // sourcePath: |
| | 30 | // A simplified XPath to a source property of an XML element |
| | 31 | // type: |
| | 32 | // A type of the value to be transferred |
| | 33 | // converter: |
| | 34 | // A class name of a converter for the value to be transferred |
| | 35 | // target: |
| | 36 | // A target object and/or property |
| | 37 | // targetStore: |
| | 38 | // A data store for a target data item |
| | 39 | // targetAttribute: |
| | 40 | // An attribute of a target data item |
| | 41 | // targetPath: |
| | 42 | // A simplified XPath to a target property of an XML element |
| | 43 | source: "", |
| | 44 | sourceStore: "", |
| | 45 | sourceAttribute: "", |
| | 46 | sourcePath: "", |
| | 47 | type: "", |
| | 48 | converter: "", |
| | 49 | delimiter: "", |
| | 50 | target: "", |
| | 51 | targetStore: "", |
| | 52 | targetAttribute: "", |
| | 53 | targetPath: "", |
| | 54 | |
| | 55 | _run: function(){ |
| | 56 | // summary: |
| | 57 | // Transfer a value from a source to a target |
| | 58 | // description: |
| | 59 | // First, Wires for a source and a target are created from attributes. |
| | 60 | // Then, a value is obtained by getValue() of the source Wire is set |
| | 61 | // by setValue() of the target Wire. |
| | 62 | // The arguments to this method is passed to getValue() and setValue() |
| | 63 | // of Wires, so that they can be used to identify the root objects off |
| | 64 | // the arguments. |
| | 65 | var sourceWire = this._getWire("source"); |
| | 66 | var targetWire = this._getWire("target"); |
| | 67 | dojox.wire.transfer(sourceWire, targetWire, arguments); |
| | 68 | }, |
| | 69 | |
| | 70 | _getWire: function(/*String*/which){ |
| | 71 | // summary: |
| | 72 | // Build Wire arguments from attributes |
| | 73 | // description: |
| | 74 | // Arguments object for a source or a target Wire, specified by |
| | 75 | // 'which' argument, are build from corresponding attributes, |
| | 76 | // including '*Store' (for 'dataStore'), '*Attribute' |
| | 77 | // (for 'attribute), '*Path' (for 'path'), 'type' and 'converter'. |
| | 78 | // 'source' or 'target' attribute is parsed as: |
| | 79 | // "object_id.property_name[.sub_property_name...]" |
| | 80 | // If 'source' or 'target' starts with "arguments", 'object' |
| | 81 | // argument for a Wire is set to null, so that the root object is |
| | 82 | // given as an event or topic arguments. |
| | 83 | // If this widget has child ChildWire widgets with a corresponding |
| | 84 | // 'which' attribute, their _addWire() methods are called to add |
| | 85 | // additional Wire arguments and nested Wire is created, |
| | 86 | // specifying the Wire defined by this widget to 'object' argument. |
| | 87 | // which: |
| | 88 | // Which Wire arguments to build, "source" or "target" |
| | 89 | // returns: |
| | 90 | // Wire arguments object |
| | 91 | var args = undefined; |
| | 92 | if(which == "source"){ |
| | 93 | args = { |
| | 94 | object: this.source, |
| | 95 | dataStore: this.sourceStore, |
| | 96 | attribute: this.sourceAttribute, |
| | 97 | path: this.sourcePath, |
| | 98 | type: this.type, |
| | 99 | converter: this.converter |
| | 100 | }; |
| | 101 | }else{ // "target" |
| | 102 | args = { |
| | 103 | object: this.target, |
| | 104 | dataStore: this.targetStore, |
| | 105 | attribute: this.targetAttribute, |
| | 106 | path: this.targetPath |
| | 107 | }; |
| | 108 | } |
| | 109 | if(args.object){ |
| | 110 | if(args.object.length >= 9 && args.object.substring(0, 9) == "arguments"){ |
| | 111 | args.property = args.object.substring(9); |
| | 112 | args.object = null; |
| | 113 | }else{ |
| | 114 | var i = args.object.indexOf('.'); |
| | 115 | if(i < 0){ |
| | 116 | args.object = dojox.wireml._getValue(args.object); |
| | 117 | }else{ |
| | 118 | args.property = args.object.substring(i + 1); |
| | 119 | args.object = dojox.wireml._getValue(args.object.substring(0, i)); |
| | 120 | } |
| | 121 | } |
| | 122 | } |
| | 123 | if(args.dataStore){ |
| | 124 | args.dataStore = dojox.wireml._getValue(args.dataStore); |
| | 125 | } |
| | 126 | var childArgs = undefined; |
| | 127 | var children = this.getChildren(); |
| | 128 | for(var i in children){ |
| | 129 | var child = children[i]; |
| | 130 | if(child instanceof dojox.wireml.ChildWire && child.which == which){ |
| | 131 | if(!childArgs){ |
| | 132 | childArgs = {}; |
| | 133 | } |
| | 134 | child._addWire(this, childArgs); |
| | 135 | } |
| | 136 | } |
| | 137 | if(childArgs){ // make nested Wires |
| | 138 | childArgs.object = dojox.wire.create(args); |
| | 139 | childArgs.dataStore = args.dataStore; |
| | 140 | args = childArgs; |
| | 141 | } |
| | 142 | return args; //Object |
| | 143 | } |
| | 144 | }); |
| | 145 | |
| | 146 | dojo.declare("dojox.wireml.ChildWire", |
| | 147 | dijit.base.Widget, { |
| | 148 | // summary: |
| | 149 | // A widget to add a child wire |
| | 150 | // description: |
| | 151 | // Attributes of this widget are used to add a child Wire to |
| | 152 | // a composite Wire of the parent Transfer widget. |
| | 153 | // which: |
| | 154 | // Which Wire to add a child Wire, "source" or "target", default to |
| | 155 | // "source" |
| | 156 | // object: |
| | 157 | // A root object for the value |
| | 158 | // property: |
| | 159 | // A property for the value |
| | 160 | // type: |
| | 161 | // A type of the value |
| | 162 | // converter: |
| | 163 | // A class name of a converter for the value |
| | 164 | // attribute: |
| | 165 | // A data item attribute for the value |
| | 166 | // path: |
| | 167 | // A simplified XPath for the value |
| | 168 | // name: |
| | 169 | // A composite property name |
| | 170 | which: "source", |
| | 171 | object: "", |
| | 172 | property: "", |
| | 173 | type: "", |
| | 174 | converter: "", |
| | 175 | attribute: "", |
| | 176 | path: "", |
| | 177 | name: "", |
| | 178 | |
| | 179 | _addWire: function(/*Transfer*/parent, /*Object*/args){ |
| | 180 | // summary: |
| | 181 | // Add a child Wire to Wire arguments |
| | 182 | // description: |
| | 183 | // If 'name' attribute is specified, a child Wire is added as |
| | 184 | // the named property of 'children' object of 'args'. |
| | 185 | // Otherwise, a child Wire is added to 'children' array of 'args'. |
| | 186 | // parent: |
| | 187 | // A parent Transfer widget |
| | 188 | // args: |
| | 189 | // Wire arguments |
| | 190 | if(this.name){ // object |
| | 191 | if(!args.children){ |
| | 192 | args.children = {}; |
| | 193 | } |
| | 194 | args.children[this.name] = this._getWire(parent); |
| | 195 | }else{ // array |
| | 196 | if(!args.children){ |
| | 197 | args.children = []; |
| | 198 | } |
| | 199 | args.children.push(this._getWire(parent)); |
| | 200 | } |
| | 201 | }, |
| | 202 | |
| | 203 | _getWire: function(/*Transfer*/parent){ |
| | 204 | // summary: |
| | 205 | // Build child Wire arguments from attributes |
| | 206 | // description: |
| | 207 | // Arguments object for a child Wire are build from attributes, |
| | 208 | // including 'object', 'property', 'type', 'converter', |
| | 209 | // 'attribute' and 'path'. |
| | 210 | // parent: |
| | 211 | // A parent Transfer widget |
| | 212 | // returns: |
| | 213 | // Wire arguments object |
| | 214 | return { |
| | 215 | object: (this.object ? dojox.wireml._getValue(this.object) : undefined), |
| | 216 | property: this.property, |
| | 217 | type: this.type, |
| | 218 | converter: this.converter, |
| | 219 | attribute: this.attribute, |
| | 220 | path: this.path |
| | 221 | }; //Object |
| | 222 | } |
| | 223 | }); |
| | 224 | |
| | 225 | dojo.declare("dojox.wireml.ColumnWire", |
| | 226 | dojox.wireml.ChildWire, { |
| | 227 | // summary: |
| | 228 | // A widget to add a column wire |
| | 229 | // description: |
| | 230 | // Attributes of this widget are used to add a column Wire to |
| | 231 | // a TableAdapter of the parent Transfer widget. |
| | 232 | // column: |
| | 233 | // A column name |
| | 234 | column: "", |
| | 235 | |
| | 236 | _addWire: function(/*Transfer*/parent, /*Object*/args){ |
| | 237 | // summary: |
| | 238 | // Add a column Wire to Wire arguments |
| | 239 | // description: |
| | 240 | // If 'column' attribute is specified, a column Wire is added as |
| | 241 | // the named property of 'columns' object of 'args'. |
| | 242 | // Otherwise, a column Wire is added to 'columns' array of 'args'. |
| | 243 | // parent: |
| | 244 | // A parent Transfer widget |
| | 245 | // args: |
| | 246 | // Wire arguments |
| | 247 | if(this.column){ // object |
| | 248 | if(!args.columns){ |
| | 249 | args.columns = {}; |
| | 250 | } |
| | 251 | args.columns[this.column] = this._getWire(parent); |
| | 252 | }else{ // array |
| | 253 | if(!args.columns){ |
| | 254 | args.columns = []; |
| | 255 | } |
| | 256 | args.columns.push(this._getWire(parent)); |
| | 257 | } |
| | 258 | } |
| | 259 | }); |
| | 260 | |
| | 261 | dojo.declare("dojox.wireml.NodeWire", |
| | 262 | [dojox.wireml.ChildWire, dijit.base.Container], { |
| | 263 | // summary: |
| | 264 | // A widget to add node wires |
| | 265 | // description: |
| | 266 | // Attributes of this widget are used to add node Wires to |
| | 267 | // a TreeAdapter of the parent Transfer widget. |
| | 268 | // titleProperty: |
| | 269 | // A property for the node title |
| | 270 | // titleAttribute: |
| | 271 | // A data item attribute for the node title |
| | 272 | // titlePath: |
| | 273 | // A simplified XPath for the node title |
| | 274 | titleProperty: "", |
| | 275 | titleAttribute: "", |
| | 276 | titlePath: "", |
| | 277 | |
| | 278 | _addWire: function(/*Transfer*/parent, /*Object*/args){ |
| | 279 | // summary: |
| | 280 | // Add node Wires to Wire arguments |
| | 281 | // description: |
| | 282 | // Node Wires are added to 'nodes' array of 'args'. |
| | 283 | // parent: |
| | 284 | // A parent Transfer widget |
| | 285 | // args: |
| | 286 | // Wire arguments |
| | 287 | if(!args.nodes){ |
| | 288 | args.nodes = []; |
| | 289 | } |
| | 290 | args.nodes.push(this._getWires(parent)); |
| | 291 | }, |
| | 292 | |
| | 293 | _getWires: function(/*Transfer*/parent){ |
| | 294 | // summary: |
| | 295 | // Build node Wires arguments from attributes |
| | 296 | // description: |
| | 297 | // Arguments object for 'node' Wire are build from attributes, |
| | 298 | // including 'object', 'property', 'type', 'converter', |
| | 299 | // 'attribute' and 'path'. |
| | 300 | // Arguments object for 'title' Wire are build from another set of |
| | 301 | // attributes, 'titleProperty', 'titleAttribute' and 'titlePath'. |
| | 302 | // If this widget has child NodeWire widgets, their _getWires() |
| | 303 | // methods are called recursively to build 'children' array of |
| | 304 | // 'args'. |
| | 305 | // parent: |
| | 306 | // A parent Transfer widget |
| | 307 | // returns: |
| | 308 | // Wire arguments object |
| | 309 | var args = { |
| | 310 | node: this._getWire(parent), |
| | 311 | title: { |
| | 312 | type: "string", |
| | 313 | property: this.titleProperty, |
| | 314 | attribute: this.titleAttribute, |
| | 315 | path: this.titlePath |
| | 316 | } |
| | 317 | }; |
| | 318 | var childArgs = []; |
| | 319 | var children = this.getChildren(); |
| | 320 | for(var i in children){ |
| | 321 | var child = children[i]; |
| | 322 | if(child instanceof dojox.wireml.NodeWire){ |
| | 323 | childArgs.push(child._getWires(parent)); |
| | 324 | } |
| | 325 | } |
| | 326 | if(childArgs.length > 0){ |
| | 327 | args.children = childArgs; |
| | 328 | } |
| | 329 | return args; //Object |
| | 330 | } |
| | 331 | }); |
| | 332 | |
| | 333 | dojo.declare("dojox.wireml.SegmentWire", |
| | 334 | dojox.wireml.ChildWire, { |
| | 335 | // summary: |
| | 336 | // A widget to add a segment wire |
| | 337 | // description: |
| | 338 | // Attributes of this widget are used to add a segment Wire to |
| | 339 | // a TextAdapter of the parent Transfer widget. |
| | 340 | |
| | 341 | _addWire: function(/*Transfer*/parent, /*Object*/args){ |
| | 342 | // summary: |
| | 343 | // Add a segument Wire to Wire arguments |
| | 344 | // description: |
| | 345 | // A segment Wire is added to 'segments' array of 'args'. |
| | 346 | // If 'parent' has 'delimiter' attribute, it is used for |
| | 347 | // 'delimiter' property of 'args'. |
| | 348 | // parent: |
| | 349 | // A parent Transfer widget |
| | 350 | // args: |
| | 351 | // Wire arguments |
| | 352 | if(!args.segments){ |
| | 353 | args.segments = []; |
| | 354 | } |
| | 355 | args.segments.push(this._getWire(parent)); |
| | 356 | if(parent.delimiter && !args.delimiter){ |
| | 357 | args.delimiter = parent.delimiter; |
| | 358 | } |
| | 359 | } |
| | 360 | }); |