LFDetailsWidget.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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/_base/array",
  21. "dojo/dom",
  22. "dojo/dom-attr",
  23. "dojo/dom-class",
  24. "dojo/dom-form",
  25. "dojo/query",
  26. "dijit/layout/BorderContainer",
  27. "dijit/layout/TabContainer",
  28. "dijit/layout/ContentPane",
  29. "dijit/Toolbar",
  30. "dijit/TooltipDialog",
  31. "dijit/form/Form",
  32. "dijit/form/SimpleTextarea",
  33. "dijit/form/TextBox",
  34. "dijit/form/Button",
  35. "dijit/form/DropDownButton",
  36. "dijit/TitlePane",
  37. "dijit/registry",
  38. "hpcc/_TabContainerWidget",
  39. "hpcc/ResultWidget",
  40. "hpcc/ECLSourceWidget",
  41. "hpcc/FilePartsWidget",
  42. "hpcc/WUDetailsWidget",
  43. "hpcc/DFUWUDetailsWidget",
  44. "hpcc/TargetSelectWidget",
  45. "hpcc/ESPLogicalFile",
  46. "hpcc/ESPDFUWorkunit",
  47. "dojo/text!../templates/LFDetailsWidget.html",
  48. "dijit/TooltipDialog"
  49. ], function (exports, declare, lang, arrayUtil, dom, domAttr, domClass, domForm, query,
  50. BorderContainer, TabContainer, ContentPane, Toolbar, TooltipDialog, Form, SimpleTextarea, TextBox, Button, DropDownButton, TitlePane, registry,
  51. _TabContainerWidget, ResultWidget, EclSourceWidget, FilePartsWidget, WUDetailsWidget, DFUWUDetailsWidget, TargetSelectWidget, ESPLogicalFile, ESPDFUWorkunit,
  52. template) {
  53. exports.fixCircularDependency = declare("LFDetailsWidget", [_TabContainerWidget], {
  54. templateString: template,
  55. baseClass: "LFDetailsWidget",
  56. borderContainer: null,
  57. tabContainer: null,
  58. summaryWidget: null,
  59. contentWidget: null,
  60. sourceWidget: null,
  61. defWidget: null,
  62. xmlWidget: null,
  63. filePartsWidget: null,
  64. workunitWidget: null,
  65. dfuWorkunitWidget: null,
  66. logicalFile: null,
  67. prevState: "",
  68. postCreate: function (args) {
  69. this.inherited(arguments);
  70. this.summaryWidget = registry.byId(this.id + "_Summary");
  71. this.contentWidget = registry.byId(this.id + "_Content");
  72. this.sourceWidget = registry.byId(this.id + "_Source");
  73. this.defWidget = registry.byId(this.id + "_DEF");
  74. this.xmlWidget = registry.byId(this.id + "_XML");
  75. this.filePartsWidget = registry.byId(this.id + "_FileParts");
  76. this.workunitWidget = registry.byId(this.id + "_Workunit");
  77. this.dfuWorkunitWidget = registry.byId(this.id + "_DFUWorkunit");
  78. this.copyTargetSelect = registry.byId(this.id + "CopyTargetSelect");
  79. this.desprayTargetSelect = registry.byId(this.id + "DesprayTargetSelect");
  80. },
  81. // Hitched actions ---
  82. _onRefresh: function (event) {
  83. this.logicalFile.refresh();
  84. },
  85. _onSave: function (event) {
  86. var context = this;
  87. this.logicalFile.save(dom.byId(context.id + "Description").value);
  88. },
  89. _onDelete: function (event) {
  90. this.logicalFile.doDelete({
  91. load: function (response) {
  92. }
  93. });
  94. },
  95. getTitle: function () {
  96. return "Logical File Details";
  97. },
  98. _handleResponse: function (wuidQualifier, response) {
  99. if (lang.exists(wuidQualifier, response)) {
  100. var wu = ESPDFUWorkunit.Get(lang.getObject(wuidQualifier, false, response));
  101. wu.startMonitor(true);
  102. var tab = this.ensurePane(this.id + "_" + wu.ID, {
  103. Wuid: wu.ID
  104. });
  105. if (tab) {
  106. this.selectChild(tab);
  107. }
  108. }
  109. },
  110. _onCopyOk: function (event) {
  111. var context = this;
  112. this.logicalFile.copy({
  113. request: domForm.toObject(this.id + "CopyDialog")
  114. }).then(function (response) {
  115. context._handleResponse("CopyResponse.result", response);
  116. });
  117. registry.byId(this.id + "CopyDropDown").closeDropDown();
  118. },
  119. _onCopyCancel: function (event) {
  120. registry.byId(this.id + "CopyDropDown").closeDropDown();
  121. },
  122. _onRenameOk: function (event) {
  123. var context = this;
  124. this.logicalFile.rename({
  125. request: domForm.toObject(this.id + "RenameDialog")
  126. }).then(function (response) {
  127. context._handleResponse("RenameResponse.wuid", response);
  128. });
  129. registry.byId(this.id + "RenameDropDown").closeDropDown();
  130. },
  131. _onRenameCancel: function (event) {
  132. registry.byId(this.id + "RenameDropDown").closeDropDown();
  133. },
  134. _onDesprayOk: function (event) {
  135. var context = this;
  136. this.logicalFile.despray({
  137. request: domForm.toObject(this.id + "DesprayDialog")
  138. }).then(function (response) {
  139. context._handleResponse("DesprayResponse.wuid", response);
  140. });
  141. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  142. },
  143. _onDesprayCancel: function (event) {
  144. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  145. },
  146. // Implementation ---
  147. init: function (params) {
  148. if (this.inherited(arguments))
  149. return;
  150. var context = this;
  151. if (params.Name) {
  152. this.logicalFile = ESPLogicalFile.Get(params.Name);
  153. var data = this.logicalFile.getData();
  154. for (key in data) {
  155. this.updateInput(key, null, data[key]);
  156. }
  157. this.logicalFile.watch(function (name, oldValue, newValue) {
  158. context.updateInput(name, oldValue, newValue);
  159. });
  160. this.logicalFile.refresh();
  161. }
  162. this.selectChild(this.summaryWidget, true);
  163. this.copyTargetSelect.init({
  164. Groups: true
  165. });
  166. this.desprayTargetSelect.init({
  167. DropZones: true,
  168. callback: function (value, item) {
  169. context.updateInput("DesprayTargetIPAddress", null, item.machine.Netaddress);
  170. context.updateInput("DesprayTargetPath", null, item.machine.Directory + "/" + context.logicalFile.Filename);
  171. }
  172. });
  173. },
  174. initTab: function() {
  175. var currSel = this.getSelectedChild();
  176. if (currSel && !currSel.initalized) {
  177. if (currSel.id == this.summaryWidget.id) {
  178. } else if (currSel.id == this.contentWidget.id) {
  179. this.contentWidget.init({
  180. result: this.logicalFile.result
  181. });
  182. } else if (currSel.id == this.sourceWidget.id) {
  183. this.sourceWidget.init({
  184. ECL: this.logicalFile.Ecl
  185. });
  186. } else if (currSel.id == this.defWidget.id) {
  187. var context = this;
  188. this.logicalFile.fetchDEF(function (response) {
  189. context.defWidget.init({
  190. ECL: response
  191. });
  192. });
  193. } else if (currSel.id == this.xmlWidget.id) {
  194. var context = this;
  195. this.logicalFile.fetchXML(function (response) {
  196. context.xmlWidget.init({
  197. ECL: response
  198. });
  199. });
  200. } else if (currSel.id == this.filePartsWidget.id) {
  201. this.filePartsWidget.init({
  202. fileParts: lang.exists("logicalFile.DFUFileParts.DFUPart", this) ? this.logicalFile.DFUFileParts.DFUPart : []
  203. });
  204. } else if (this.workunitWidget && currSel.id == this.workunitWidget.id) {
  205. this.workunitWidget.init({
  206. Wuid: this.logicalFile.Wuid
  207. });
  208. } else if (this.dfuWorkunitWidget && currSel.id == this.dfuWorkunitWidget.id) {
  209. this.dfuWorkunitWidget.init({
  210. Wuid: this.logicalFile.Wuid
  211. });
  212. } else {
  213. currSel.init(currSel.params);
  214. }
  215. }
  216. },
  217. showMessage: function (msg) {
  218. },
  219. updateInput: function (name, oldValue, newValue) {
  220. var registryNode = registry.byId(this.id + name);
  221. if (registryNode) {
  222. registryNode.set("value", newValue);
  223. } else {
  224. var domElem = dom.byId(this.id + name);
  225. if (domElem) {
  226. switch (domElem.tagName) {
  227. case "SPAN":
  228. case "DIV":
  229. domAttr.set(this.id + name, "innerHTML", newValue);
  230. break;
  231. case "INPUT":
  232. case "TEXTAREA":
  233. domAttr.set(this.id + name, "value", newValue);
  234. break;
  235. default:
  236. alert(domElem.tagName);
  237. }
  238. }
  239. }
  240. if (name === "Wuid") {
  241. if (!newValue) {
  242. this.removeChild(this.workunitWidget);
  243. this.workunitWidget = null;
  244. this.removeChild(this.dfuWorkunitWidget);
  245. this.dfuWorkunitWidget = null;
  246. } else if (this.workunitWidget && newValue[0] === "D") {
  247. this.removeChild(this.workunitWidget);
  248. this.workunitWidget = null;
  249. } else if (this.dfuWorkunitWidget) {
  250. this.removeChild(this.dfuWorkunitWidget);
  251. this.dfuWorkunitWidget = null;
  252. }
  253. }
  254. if (name === "Name") {
  255. this.updateInput("RenameSourceName", oldValue, newValue);
  256. this.updateInput("RenameTargetName", oldValue, newValue);
  257. this.updateInput("DespraySourceName", oldValue, newValue);
  258. this.updateInput("CopySourceName", oldValue, newValue);
  259. this.updateInput("CopyTargetName", oldValue, newValue);
  260. }
  261. },
  262. ensurePane: function (id, params) {
  263. var retVal = registry.byId(id);
  264. if (!retVal) {
  265. var context = this;
  266. retVal = new DFUWUDetailsWidget.fixCircularDependency({
  267. id: id,
  268. title: params.Wuid,
  269. closable: true,
  270. params: params
  271. });
  272. this.addChild(retVal);
  273. }
  274. return retVal;
  275. }
  276. });
  277. });