LFDetailsWidget.js 12 KB

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