DFUWUDetailsWidget.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "exports",
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/i18n",
  21. "dojo/i18n!./nls/common",
  22. "dojo/i18n!./nls/DFUWUDetailsWidget",
  23. "dojo/_base/array",
  24. "dojo/dom",
  25. "dojo/dom-attr",
  26. "dojo/dom-class",
  27. "dojo/dom-style",
  28. "dojo/query",
  29. "dijit/layout/BorderContainer",
  30. "dijit/layout/TabContainer",
  31. "dijit/layout/ContentPane",
  32. "dijit/Toolbar",
  33. "dijit/form/Textarea",
  34. "dijit/TitlePane",
  35. "dijit/registry",
  36. "dijit/ProgressBar",
  37. "hpcc/_TabContainerWidget",
  38. "hpcc/FileSpray",
  39. "hpcc/ESPDFUWorkunit",
  40. "hpcc/ECLSourceWidget",
  41. "hpcc/LFDetailsWidget",
  42. "dojo/text!../templates/DFUWUDetailsWidget.html"
  43. ], function (exports, declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, dom, domAttr, domClass, domStyle, query,
  44. BorderContainer, TabContainer, ContentPane, Toolbar, Textarea, TitlePane, registry, ProgressBar,
  45. _TabContainerWidget, FileSpray, ESPDFUWorkunit, ECLSourceWidget, LFDetailsWidget,
  46. template) {
  47. exports.fixCircularDependency = declare("DFUWUDetailsWidget", [_TabContainerWidget], {
  48. templateString: template,
  49. baseClass: "DFUWUDetailsWidget",
  50. i18n: lang.mixin(nlsCommon, nlsSpecific),
  51. summaryWidget: null,
  52. xmlWidget: null,
  53. wu: null,
  54. loaded: false,
  55. buildRendering: function (args) {
  56. this.inherited(arguments);
  57. },
  58. postCreate: function (args) {
  59. this.inherited(arguments);
  60. this.summaryWidget = registry.byId(this.id + "_Summary");
  61. this.xmlWidget = registry.byId(this.id + "_XML");
  62. var stateOptions = [];
  63. for (var key in FileSpray.States) {
  64. stateOptions.push({
  65. label: FileSpray.States[key],
  66. value: FileSpray.States[key]
  67. });
  68. }
  69. var stateSelect = registry.byId(this.id + "StateMessage");
  70. stateSelect.addOption(stateOptions);
  71. },
  72. getTitle: function () {
  73. return this.i18n.title;
  74. },
  75. // Hitched actions ---
  76. _onRefresh: function (event) {
  77. this.wu.refresh(true);
  78. },
  79. _onSave: function (event) {
  80. var protectedCheckbox = registry.byId(this.id + "isProtected");
  81. var context = this;
  82. this.wu.update({
  83. JobName: dom.byId(context.id + "JobName").value,
  84. isProtected: protectedCheckbox.get("value")
  85. }, null);
  86. },
  87. _onDelete: function (event) {
  88. this.wu.doDelete();
  89. },
  90. _onAbort: function (event) {
  91. this.wu.abort();
  92. },
  93. _onResubmit: function (event) {
  94. var context = this;
  95. this.wu.resubmit();
  96. },
  97. _onModify: function (event) {
  98. //TODO
  99. },
  100. // Implementation ---
  101. init: function (params) {
  102. if (this.inherited(arguments))
  103. return;
  104. //dom.byId("showWuid").innerHTML = params.Wuid;
  105. if (params.Wuid) {
  106. this.summaryWidget.set("title", params.Wuid);
  107. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  108. this.clearInput();
  109. this.wu = ESPDFUWorkunit.Get(params.Wuid);
  110. var data = this.wu.getData();
  111. for (var key in data) {
  112. this.updateInput(key, null, data[key]);
  113. }
  114. var context = this;
  115. this.wu.watch(function (name, oldValue, newValue) {
  116. context.updateInput(name, oldValue, newValue);
  117. });
  118. this.wu.refresh();
  119. }
  120. this.selectChild(this.summaryWidget, true);
  121. },
  122. initTab: function () {
  123. if (!this.wu) {
  124. return
  125. }
  126. var currSel = this.getSelectedChild();
  127. if (!currSel.initalized) {
  128. if (currSel.id == this.summaryWidget.id) {
  129. } else if (currSel.id == this.xmlWidget.id) {
  130. var context = this;
  131. this.wu.fetchXML(function (response) {
  132. context.xmlWidget.init({
  133. ECL: response
  134. });
  135. });
  136. } else {
  137. currSel.init(currSel._hpccParams);
  138. }
  139. }
  140. },
  141. objectToText: function (obj) {
  142. var text = ""
  143. for (var key in obj) {
  144. text += "<tr><td>" + key + ":</td>";
  145. if (typeof obj[key] == "object") {
  146. text += "[<br/>";
  147. for (var i = 0; i < obj[key].length; ++i) {
  148. text += this.objectToText(obj[key][i]);
  149. }
  150. text += "<br/>]<br/>";
  151. } else {
  152. text += "<td>" + obj[key] + "</td></tr>";
  153. }
  154. }
  155. return text;
  156. },
  157. resetPage: function () {
  158. },
  159. getAncestor: function (node, type) {
  160. if (node) {
  161. if (node.tagName === type) {
  162. return node;
  163. }
  164. return this.getAncestor(node.parentNode, type);
  165. }
  166. return null;
  167. },
  168. setInnerHTML: function (id, value) {
  169. var domNode = dom.byId(this.id + id);
  170. var pNode = this.getAncestor(domNode, "LI");
  171. if (typeof value != 'undefined') {
  172. if (pNode) {
  173. domClass.remove(pNode, "hidden");
  174. }
  175. domNode.innerHTML = value;
  176. } else {
  177. if (pNode) {
  178. domClass.add(pNode, "hidden");
  179. }
  180. }
  181. },
  182. setValue: function (id, value) {
  183. var domNode = dom.byId(this.id + id);
  184. var pNode = this.getAncestor(domNode, "LI");
  185. if (typeof value != 'undefined') {
  186. if (pNode) {
  187. domClass.remove(pNode, "hidden");
  188. }
  189. var registryNode = registry.byId(this.id + id);
  190. if (registryNode) {
  191. registryNode.set("value", value);
  192. } else {
  193. domNode.value = value;
  194. }
  195. } else {
  196. if (pNode) {
  197. domClass.add(pNode, "hidden");
  198. }
  199. }
  200. },
  201. clearInput: function () {
  202. var list = query("div#" + this.id + "_Summary form > ul > li");
  203. arrayUtil.forEach(list, function (item, idx) {
  204. domClass.add(item, "hidden");
  205. });
  206. },
  207. updateInput: function (name, oldValue, newValue) {
  208. var registryNode = registry.byId(this.id + name);
  209. if (registryNode) {
  210. this.setValue(name, newValue);
  211. } else {
  212. var domNode = dom.byId(this.id + name);
  213. if (domNode) {
  214. switch (domNode.tagName) {
  215. case "SPAN":
  216. case "DIV":
  217. this.setInnerHTML(name, newValue);
  218. break;
  219. case "INPUT":
  220. case "TEXTAREA":
  221. this.setValue(name, newValue);
  222. break;
  223. default:
  224. alert(domNode.tagName + ":" + name);
  225. }
  226. }
  227. }
  228. switch (name) {
  229. case "CommandMessage":
  230. this.setInnerHTML("CommandMessage2", newValue);
  231. break;
  232. case "isProtected":
  233. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  234. break;
  235. case "State":
  236. case "hasCompleted":
  237. this.refreshActionState();
  238. break;
  239. case "SourceLogicalName":
  240. this.ensurePane(this.id + "_SourceLogicalName", this.i18n.Source, {
  241. Name: newValue
  242. });
  243. break;
  244. case "DestLogicalName":
  245. this.ensurePane(this.id + "_DestLogicalName", this.i18n.Target, {
  246. Name: newValue
  247. });
  248. break;
  249. }
  250. },
  251. refreshActionState: function () {
  252. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  253. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  254. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  255. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  256. registry.byId(this.id + "Modify").set("disabled", true); //TODO
  257. registry.byId(this.id + "JobName").set("readOnly", !this.wu.isComplete());
  258. registry.byId(this.id + "isProtected").set("readOnly", !this.wu.isComplete());
  259. this.summaryWidget.set("iconClass", this.wu.getStateIconClass());
  260. dom.byId(this.id + "StateIdImage").src = this.wu.getStateImage();
  261. },
  262. checkIfComplete: function() {
  263. },
  264. monitorWorkunit: function (response) {
  265. },
  266. ensurePane: function (id, title, params) {
  267. var retVal = registry.byId(id);
  268. if (!retVal) {
  269. var context = this;
  270. retVal = new LFDetailsWidget.fixCircularDependency({
  271. id: id,
  272. title: title,
  273. closable: false,
  274. _hpccParams: params
  275. });
  276. this.addChild(retVal);
  277. }
  278. return retVal;
  279. }
  280. });
  281. });