LZBrowseWidget.js 17 KB

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