LFDetailsWidget.js 12 KB

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