Transfer.js 10 KB

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