DFUWUDetailsWidget.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 data = this.wu.getData();
  125. for (key in data) {
  126. this.updateInput(key, null, data[key]);
  127. }
  128. var context = this;
  129. this.wu.watch(function (name, oldValue, newValue) {
  130. context.updateInput(name, oldValue, newValue);
  131. });
  132. this.wu.refresh();
  133. }
  134. this.selectChild(this.summaryWidget, true);
  135. },
  136. initTab: function () {
  137. if (!this.wu) {
  138. return
  139. }
  140. var currSel = this.getSelectedChild();
  141. if (currSel.id == this.summaryWidget.id) {
  142. } else if (currSel.id == this.xmlWidget.id) {
  143. if (!this.xmlWidgetLoaded) {
  144. var context = this;
  145. this.wu.fetchXML(function (response) {
  146. context.xmlWidgetLoaded = true;
  147. context.xmlWidget.init({
  148. ECL: response
  149. });
  150. });
  151. }
  152. } else {
  153. if (!currSel.initalized) {
  154. currSel.init(currSel._hpccParams);
  155. }
  156. }
  157. },
  158. objectToText: function (obj) {
  159. var text = ""
  160. for (var key in obj) {
  161. text += "<tr><td>" + key + ":</td>";
  162. if (typeof obj[key] == "object") {
  163. text += "[<br/>";
  164. for (var i = 0; i < obj[key].length; ++i) {
  165. text += this.objectToText(obj[key][i]);
  166. }
  167. text += "<br/>]<br/>";
  168. } else {
  169. text += "<td>" + obj[key] + "</td></tr>";
  170. }
  171. }
  172. return text;
  173. },
  174. resetPage: function () {
  175. },
  176. getAncestor: function (node, type) {
  177. if (node) {
  178. if (node.tagName === type) {
  179. return node;
  180. }
  181. return this.getAncestor(node.parentNode, type);
  182. }
  183. return null;
  184. },
  185. setInnerHTML: function (id, value) {
  186. var domNode = dom.byId(this.id + id);
  187. var pNode = this.getAncestor(domNode, "LI");
  188. if (typeof value != 'undefined') {
  189. if (pNode) {
  190. domClass.remove(pNode, "hidden");
  191. }
  192. domNode.innerHTML = value;
  193. } else {
  194. if (pNode) {
  195. domClass.add(pNode, "hidden");
  196. }
  197. }
  198. },
  199. setValue: function (id, value) {
  200. var domNode = dom.byId(this.id + id);
  201. var pNode = this.getAncestor(domNode, "LI");
  202. if (typeof value != 'undefined') {
  203. if (pNode) {
  204. domClass.remove(pNode, "hidden");
  205. }
  206. var registryNode = registry.byId(this.id + id);
  207. if (registryNode) {
  208. registryNode.set("value", value);
  209. } else {
  210. domNode.value = value;
  211. }
  212. } else {
  213. if (pNode) {
  214. domClass.add(pNode, "hidden");
  215. }
  216. }
  217. },
  218. clearInput: function () {
  219. var list = query("div#" + this.id + "_Summary form > ul > li");
  220. arrayUtil.forEach(list, function (item, idx) {
  221. domClass.add(item, "hidden");
  222. });
  223. },
  224. updateInput: function (name, oldValue, newValue) {
  225. var registryNode = registry.byId(this.id + name);
  226. if (registryNode) {
  227. this.setValue(name, newValue);
  228. } else {
  229. var domNode = dom.byId(this.id + name);
  230. if (domNode) {
  231. switch (domNode.tagName) {
  232. case "SPAN":
  233. case "DIV":
  234. this.setInnerHTML(name, newValue);
  235. break;
  236. case "INPUT":
  237. case "TEXTAREA":
  238. this.setValue(name, newValue);
  239. break;
  240. default:
  241. alert(domNode.tagName + ":" + name);
  242. }
  243. }
  244. }
  245. switch (name) {
  246. case "CommandMessage":
  247. this.setInnerHTML("CommandMessage2", newValue);
  248. break;
  249. case "isProtected":
  250. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  251. break;
  252. case "State":
  253. case "hasCompleted":
  254. this.refreshActionState();
  255. break;
  256. case "SourceLogicalName":
  257. this.ensurePane(this.id + "_SourceLogicalName", "Source", {
  258. Name: newValue
  259. });
  260. break;
  261. case "DestLogicalName":
  262. this.ensurePane(this.id + "_DestLogicalName", "Target", {
  263. Name: newValue
  264. });
  265. break;
  266. }
  267. },
  268. refreshActionState: function () {
  269. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  270. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  271. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  272. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  273. registry.byId(this.id + "Modify").set("disabled", true); //TODO
  274. registry.byId(this.id + "JobName").set("readOnly", !this.wu.isComplete());
  275. registry.byId(this.id + "isProtected").set("readOnly", !this.wu.isComplete());
  276. this.summaryWidget.set("iconClass", this.wu.getStateIconClass());
  277. dom.byId(this.id + "StateIdImage").src = this.wu.getStateImage();
  278. },
  279. checkIfComplete: function() {
  280. },
  281. monitorWorkunit: function (response) {
  282. },
  283. ensurePane: function (id, title, params) {
  284. var retVal = this.tabMap[id];
  285. if (!retVal) {
  286. retVal = registry.byId(id);
  287. if (!retVal) {
  288. var context = this;
  289. retVal = new LFDetailsWidget.fixCircularDependency({
  290. id: id,
  291. title: title,
  292. closable: false,
  293. _hpccParams: params
  294. });
  295. }
  296. this.tabMap[id] = retVal;
  297. this.addChild(retVal);
  298. }
  299. return retVal;
  300. }
  301. });
  302. });