LFDetailsWidget.js 12 KB

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