LZBrowseWidget.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/_base/array",
  20. "dojo/dom",
  21. "dojo/dom-attr",
  22. "dojo/dom-class",
  23. "dojo/dom-form",
  24. "dojo/request/iframe",
  25. "dojo/date",
  26. "dojo/on",
  27. "dijit/registry",
  28. "dijit/Dialog",
  29. "dijit/Menu",
  30. "dijit/MenuItem",
  31. "dijit/MenuSeparator",
  32. "dijit/PopupMenuItem",
  33. "dgrid/OnDemandGrid",
  34. "dgrid/tree",
  35. "dgrid/Keyboard",
  36. "dgrid/Selection",
  37. "dgrid/selector",
  38. "dgrid/extensions/ColumnResizer",
  39. "dgrid/extensions/DijitRegistry",
  40. "dgrid/extensions/Pagination",
  41. "hpcc/_TabContainerWidget",
  42. "hpcc/FileSpray",
  43. "hpcc/ESPUtil",
  44. "hpcc/ESPRequest",
  45. "hpcc/ESPDFUWorkunit",
  46. "hpcc/HexViewWidget",
  47. "hpcc/DFUWUDetailsWidget",
  48. "hpcc/TargetSelectWidget",
  49. "dojo/text!../templates/LZBrowseWidget.html",
  50. "dijit/layout/BorderContainer",
  51. "dijit/layout/TabContainer",
  52. "dijit/layout/ContentPane",
  53. "dijit/form/Form",
  54. "dijit/form/Textarea",
  55. "dijit/form/DateTextBox",
  56. "dijit/form/TimeTextBox",
  57. "dijit/form/Button",
  58. "dijit/form/RadioButton",
  59. "dijit/form/Select",
  60. "dijit/Toolbar",
  61. "dijit/ToolbarSeparator",
  62. "dijit/TooltipDialog",
  63. "dijit/form/DropDownButton",
  64. "dojox/layout/TableContainer",
  65. "dojox/form/Uploader",
  66. "dojox/form/uploader/FileList"
  67. ], function (declare, lang, arrayUtil, dom, domAttr, domClass, domForm, iframe, date, on,
  68. registry, Dialog, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  69. OnDemandGrid, tree, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  70. _TabContainerWidget, FileSpray, ESPUtil, ESPRequest, ESPDFUWorkunit, HexViewWidget, DFUWUDetailsWidget, TargetSelectWidget,
  71. template) {
  72. return declare("LZBrowseWidget", [_TabContainerWidget, ESPUtil.FormHelper], {
  73. templateString: template,
  74. baseClass: "LZBrowseWidget",
  75. sprayFixedDialog: null,
  76. sprayVariableDialog: null,
  77. sprayXmlDialog: null,
  78. landingZonesTab: null,
  79. landingZonesGrid: null,
  80. tabMap: [],
  81. validateDialog: null,
  82. postCreate: function (args) {
  83. this.inherited(arguments);
  84. this.sprayFixedDialog = registry.byId(this.id + "SprayFixedDialog");
  85. this.sprayVariableDialog = registry.byId(this.id + "SprayVariableDialog");
  86. this.sprayXmlDialog = registry.byId(this.id + "SprayXmlDialog");
  87. this.landingZonesTab = registry.byId(this.id + "_LandingZones");
  88. this.uploader = registry.byId(this.id + "Upload");
  89. this.uploadFileList = registry.byId(this.id + "UploadFileList");
  90. this.spraySourceSelect = registry.byId(this.id + "SpraySourceSelect");
  91. this.sprayFixedDestinationSelect = registry.byId(this.id + "SprayFixedDestination");
  92. this.sprayVariableDestinationSelect = registry.byId(this.id + "SprayVariableDestination");
  93. this.sprayXmlDestinationSelect = registry.byId(this.id + "SprayXmlDestinationSelect");
  94. this.dropZoneSelect = registry.byId(this.id + "DropZoneTargetSelect");
  95. this.fileListDialog = registry.byId(this.id + "FileListDialog");
  96. var context = this;
  97. this.connect(this.uploader, "onComplete", function () {
  98. context.fileListDialog.hide();
  99. context.refreshGrid();
  100. });
  101. // Workaround for HPCC-9414 --->
  102. this.connect(this.uploader, "onError", function (msg, e) {
  103. if (msg === "Error parsing server result:") {
  104. context.fileListDialog.hide();
  105. context.refreshGrid();
  106. }
  107. });
  108. // <--- Workaround for HPCC-9414
  109. },
  110. startup: function (args) {
  111. this.inherited(arguments);
  112. },
  113. getTitle: function () {
  114. return "Landing Zones";
  115. },
  116. _handleResponse: function (wuidQualifier, response) {
  117. if (lang.exists(wuidQualifier, response)) {
  118. var wu = ESPDFUWorkunit.Get(lang.getObject(wuidQualifier, false, response));
  119. wu.startMonitor(true);
  120. var tab = this.ensurePane("dfu", this.id + "_" + wu.ID, wu.ID, {
  121. Wuid: wu.ID
  122. });
  123. if (tab) {
  124. this.selectChild(tab);
  125. }
  126. }
  127. },
  128. // Hitched actions ---
  129. _onRefresh: function (event) {
  130. this.refreshGrid();
  131. },
  132. _onUpload: function (event) {
  133. this.uploadFileList.hideProgress();
  134. this.fileListDialog.show();
  135. },
  136. _onDownload: function (event) {
  137. var context = this;
  138. arrayUtil.forEach(this.landingZonesGrid.getSelected(), function (item, idx) {
  139. var downloadIframeName = "downloadIframe_" + item.calculatedID;
  140. var frame = iframe.create(downloadIframeName);
  141. var url = ESPRequest.getBaseURL("FileSpray") + "/DownloadFile?Name=" + encodeURIComponent(item.partialPath) + "&NetAddress=" + item.DropZone.NetAddress + "&Path=" + encodeURIComponent(item.DropZone.Path) + "&OS=" + item.DropZone.OS;
  142. iframe.setSrc(frame, url, true);
  143. });
  144. },
  145. _onDelete: function (event) {
  146. if (confirm('Delete selected files?')) {
  147. var context = this;
  148. arrayUtil.forEach(this.landingZonesGrid.getSelected(), function(item, idx) {
  149. FileSpray.DeleteDropZoneFile({
  150. request:{
  151. NetAddress: item.DropZone.NetAddress,
  152. Path: item.DropZone.Path,
  153. OS: item.DropZone.OS,
  154. Names: item.partialPath
  155. },
  156. load: function (response) {
  157. context.refreshGrid();
  158. }
  159. });
  160. });
  161. }
  162. },
  163. _onHexPreview: function (event) {
  164. var selections = this.landingZonesGrid.getSelected();
  165. var firstTab = null;
  166. var context = this;
  167. arrayUtil.forEach(selections, function (item, idx) {
  168. var tab = context.ensurePane("hex", context.id + "_" + item.calculatedID, item.displayName, {
  169. logicalFile: item.getLogicalFile()
  170. });
  171. if (firstTab === null) {
  172. firstTab = tab;
  173. }
  174. });
  175. if (firstTab) {
  176. this.selectChild(firstTab);
  177. }
  178. },
  179. _onUploadSubmit: function (event) {
  180. var item = this.dropZoneSelect.get("row");
  181. this.uploader.set("uploadUrl", "/FileSpray/UploadFile.json?upload_&rawxml_=1&NetAddress=" + item.machine.Netaddress + "&OS=" + item.machine.OS + "&Path=" + item.machine.Directory);
  182. this.uploader.upload();
  183. },
  184. _onUploadCancel: function (event) {
  185. registry.byId(this.id + "FileListDialog").hide();
  186. },
  187. _onSprayFixed: function (event) {
  188. if (this.sprayFixedDialog.validate()) {
  189. var selections = this.landingZonesGrid.getSelected();
  190. var context = this;
  191. arrayUtil.forEach(selections, function (item, idx) {
  192. var formData = domForm.toObject(context.id + "SprayFixedDialog");
  193. lang.mixin(formData, {
  194. sourceIP: item.DropZone.NetAddress,
  195. sourcePath: item.fullPath
  196. });
  197. FileSpray.SprayFixed({
  198. request: formData
  199. }).then(function (response) {
  200. context._handleResponse("SprayFixedResponse.wuid", response);
  201. })
  202. });
  203. registry.byId(this.id + "SprayFixedDropDown").closeDropDown();
  204. }
  205. },
  206. _onSprayVariable: function(event) {
  207. if (this.sprayVariableDialog.validate()) {
  208. var selections = this.landingZonesGrid.getSelected();
  209. var context = this;
  210. arrayUtil.forEach(selections, function (item, idx) {
  211. var formData = domForm.toObject(context.id + "SprayVariableDialog");
  212. lang.mixin(formData, {
  213. sourceIP: item.DropZone.NetAddress,
  214. sourcePath: item.fullPath
  215. });
  216. FileSpray.SprayVariable({
  217. request: formData
  218. }).then(function (response) {
  219. context._handleResponse("SprayResponse.wuid", response);
  220. });
  221. });
  222. registry.byId(this.id + "SprayVariableDropDown").closeDropDown();
  223. }
  224. },
  225. _onSprayXml: function(event) {
  226. if (this.sprayXmlDialog.validate()) {
  227. var selections = this.landingZonesGrid.getSelected();
  228. var context = this;
  229. arrayUtil.forEach(selections, function (item, idx) {
  230. var formData = domForm.toObject(context.id + "SprayXmlDialog");
  231. lang.mixin(formData, {
  232. sourceIP: item.DropZone.NetAddress,
  233. sourcePath: item.DropZone.fullPath
  234. });
  235. FileSpray.SprayVariable({
  236. request: formData
  237. }).then(function (response) {
  238. context._handleResponse("SprayResponse.wuid", response);
  239. });
  240. });
  241. registry.byId(this.id + "SprayXmlDropDown").closeDropDown();
  242. }
  243. },
  244. _onRowDblClick: function (wuid) {
  245. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  246. Wuid: wuid
  247. });
  248. this.selectChild(wuTab);
  249. },
  250. _onRowContextMenu: function (item, colField, mystring) {
  251. },
  252. // Implementation ---
  253. init: function (params) {
  254. if (this.inherited(arguments))
  255. return;
  256. this.initLandingZonesGrid();
  257. this.selectChild(this.landingZonesTab, true);
  258. this.sprayFixedDestinationSelect.init({
  259. Groups: true
  260. });
  261. this.sprayVariableDestinationSelect.init({
  262. Groups: true
  263. });
  264. this.sprayXmlDestinationSelect.init({
  265. Groups: true
  266. });
  267. this.dropZoneSelect.init({
  268. DropZones: true
  269. });
  270. var context = this;
  271. this.spraySourceSelect.set("value", "Fixed");
  272. this.spraySourceSelect.on("change", function (evt) {
  273. var source = this.get("value");
  274. if(source == "Fixed"){
  275. registry.byId(context.id + "SprayFixedRecordLength").set('readOnly', false);
  276. }else{
  277. registry.byId(context.id + "SprayFixedRecordLength").set('readOnly', true);
  278. registry.byId(context.id + "SprayFixedRecordLength").set('value', "");
  279. }
  280. });
  281. },
  282. initTab: function () {
  283. var currSel = this.getSelectedChild();
  284. if (currSel && !currSel.initalized) {
  285. if (currSel.id == this.landingZonesTab.id) {
  286. } else {
  287. if (!currSel.initalized) {
  288. currSel.init(currSel.params);
  289. }
  290. }
  291. }
  292. },
  293. addMenuItem: function (menu, details) {
  294. var menuItem = new MenuItem(details);
  295. menu.addChild(menuItem);
  296. return menuItem;
  297. },
  298. initLandingZonesGrid: function () {
  299. var store = new FileSpray.CreateLandingZonesStore();
  300. this.landingZonesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  301. allowSelectAll: true,
  302. deselectOnRefresh: false,
  303. store: store,
  304. columns: {
  305. col1: selector({
  306. width: 27,
  307. selectorType: 'checkbox',
  308. disabled: function (item) {
  309. if (item.type) {
  310. switch (item.type) {
  311. case "dropzone":
  312. case "folder":
  313. return true;
  314. }
  315. }
  316. return false;
  317. },
  318. sortable: false
  319. }),
  320. displayName: tree({
  321. label: "Name",
  322. collapseOnRefresh: true,
  323. sortable: false,
  324. formatter: function (name, row) {
  325. var img = "../files/img/";
  326. if (row.isDir === undefined) {
  327. img += "server.png";
  328. } else if (row.isDir) {
  329. img += "folder.png";
  330. } else {
  331. img += "file.png";
  332. }
  333. return "<img src='" + img + "'/>&nbsp;" + name;
  334. }
  335. }),
  336. filesize: { label: "Size", width: 108, sortable: false },
  337. modifiedtime: { label: "Date", width: 180, sortable: false }
  338. },
  339. getSelected: function () {
  340. var retVal = [];
  341. var store = FileSpray.CreateFileListStore();
  342. for (var key in this.selection) {
  343. retVal.push(store.get(key));
  344. }
  345. return retVal;
  346. }
  347. }, this.id + "LandingZonesGrid");
  348. this.landingZonesGrid.set("noDataMessage", "<span>Zero Files (Upload Some Files).</span>");
  349. var context = this;
  350. on(document, ".WuidClick:click", function (evt) {
  351. if (context._onRowDblClick) {
  352. var item = context.landingZonesGrid.row(evt).data;
  353. context._onRowDblClick(item.Wuid);
  354. }
  355. });
  356. this.landingZonesGrid.on(".dgrid-row:dblclick", function (evt) {
  357. if (context._onRowDblClick) {
  358. var item = context.landingZonesGrid.row(evt).data;
  359. context._onRowDblClick(item.Wuid);
  360. }
  361. });
  362. this.landingZonesGrid.on(".dgrid-row:contextmenu", function (evt) {
  363. if (context._onRowContextMenu) {
  364. var item = context.landingZonesGrid.row(evt).data;
  365. var cell = context.landingZonesGrid.cell(evt);
  366. var colField = cell.column.field;
  367. var mystring = "item." + colField;
  368. context._onRowContextMenu(item, colField, mystring);
  369. }
  370. });
  371. this.landingZonesGrid.onSelectionChanged(function (event) {
  372. context.refreshActionState();
  373. });
  374. this.landingZonesGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  375. context.refreshActionState();
  376. });
  377. this.landingZonesGrid.startup();
  378. this.refreshActionState();
  379. },
  380. refreshGrid: function (args) {
  381. this.landingZonesGrid.set("query", {
  382. id: "*"
  383. });
  384. },
  385. refreshActionState: function () {
  386. var selection = this.landingZonesGrid.getSelected();
  387. var hasSelection = selection.length;
  388. registry.byId(this.id + "HexPreview").set("disabled", !hasSelection);
  389. registry.byId(this.id + "Download").set("disabled", !hasSelection);
  390. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  391. registry.byId(this.id + "SprayFixedDropDown").set("disabled", !hasSelection);
  392. registry.byId(this.id + "SprayVariableDropDown").set("disabled", !hasSelection);
  393. registry.byId(this.id + "SprayXmlDropDown").set("disabled", !hasSelection);
  394. },
  395. ensurePane: function (type, id, title, params) {
  396. var retVal = registry.byId(id);
  397. if (!retVal) {
  398. var context = this;
  399. switch (type) {
  400. case "hex":
  401. retVal = new HexViewWidget({
  402. id: id,
  403. title: title,
  404. closable: true,
  405. params: params
  406. });
  407. break;
  408. case "dfu":
  409. retVal = new DFUWUDetailsWidget.fixCircularDependency({
  410. id: id,
  411. title: title,
  412. closable: true,
  413. params: params
  414. });
  415. break;
  416. }
  417. if (retVal) {
  418. this.addChild(retVal);
  419. }
  420. }
  421. return retVal;
  422. }
  423. });
  424. });