DFUWUDetailsWidget.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. "dojo/_base/declare",
  18. "dojo/_base/array",
  19. "dojo/dom",
  20. "dojo/dom-attr",
  21. "dojo/dom-class",
  22. "dojo/dom-style",
  23. "dojo/query",
  24. "dijit/_TemplatedMixin",
  25. "dijit/_WidgetsInTemplateMixin",
  26. "dijit/layout/BorderContainer",
  27. "dijit/layout/TabContainer",
  28. "dijit/layout/ContentPane",
  29. "dijit/Toolbar",
  30. "dijit/form/Textarea",
  31. "dijit/TitlePane",
  32. "dijit/registry",
  33. "dijit/ProgressBar",
  34. "hpcc/_TabContainerWidget",
  35. "hpcc/FileSpray",
  36. "hpcc/ESPDFUWorkunit",
  37. "hpcc/ECLSourceWidget",
  38. "hpcc/TargetSelectWidget",
  39. "hpcc/SampleSelectWidget",
  40. "hpcc/GraphWidget",
  41. "hpcc/ResultsWidget",
  42. "hpcc/InfoGridWidget",
  43. "hpcc/LFDetailsWidget",
  44. "dojo/text!../templates/DFUWUDetailsWidget.html",
  45. "dojox/layout/TableContainer"
  46. ], function (declare, arrayUtil, dom, domAttr, domClass, domStyle, query,
  47. _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, Toolbar, Textarea, TitlePane, registry, ProgressBar,
  48. _TabContainerWidget, FileSpray, ESPDFUWorkunit, EclSourceWidget, TargetSelectWidget, SampleSelectWidget, GraphWidget, ResultsWidget, InfoGridWidget, LFDetailsWidget,
  49. template) {
  50. return declare("DFUWUDetailsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  51. templateString: template,
  52. baseClass: "DFUWUDetailsWidget",
  53. summaryWidget: null,
  54. resultsWidget: null,
  55. resultsWidgetLoaded: false,
  56. filesWidget: null,
  57. filesWidgetLoaded: false,
  58. timersWidget: null,
  59. timersWidgetLoaded: false,
  60. graphsWidget: null,
  61. graphsWidgetLoaded: false,
  62. sourceWidget: null,
  63. sourceWidgetLoaded: false,
  64. playgroundWidget: null,
  65. playgroundWidgetLoaded: false,
  66. xmlWidget: null,
  67. xmlWidgetLoaded: false,
  68. wu: null,
  69. loaded: false,
  70. tabMap: [],
  71. buildRendering: function (args) {
  72. this.inherited(arguments);
  73. },
  74. postCreate: function (args) {
  75. this.inherited(arguments);
  76. this.summaryWidget = registry.byId(this.id + "_Summary");
  77. this.xmlWidget = registry.byId(this.id + "_XML");
  78. var stateOptions = [];
  79. for (var key in FileSpray.States) {
  80. stateOptions.push({
  81. label: FileSpray.States[key],
  82. value: FileSpray.States[key]
  83. });
  84. }
  85. var stateSelect = registry.byId(this.id + "StateMessage");
  86. stateSelect.addOption(stateOptions);
  87. },
  88. // Hitched actions ---
  89. _onRefresh: function (event) {
  90. this.wu.refresh(true);
  91. },
  92. _onSave: function (event) {
  93. var protectedCheckbox = registry.byId(this.id + "isProtected");
  94. var context = this;
  95. this.wu.update({
  96. JobName: dom.byId(context.id + "JobName").value,
  97. isProtected: protectedCheckbox.get("value")
  98. }, null);
  99. },
  100. _onDelete: function (event) {
  101. this.wu.doDelete();
  102. },
  103. _onAbort: function (event) {
  104. this.wu.abort();
  105. },
  106. _onResubmit: function (event) {
  107. var context = this;
  108. this.wu.resubmit();
  109. },
  110. _onModify: function (event) {
  111. //TODO
  112. },
  113. // Implementation ---
  114. init: function (params) {
  115. if (this.initalized)
  116. return;
  117. this.initalized = true;
  118. //dom.byId("showWuid").innerHTML = params.Wuid;
  119. if (params.Wuid) {
  120. this.summaryWidget.set("title", params.Wuid);
  121. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  122. this.clearInput();
  123. this.wu = ESPDFUWorkunit.Get(params.Wuid);
  124. var context = this;
  125. this.wu.watch(function (name, oldValue, newValue) {
  126. context.updateInput(name, oldValue, newValue);
  127. });
  128. this.wu.refresh();
  129. }
  130. this.selectChild(this.summaryWidget, true);
  131. },
  132. initTab: function () {
  133. if (!this.wu) {
  134. return
  135. }
  136. var currSel = this.getSelectedChild();
  137. if (currSel.id == this.summaryWidget.id) {
  138. } else if (currSel.id == this.xmlWidget.id) {
  139. if (!this.xmlWidgetLoaded) {
  140. var context = this;
  141. this.wu.fetchXML(function (response) {
  142. context.xmlWidgetLoaded = true;
  143. context.xmlWidget.init({
  144. ECL: response
  145. });
  146. });
  147. }
  148. } else {
  149. if (!currSel.initalized) {
  150. currSel.init(currSel._hpccParams);
  151. }
  152. }
  153. },
  154. objectToText: function (obj) {
  155. var text = ""
  156. for (var key in obj) {
  157. text += "<tr><td>" + key + ":</td>";
  158. if (typeof obj[key] == "object") {
  159. text += "[<br/>";
  160. for (var i = 0; i < obj[key].length; ++i) {
  161. text += this.objectToText(obj[key][i]);
  162. }
  163. text += "<br/>]<br/>";
  164. } else {
  165. text += "<td>" + obj[key] + "</td></tr>";
  166. }
  167. }
  168. return text;
  169. },
  170. resetPage: function () {
  171. },
  172. getAncestor: function (node, type) {
  173. if (node) {
  174. if (node.tagName === type) {
  175. return node;
  176. }
  177. return this.getAncestor(node.parentNode, type);
  178. }
  179. return null;
  180. },
  181. setInnerHTML: function (id, value) {
  182. var domNode = dom.byId(this.id + id);
  183. var pNode = this.getAncestor(domNode, "LI");
  184. if (typeof value != 'undefined') {
  185. if (pNode) {
  186. domClass.remove(pNode, "hidden");
  187. }
  188. domNode.innerHTML = value;
  189. } else {
  190. if (pNode) {
  191. domClass.add(pNode, "hidden");
  192. }
  193. }
  194. },
  195. setValue: function (id, value) {
  196. var domNode = dom.byId(this.id + id);
  197. var pNode = this.getAncestor(domNode, "LI");
  198. if (typeof value != 'undefined') {
  199. if (pNode) {
  200. domClass.remove(pNode, "hidden");
  201. }
  202. var registryNode = registry.byId(this.id + id);
  203. if (registryNode) {
  204. registryNode.set("value", value);
  205. } else {
  206. domNode.value = value;
  207. }
  208. } else {
  209. if (pNode) {
  210. domClass.add(pNode, "hidden");
  211. }
  212. }
  213. },
  214. clearInput: function () {
  215. var list = query("div#" + this.id + "_Summary form > ul > li");
  216. arrayUtil.forEach(list, function (item, idx) {
  217. domClass.add(item, "hidden");
  218. });
  219. },
  220. updateInput: function (name, oldValue, newValue) {
  221. var registryNode = registry.byId(this.id + name);
  222. if (registryNode) {
  223. this.setValue(name, newValue);
  224. } else {
  225. var domNode = dom.byId(this.id + name);
  226. if (domNode) {
  227. switch (domNode.tagName) {
  228. case "SPAN":
  229. case "DIV":
  230. this.setInnerHTML(name, newValue);
  231. break;
  232. case "INPUT":
  233. case "TEXTAREA":
  234. this.setValue(name, newValue);
  235. break;
  236. default:
  237. alert(domNode.tagName + ":" + name);
  238. }
  239. }
  240. }
  241. switch (name) {
  242. case "CommandMessage":
  243. this.setInnerHTML("CommandMessage2", newValue);
  244. break;
  245. case "isProtected":
  246. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  247. break;
  248. case "State":
  249. case "hasCompleted":
  250. this.refreshActionState();
  251. break;
  252. case "SourceLogicalName":
  253. this.ensurePane(this.id + "_SourceLogicalName", "Source", {
  254. Name: newValue
  255. });
  256. break;
  257. case "DestLogicalName":
  258. this.ensurePane(this.id + "_DestLogicalName", "Target", {
  259. Name: newValue
  260. });
  261. break;
  262. }
  263. },
  264. refreshActionState: function () {
  265. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  266. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  267. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  268. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  269. registry.byId(this.id + "Modify").set("disabled", true); //TODO
  270. registry.byId(this.id + "JobName").set("readOnly", !this.wu.isComplete());
  271. registry.byId(this.id + "isProtected").set("readOnly", !this.wu.isComplete());
  272. this.summaryWidget.set("iconClass", this.wu.getStateIconClass());
  273. dom.byId(this.id + "StateIdImage").src = this.wu.getStateImage();
  274. },
  275. checkIfComplete: function() {
  276. },
  277. monitorWorkunit: function (response) {
  278. },
  279. ensurePane: function (id, title, params) {
  280. var retVal = this.tabMap[id];
  281. if (!retVal) {
  282. retVal = registry.byId(id);
  283. if (!retVal) {
  284. var context = this;
  285. retVal = new LFDetailsWidget.fixCircularDependency({
  286. id: id,
  287. title: title,
  288. closable: false,
  289. _hpccParams: params
  290. });
  291. }
  292. this.tabMap[id] = retVal;
  293. this.addChild(retVal);
  294. }
  295. return retVal;
  296. }
  297. });
  298. });