LFDetailsWidget.js 12 KB

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