Transfer.js 12 KB

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