LZBrowseWidget.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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/i18n",
  20. "dojo/i18n!./nls/common",
  21. "dojo/i18n!./nls/LZBrowseWidget",
  22. "dojo/_base/array",
  23. "dojo/dom",
  24. "dojo/dom-attr",
  25. "dojo/dom-class",
  26. "dojo/dom-form",
  27. "dojo/request/iframe",
  28. "dojo/date",
  29. "dojo/on",
  30. "dijit/registry",
  31. "dijit/Dialog",
  32. "dijit/Menu",
  33. "dijit/MenuItem",
  34. "dijit/MenuSeparator",
  35. "dijit/PopupMenuItem",
  36. "dgrid/OnDemandGrid",
  37. "dgrid/tree",
  38. "dgrid/Keyboard",
  39. "dgrid/Selection",
  40. "dgrid/editor",
  41. "dgrid/selector",
  42. "dgrid/extensions/ColumnResizer",
  43. "dgrid/extensions/DijitRegistry",
  44. "dgrid/extensions/Pagination",
  45. "hpcc/_TabContainerWidget",
  46. "hpcc/FileSpray",
  47. "hpcc/ESPUtil",
  48. "hpcc/ESPRequest",
  49. "hpcc/ESPDFUWorkunit",
  50. "hpcc/HexViewWidget",
  51. "hpcc/DFUWUDetailsWidget",
  52. "hpcc/TargetSelectWidget",
  53. "hpcc/SelectionGridWidget",
  54. "dojo/text!../templates/LZBrowseWidget.html",
  55. "dijit/layout/BorderContainer",
  56. "dijit/layout/TabContainer",
  57. "dijit/layout/ContentPane",
  58. "dijit/form/Form",
  59. "dijit/form/Textarea",
  60. "dijit/form/DateTextBox",
  61. "dijit/form/TimeTextBox",
  62. "dijit/form/Button",
  63. "dijit/form/RadioButton",
  64. "dijit/form/Select",
  65. "dijit/Toolbar",
  66. "dijit/ToolbarSeparator",
  67. "dijit/TooltipDialog",
  68. "dijit/form/DropDownButton",
  69. "dijit/Fieldset",
  70. "dojox/form/Uploader",
  71. "dojox/form/uploader/FileList",
  72. "hpcc/TableContainer"
  73. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, dom, domAttr, domClass, domForm, iframe, date, on,
  74. registry, Dialog, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  75. OnDemandGrid, tree, Keyboard, Selection, editor, selector, ColumnResizer, DijitRegistry, Pagination,
  76. _TabContainerWidget, FileSpray, ESPUtil, ESPRequest, ESPDFUWorkunit, HexViewWidget, DFUWUDetailsWidget, TargetSelectWidget, SelectionGridWidget,
  77. template) {
  78. return declare("LZBrowseWidget", [_TabContainerWidget, ESPUtil.FormHelper], {
  79. templateString: template,
  80. baseClass: "LZBrowseWidget",
  81. i18n: lang.mixin(nlsCommon, nlsSpecific),
  82. postCreate: function (args) {
  83. this.inherited(arguments);
  84. this.sprayFixedForm = registry.byId(this.id + "SprayFixedForm");
  85. this.sprayFixedDestinationSelect = registry.byId(this.id + "SprayFixedDestination");
  86. this.sprayFixedGrid = registry.byId(this.id + "SprayFixedGrid");
  87. this.sprayDelimitedForm = registry.byId(this.id + "SprayDelimitedForm");
  88. this.sprayDelimitedDestinationSelect = registry.byId(this.id + "SprayDelimitedDestination");
  89. this.sprayDelimitedGrid = registry.byId(this.id + "SprayDelimitedGrid");
  90. this.sprayXmlForm = registry.byId(this.id + "SprayXmlForm");
  91. this.sprayXmlDestinationSelect = registry.byId(this.id + "SprayXmlDestinationSelect");
  92. this.sprayXmlGrid = registry.byId(this.id + "SprayXmlGrid");
  93. this.sprayVariableForm = registry.byId(this.id + "SprayVariableForm");
  94. this.sprayVariableDestinationSelect = registry.byId(this.id + "SprayVariableDestination");
  95. this.sprayVariableGrid = registry.byId(this.id + "SprayVariableGrid");
  96. this.sprayBlobForm = registry.byId(this.id + "SprayBlobForm");
  97. this.sprayBlobDestinationSelect = registry.byId(this.id + "SprayBlobDestination");
  98. this.sprayBlobGrid = registry.byId(this.id + "SprayBlobGrid");
  99. this.landingZonesTab = registry.byId(this.id + "_LandingZones");
  100. this.uploader = registry.byId(this.id + "Upload");
  101. this.uploadFileList = registry.byId(this.id + "UploadFileList");
  102. this.dropZoneSelect = registry.byId(this.id + "DropZoneTargetSelect");
  103. this.fileListDialog = registry.byId(this.id + "FileListDialog");
  104. var context = this;
  105. this.connect(this.uploader, "onComplete", function () {
  106. context.fileListDialog.hide();
  107. context.refreshGrid();
  108. });
  109. // Workaround for HPCC-9414 --->
  110. this.connect(this.uploader, "onError", function (msg, e) {
  111. if (msg === context.i18n.Errorparsingserverresult + ":") {
  112. context.fileListDialog.hide();
  113. context.refreshGrid();
  114. }
  115. });
  116. // <--- Workaround for HPCC-9414
  117. },
  118. startup: function (args) {
  119. this.inherited(arguments);
  120. },
  121. getTitle: function () {
  122. return this.i18n.title;
  123. },
  124. _handleResponse: function (wuidQualifier, response) {
  125. if (lang.exists(wuidQualifier, response)) {
  126. var wu = ESPDFUWorkunit.Get(lang.getObject(wuidQualifier, false, response));
  127. wu.startMonitor(true);
  128. var tab = this.ensurePane("dfu", this.id + "_" + wu.ID, wu.ID, {
  129. Wuid: wu.ID
  130. });
  131. if (tab) {
  132. this.selectChild(tab);
  133. }
  134. }
  135. },
  136. // Hitched actions ---
  137. _onRefresh: function (event) {
  138. this.refreshGrid();
  139. },
  140. _onUpload: function (event) {
  141. this.uploadFileList.hideProgress();
  142. this.fileListDialog.show();
  143. },
  144. _onDownload: function (event) {
  145. var context = this;
  146. arrayUtil.forEach(this.landingZonesGrid.getSelected(), function (item, idx) {
  147. var downloadIframeName = "downloadIframe_" + item.calculatedID;
  148. var frame = iframe.create(downloadIframeName);
  149. var url = ESPRequest.getBaseURL("FileSpray") + "/DownloadFile?Name=" + encodeURIComponent(item.partialPath) + "&NetAddress=" + item.DropZone.NetAddress + "&Path=" + encodeURIComponent(item.DropZone.Path) + "&OS=" + item.DropZone.OS;
  150. iframe.setSrc(frame, url, true);
  151. });
  152. },
  153. _onDelete: function (event) {
  154. if (confirm(this.i18n.DeleteSelectedFiles)) {
  155. var context = this;
  156. arrayUtil.forEach(this.landingZonesGrid.getSelected(), function(item, idx) {
  157. FileSpray.DeleteDropZoneFile({
  158. request:{
  159. NetAddress: item.DropZone.NetAddress,
  160. Path: item.DropZone.Path,
  161. OS: item.DropZone.OS,
  162. Names: item.partialPath
  163. },
  164. load: function (response) {
  165. context.refreshGrid();
  166. }
  167. });
  168. });
  169. }
  170. },
  171. _onHexPreview: function (event) {
  172. var selections = this.landingZonesGrid.getSelected();
  173. var firstTab = null;
  174. var context = this;
  175. arrayUtil.forEach(selections, function (item, idx) {
  176. var tab = context.ensurePane("hex", context.id + "_" + item.calculatedID, item.displayName, {
  177. logicalFile: item.getLogicalFile()
  178. });
  179. if (firstTab === null) {
  180. firstTab = tab;
  181. }
  182. });
  183. if (firstTab) {
  184. this.selectChild(firstTab);
  185. }
  186. },
  187. _onUploadSubmit: function (event) {
  188. var item = this.dropZoneSelect.get("row");
  189. this.uploader.set("uploadUrl", "/FileSpray/UploadFile.json?upload_&rawxml_=1&NetAddress=" + item.machine.Netaddress + "&OS=" + item.machine.OS + "&Path=" + item.machine.Directory);
  190. this.uploader.upload();
  191. },
  192. _onUploadCancel: function (event) {
  193. registry.byId(this.id + "FileListDialog").hide();
  194. },
  195. _spraySelectedOneAtATime: function (dropDownID, formID, doSpray) {
  196. if (registry.byId(this.id + formID).validate()) {
  197. var selections = this.landingZonesGrid.getSelected();
  198. var context = this;
  199. arrayUtil.forEach(selections, function (item, idx) {
  200. var request = domForm.toObject(context.id + formID);
  201. if (request.namePrefix && !context.endsWith(request.namePrefix, "::")) {
  202. request.namePrefix += "::";
  203. }
  204. lang.mixin(request, {
  205. sourceIP: item.DropZone.NetAddress,
  206. sourcePath: item.fullPath,
  207. sourceRowTag: item.targetRowTag,
  208. destLogicalName: request.namePrefix + item.targetName
  209. });
  210. doSpray(request, item);
  211. });
  212. registry.byId(this.id + dropDownID).closeDropDown();
  213. }
  214. },
  215. _spraySelected: function (dropDownID, formID, doSpray) {
  216. if (registry.byId(this.id + formID).validate()) {
  217. var selections = this.landingZonesGrid.getSelected();
  218. if (selections.length) {
  219. var request = domForm.toObject(this.id + formID);
  220. var item = selections[0];
  221. lang.mixin(request, {
  222. sourceIP: selections[0].DropZone.NetAddress,
  223. nosplit: true
  224. });
  225. var sourcePath = "";
  226. arrayUtil.forEach(selections, function (item, idx) {
  227. if (sourcePath.length)
  228. sourcePath += ",";
  229. sourcePath += item.fullPath;
  230. });
  231. lang.mixin(request, {
  232. sourcePath: sourcePath
  233. });
  234. doSpray(request, item);
  235. registry.byId(this.id + dropDownID).closeDropDown();
  236. }
  237. }
  238. },
  239. _onSprayFixed: function (event) {
  240. var context = this;
  241. this._spraySelectedOneAtATime("SprayFixedDropDown", "SprayFixedForm", function (request, item) {
  242. lang.mixin(request, {
  243. sourceRecordSize: item.targetRecordLength
  244. });
  245. FileSpray.SprayFixed({
  246. request: request
  247. }).then(function (response) {
  248. context._handleResponse("SprayFixedResponse.wuid", response);
  249. });
  250. });
  251. },
  252. _onSprayDelimited: function(event) {
  253. var context = this;
  254. this._spraySelectedOneAtATime("SprayDelimitedDropDown", "SprayDelimitedForm", function (request, item) {
  255. FileSpray.SprayVariable({
  256. request: request
  257. }).then(function (response) {
  258. context._handleResponse("SprayResponse.wuid", response);
  259. });
  260. });
  261. },
  262. _onSprayXml: function(event) {
  263. var context = this;
  264. this._spraySelectedOneAtATime("SprayXmlDropDown", "SprayXmlForm", function (request, item) {
  265. lang.mixin(request, {
  266. sourceRowTag: item.targetRowTag
  267. });
  268. FileSpray.SprayVariable({
  269. request: request
  270. }).then(function (response) {
  271. context._handleResponse("SprayResponse.wuid", response);
  272. });
  273. });
  274. },
  275. _onSprayVariable: function (event) {
  276. var context = this;
  277. this._spraySelectedOneAtATime("SprayVariableDropDown", "SprayVariableForm", function (request, item) {
  278. FileSpray.SprayFixed({
  279. request: request
  280. }).then(function (response) {
  281. context._handleResponse("SprayFixedResponse.wuid", response);
  282. });
  283. });
  284. },
  285. _onSprayBlob: function (event) {
  286. var context = this;
  287. this._spraySelected("SprayBlobDropDown", "SprayBlobForm", function (request, item) {
  288. FileSpray.SprayFixed({
  289. request: request
  290. }).then(function (response) {
  291. context._handleResponse("SprayFixedResponse.wuid", response);
  292. });
  293. });
  294. },
  295. _onRowContextMenu: function (item, colField, mystring) {
  296. },
  297. // Implementation ---
  298. init: function (params) {
  299. if (this.inherited(arguments))
  300. return;
  301. this.initLandingZonesGrid();
  302. this.selectChild(this.landingZonesTab, true);
  303. this.sprayFixedDestinationSelect.init({
  304. Groups: true
  305. });
  306. this.sprayDelimitedDestinationSelect.init({
  307. Groups: true
  308. });
  309. this.sprayXmlDestinationSelect.init({
  310. Groups: true
  311. });
  312. this.sprayVariableDestinationSelect.init({
  313. Groups: true
  314. });
  315. this.sprayBlobDestinationSelect.init({
  316. Groups: true
  317. });
  318. this.dropZoneSelect.init({
  319. DropZones: true
  320. });
  321. },
  322. initTab: function () {
  323. var currSel = this.getSelectedChild();
  324. if (currSel && !currSel.initalized) {
  325. if (currSel.id == this.landingZonesTab.id) {
  326. } else {
  327. if (!currSel.initalized) {
  328. currSel.init(currSel.params);
  329. }
  330. }
  331. }
  332. },
  333. addMenuItem: function (menu, details) {
  334. var menuItem = new MenuItem(details);
  335. menu.addChild(menuItem);
  336. return menuItem;
  337. },
  338. initLandingZonesGrid: function () {
  339. var store = new FileSpray.CreateLandingZonesStore();
  340. this.landingZonesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  341. allowSelectAll: true,
  342. deselectOnRefresh: false,
  343. store: store,
  344. columns: {
  345. col1: selector({
  346. width: 27,
  347. selectorType: 'checkbox',
  348. disabled: function (item) {
  349. if (item.type) {
  350. switch (item.type) {
  351. case "dropzone":
  352. case "folder":
  353. return true;
  354. }
  355. }
  356. return false;
  357. },
  358. sortable: false
  359. }),
  360. displayName: tree({
  361. label: this.i18n.Name,
  362. collapseOnRefresh: true,
  363. sortable: false,
  364. formatter: function (name, row) {
  365. var img = "../files/img/";
  366. if (row.isDir === undefined) {
  367. img += "server.png";
  368. } else if (row.isDir) {
  369. img += "folder.png";
  370. } else {
  371. img += "file.png";
  372. }
  373. return "<img src='" + img + "'/>&nbsp;" + name;
  374. }
  375. }),
  376. filesize: { label: this.i18n.Size, width: 108, sortable: false },
  377. modifiedtime: { label: this.i18n.Date, width: 180, sortable: false }
  378. },
  379. getSelected: function () {
  380. var retVal = [];
  381. var store = FileSpray.CreateFileListStore();
  382. for (var key in this.selection) {
  383. retVal.push(store.get(key));
  384. }
  385. return retVal;
  386. }
  387. }, this.id + "LandingZonesGrid");
  388. this.landingZonesGrid.set("noDataMessage", "<span class='dojoxGridNoData'>" + this.i18n.noDataMessage + "</span>");
  389. var context = this;
  390. this.landingZonesGrid.on(".dgrid-row:contextmenu", function (evt) {
  391. if (context._onRowContextMenu) {
  392. var item = context.landingZonesGrid.row(evt).data;
  393. var cell = context.landingZonesGrid.cell(evt);
  394. var colField = cell.column.field;
  395. var mystring = "item." + colField;
  396. context._onRowContextMenu(item, colField, mystring);
  397. }
  398. });
  399. this.landingZonesGrid.onSelectionChanged(function (event) {
  400. context.refreshActionState();
  401. });
  402. this.landingZonesGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  403. context.refreshActionState();
  404. });
  405. this.landingZonesGrid.startup();
  406. this.sprayFixedGrid.createGrid({
  407. idProperty: "calculatedID",
  408. columns: {
  409. targetName: editor({
  410. label: this.i18n.TargetName,
  411. width: 144,
  412. autoSave: true,
  413. editor: "text"
  414. }),
  415. targetRecordLength: editor({
  416. label: this.i18n.RecordLength,
  417. width: 72,
  418. autoSave: true,
  419. editor: "text"
  420. })
  421. }
  422. });
  423. this.sprayDelimitedGrid.createGrid({
  424. idProperty: "calculatedID",
  425. columns: {
  426. targetName: editor({
  427. label: this.i18n.TargetName,
  428. width: 144,
  429. autoSave: true,
  430. editor: "text"
  431. })
  432. }
  433. });
  434. this.sprayXmlGrid.createGrid({
  435. idProperty: "calculatedID",
  436. columns: {
  437. targetName: editor({
  438. label: this.i18n.TargetName,
  439. width: 144,
  440. autoSave: true,
  441. editor: "text"
  442. }),
  443. targetRowTag: editor({
  444. label: this.i18n.RowTag,
  445. width: 72,
  446. autoSave: true,
  447. editor: "text"
  448. })
  449. }
  450. });
  451. this.sprayVariableGrid.createGrid({
  452. idProperty: "calculatedID",
  453. columns: {
  454. targetName: editor({
  455. label: this.i18n.TargetName,
  456. width: 144,
  457. autoSave: true,
  458. editor: "text"
  459. })
  460. }
  461. });
  462. this.sprayBlobGrid.createGrid({
  463. idProperty: "calculatedID",
  464. columns: {
  465. fullPath: editor({
  466. label: this.i18n.SourcePath,
  467. width: 144,
  468. autoSave: true,
  469. editor: "text"
  470. })
  471. }
  472. });
  473. this.refreshActionState();
  474. },
  475. refreshGrid: function (args) {
  476. this.landingZonesGrid.set("query", {
  477. id: "*"
  478. });
  479. },
  480. refreshActionState: function () {
  481. var selection = this.landingZonesGrid.getSelected();
  482. var hasSelection = selection.length;
  483. registry.byId(this.id + "HexPreview").set("disabled", !hasSelection);
  484. registry.byId(this.id + "Download").set("disabled", !hasSelection);
  485. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  486. registry.byId(this.id + "SprayFixedDropDown").set("disabled", !hasSelection);
  487. registry.byId(this.id + "SprayDelimitedDropDown").set("disabled", !hasSelection);
  488. registry.byId(this.id + "SprayXmlDropDown").set("disabled", !hasSelection);
  489. registry.byId(this.id + "SprayVariableDropDown").set("disabled", !hasSelection);
  490. registry.byId(this.id + "SprayBlobDropDown").set("disabled", !hasSelection);
  491. if (hasSelection) {
  492. var context = this;
  493. var data = [];
  494. arrayUtil.forEach(selection, function (item, idx) {
  495. lang.mixin(item, lang.mixin({
  496. targetName: item.displayName,
  497. targetRecordLength: 1,
  498. targetRowTag: context.i18n.tag
  499. }, item));
  500. data.push(item);
  501. });
  502. this.sprayFixedGrid.setData(data);
  503. this.sprayDelimitedGrid.setData(data);
  504. this.sprayXmlGrid.setData(data);
  505. this.sprayVariableGrid.setData(data);
  506. this.sprayBlobGrid.setData(data);
  507. }
  508. },
  509. ensurePane: function (type, id, title, params) {
  510. var retVal = registry.byId(id);
  511. if (!retVal) {
  512. var context = this;
  513. switch (type) {
  514. case "hex":
  515. retVal = new HexViewWidget({
  516. id: id,
  517. title: title,
  518. closable: true,
  519. params: params
  520. });
  521. break;
  522. case "dfu":
  523. retVal = new DFUWUDetailsWidget.fixCircularDependency({
  524. id: id,
  525. title: title,
  526. closable: true,
  527. params: params
  528. });
  529. break;
  530. }
  531. if (retVal) {
  532. this.addChild(retVal);
  533. }
  534. }
  535. return retVal;
  536. }
  537. });
  538. });