LFDetailsWidget.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. "dojo/text!../templates/LFDetailsWidget.html",
  49. "dijit/TooltipDialog"
  50. ], function (exports, declare, lang, arrayUtil, dom, domAttr, domClass, domForm, query,
  51. _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, Toolbar, TooltipDialog, Form, SimpleTextarea, TextBox, Button, DropDownButton, TitlePane, registry,
  52. _TabContainerWidget, ResultWidget, EclSourceWidget, FilePartsWidget, WUDetailsWidget, DFUWUDetailsWidget, TargetSelectWidget,
  53. ESPLogicalFile,
  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. contentWidgetLoaded: false,
  63. sourceWidget: null,
  64. sourceWidgetLoaded: false,
  65. defWidget: null,
  66. defWidgetLoaded: false,
  67. xmlWidget: null,
  68. xmlWidgetLoaded: false,
  69. filePartsWidget: null,
  70. filePartsWidgetLoaded: false,
  71. workunitWidget: null,
  72. workunitWidgetLoaded: false,
  73. dfuWorkunitWidget: null,
  74. dfuWorkunitWidgetLoaded: false,
  75. legacyPane: null,
  76. legacyPaneLoaded: false,
  77. logicalFile: null,
  78. prevState: "",
  79. initalized: false,
  80. postCreate: function (args) {
  81. this.inherited(arguments);
  82. this.summaryWidget = registry.byId(this.id + "_Summary");
  83. this.contentWidget = registry.byId(this.id + "_Content");
  84. this.sourceWidget = registry.byId(this.id + "_Source");
  85. this.defWidget = registry.byId(this.id + "_DEF");
  86. this.xmlWidget = registry.byId(this.id + "_XML");
  87. this.filePartsWidget = registry.byId(this.id + "_FileParts");
  88. this.workunitWidget = registry.byId(this.id + "_Workunit");
  89. this.dfuWorkunitWidget = registry.byId(this.id + "_DFUWorkunit");
  90. this.legacyPane = registry.byId(this.id + "_Legacy");
  91. this.copyTargetSelect = registry.byId(this.id + "CopyTargetSelect");
  92. this.desprayTargetSelect = registry.byId(this.id + "DesprayTargetSelect");
  93. },
  94. // Hitched actions ---
  95. _onRefresh: function (event) {
  96. this.logicalFile.refresh();
  97. },
  98. _onSave: function (event) {
  99. var context = this;
  100. this.logicalFile.save(dom.byId(context.id + "Description").value);
  101. },
  102. _onDelete: function (event) {
  103. this.logicalFile.doDelete({
  104. load: function (response) {
  105. }
  106. });
  107. },
  108. _onCopyOk: function (event) {
  109. this.logicalFile.copy({
  110. request: domForm.toObject(this.id + "CopyDialog")
  111. });
  112. registry.byId(this.id + "CopyDropDown").closeDropDown();
  113. },
  114. _onCopyCancel: function (event) {
  115. registry.byId(this.id + "CopyDropDown").closeDropDown();
  116. },
  117. _onDesprayOk: function (event) {
  118. this.logicalFile.despray({
  119. request: domForm.toObject(this.id + "DesprayDialog")
  120. });
  121. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  122. },
  123. _onDesprayCancel: function (event) {
  124. registry.byId(this.id + "DesprayDropDown").closeDropDown();
  125. },
  126. _onRenameOk: function (event) {
  127. this.logicalFile.rename({
  128. request: domForm.toObject(this.id + "RenameDialog")
  129. });
  130. registry.byId(this.id + "RenameDropDown").closeDropDown();
  131. },
  132. _onRenameCancel: function (event) {
  133. registry.byId(this.id + "RenameDropDown").closeDropDown();
  134. },
  135. // Implementation ---
  136. init: function (params) {
  137. if (this.initalized)
  138. return;
  139. this.initalized = true;
  140. var context = this;
  141. if (params.Name) {
  142. //dom.byId(this.id + "Name").innerHTML = params.Name;
  143. //dom.byId(this.id + "LogicalFileName2").value = params.Name;
  144. this.logicalFile = ESPLogicalFile.Get(params.Name);
  145. var data = this.logicalFile.getData();
  146. for (key in data) {
  147. this.updateInput(key, null, data[key]);
  148. }
  149. this.logicalFile.watch(function (name, oldValue, newValue) {
  150. context.updateInput(name, oldValue, newValue);
  151. });
  152. this.logicalFile.refresh();
  153. }
  154. this.selectChild(this.summaryWidget, true);
  155. this.copyTargetSelect.init({
  156. Groups: true
  157. });
  158. this.desprayTargetSelect.init({
  159. DropZones: true,
  160. callback: function (value, item) {
  161. context.updateInput("DesprayTargetIPAddress", null, item.machine.Netaddress);
  162. context.updateInput("DesprayTargetPath", null, item.machine.Directory + "/" + context.logicalFile.Filename);
  163. }
  164. });
  165. },
  166. initTab: function() {
  167. var currSel = this.getSelectedChild();
  168. if (currSel.id == this.contentWidget.id && !this.contentWidgetLoaded) {
  169. this.contentWidgetLoaded = true;
  170. this.contentWidget.init({
  171. result: this.logicalFile.result
  172. });
  173. } else if (currSel.id == this.sourceWidget.id && !this.sourceWidgetLoaded) {
  174. this.sourceWidgetLoaded = true;
  175. this.sourceWidget.init({
  176. ECL: this.logicalFile.Ecl
  177. });
  178. } else if (currSel.id == this.defWidget.id && !this.defWidgetLoaded) {
  179. var context = this;
  180. this.logicalFile.fetchDEF(function (response) {
  181. context.defWidgetLoaded = true;
  182. context.defWidget.init({
  183. ECL: response
  184. });
  185. });
  186. } else if (currSel.id == this.xmlWidget.id && !this.xmlWidgetLoaded) {
  187. var context = this;
  188. this.logicalFile.fetchXML(function (response) {
  189. context.xmlWidgetLoaded = true;
  190. context.xmlWidget.init({
  191. ECL: response
  192. });
  193. });
  194. } else if (currSel.id == this.filePartsWidget.id && !this.filePartsWidgetLoaded) {
  195. this.filePartsWidgetLoaded = true;
  196. this.filePartsWidget.init({
  197. fileParts: lang.exists("logicalFile.DFUFileParts.DFUPart", this) ? this.logicalFile.DFUFileParts.DFUPart : []
  198. });
  199. } else if (this.workunitWidget && currSel.id == this.workunitWidget.id && !this.workunitWidgetLoaded) {
  200. this.workunitWidgetLoaded = true;
  201. this.workunitWidget.init({
  202. Wuid: this.logicalFile.Wuid
  203. });
  204. } else if (this.dfuWorkunitWidget && currSel.id == this.dfuWorkunitWidget.id && !this.workunitWidgetLoaded) {
  205. this.dfuWorkunitWidgetLoaded = true;
  206. this.dfuWorkunitWidget.init({
  207. Wuid: this.logicalFile.Wuid
  208. });
  209. } else if (currSel.id == this.legacyPane.id && !this.legacyPaneLoaded) {
  210. this.legacyPaneLoaded = true;
  211. this.legacyPane.set("content", dojo.create("iframe", {
  212. src: "/WsDfu/DFUInfo?Name=" + this.logicalFile.Name,//+ "&Cluster=" + this.logicalFile.cluster,
  213. style: "border: 0; width: 100%; height: 100%"
  214. }));
  215. }
  216. },
  217. showMessage: function (msg) {
  218. },
  219. /*isComplete: function () {
  220. return true;
  221. },*/
  222. updateInput: function (name, oldValue, newValue) {
  223. var domElem = dom.byId(this.id + name);
  224. if (domElem) {
  225. switch(domElem.tagName) {
  226. case "SPAN":
  227. case "DIV":
  228. domAttr.set(this.id + name, "innerHTML", newValue)
  229. break;
  230. case "INPUT":
  231. case "TEXTAREA":
  232. domAttr.set(this.id + name, "value", newValue)
  233. break;
  234. default:
  235. alert(domElem.tagName);
  236. }
  237. }
  238. if (name === "Wuid") {
  239. if (!newValue) {
  240. this.removeChild(this.workunitWidget);
  241. this.workunitWidget = null;
  242. this.removeChild(this.dfuWorkunitWidget);
  243. this.dfuWorkunitWidget = null;
  244. } else if (this.workunitWidget && newValue[0] === "D") {
  245. this.removeChild(this.workunitWidget);
  246. this.workunitWidget = null;
  247. } else if (this.dfuWorkunitWidget) {
  248. this.removeChild(this.dfuWorkunitWidget);
  249. this.dfuWorkunitWidget = null;
  250. }
  251. }
  252. if (name === "Name") {
  253. this.updateInput("RenameSourceName", oldValue, newValue);
  254. this.updateInput("RenameTargetName", oldValue, newValue);
  255. this.updateInput("DespraySourceName", oldValue, newValue);
  256. this.updateInput("CopySourceName", oldValue, newValue);
  257. this.updateInput("CopyTargetName", oldValue, newValue);
  258. }
  259. /*
  260. var widget = registry.byId(this.id + name);
  261. if (widget) {
  262. if (widget.has("innerHTML")) {
  263. widget.set("innerHTML", newValue);
  264. } else {
  265. widget.set("value", newValue);
  266. }
  267. } else {
  268. var element = dom.byId(this.id + name);
  269. if (element) {
  270. if (element.innerHTML) {
  271. element.innerHTML = newValue;
  272. } else {
  273. element.value = newValue;
  274. }
  275. }
  276. }
  277. if (name === "Filename") {
  278. registry.byId(this.id + "_Summary").set("title", newValue);
  279. }
  280. */
  281. },
  282. refreshFileDetails: function (fileDetails) {
  283. /*
  284. if (fileDetails.Wuid && fileDetails.Wuid[0] == "D" && this.workunitWidget) {
  285. this.removeChild(this.workunitWidget);
  286. this.workunitWidget = null;
  287. } else if (this.dfuWorkunitWidget) {
  288. this.removeChild(this.dfuWorkunitWidget);
  289. this.dfuWorkunitWidget = null;
  290. }
  291. registry.byId(this.id + "_Summary").set("title", fileDetails.Filename);
  292. //registry.byId(this.id + "Summary").set("iconClass", "iconRefresh");
  293. //domClass.remove(this.id + "Test");
  294. //domClass.add(this.id + "Test", "iconRefresh");
  295. dom.byId(this.id + "Owner").innerHTML = fileDetails.Owner;
  296. dom.byId(this.id + "Description").value = fileDetails.Description;
  297. dom.byId(this.id + "JobName").innerHTML = fileDetails.JobName;
  298. dom.byId(this.id + "Wuid").innerHTML = fileDetails.Wuid;
  299. dom.byId(this.id + "Modification").innerHTML = fileDetails.Modified + " (UTC/GMT)";
  300. dom.byId(this.id + "Dir").innerHTML = fileDetails.Dir;
  301. dom.byId(this.id + "RecordSize").innerHTML = fileDetails.RecordSize;
  302. dom.byId(this.id + "Count").innerHTML = fileDetails.RecordCount;
  303. this.contentWidget.set("title", "Content " + "(" + fileDetails.RecordCount + ")");
  304. dom.byId(this.id + "Filesize").innerHTML = fileDetails.Filesize;
  305. dom.byId(this.id + "PathMask").innerHTML = fileDetails.PathMask;
  306. */
  307. }
  308. });
  309. });