DFUWUDetailsWidget.js 10 KB

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