DFUWUDetailsWidget.js 10 KB

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