123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/_base/array",
- "dojo/dom",
- "dojo/dom-attr",
- "dojo/dom-class",
- "dojo/dom-form",
- "dojo/request/iframe",
- "dojo/date",
- "dojo/on",
- "dijit/registry",
- "dijit/Dialog",
- "dijit/Menu",
- "dijit/MenuItem",
- "dijit/MenuSeparator",
- "dijit/PopupMenuItem",
- "dgrid/OnDemandGrid",
- "dgrid/tree",
- "dgrid/Keyboard",
- "dgrid/Selection",
- "dgrid/selector",
- "dgrid/extensions/ColumnResizer",
- "dgrid/extensions/DijitRegistry",
- "dgrid/extensions/Pagination",
- "hpcc/_TabContainerWidget",
- "hpcc/FileSpray",
- "hpcc/ESPUtil",
- "hpcc/ESPRequest",
- "hpcc/ESPDFUWorkunit",
- "hpcc/HexViewWidget",
- "hpcc/DFUWUDetailsWidget",
- "hpcc/TargetSelectWidget",
- "dojo/text!../templates/LZBrowseWidget.html",
- "dijit/layout/BorderContainer",
- "dijit/layout/TabContainer",
- "dijit/layout/ContentPane",
- "dijit/form/Form",
- "dijit/form/Textarea",
- "dijit/form/DateTextBox",
- "dijit/form/TimeTextBox",
- "dijit/form/Button",
- "dijit/form/RadioButton",
- "dijit/form/Select",
- "dijit/Toolbar",
- "dijit/ToolbarSeparator",
- "dijit/TooltipDialog",
- "dijit/form/DropDownButton",
- "dojox/layout/TableContainer",
- "dojox/form/Uploader",
- "dojox/form/uploader/FileList"
- ], function (declare, lang, arrayUtil, dom, domAttr, domClass, domForm, iframe, date, on,
- registry, Dialog, Menu, MenuItem, MenuSeparator, PopupMenuItem,
- OnDemandGrid, tree, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
- _TabContainerWidget, FileSpray, ESPUtil, ESPRequest, ESPDFUWorkunit, HexViewWidget, DFUWUDetailsWidget, TargetSelectWidget,
- template) {
- return declare("LZBrowseWidget", [_TabContainerWidget, ESPUtil.FormHelper], {
- templateString: template,
- baseClass: "LZBrowseWidget",
- landingZonesTab: null,
- landingZonesGrid: null,
- tabMap: [],
- validateDialog: null,
- postCreate: function (args) {
- this.inherited(arguments);
- this.landingZonesTab = registry.byId(this.id + "_LandingZones");
- this.uploader = registry.byId(this.id + "Upload");
- this.uploadFileList = registry.byId(this.id + "UploadFileList");
- this.uploadFileList.uploaderId = this.id + "Upload";
- this.sprayFixedDestinationSelect = registry.byId(this.id + "SprayFixedDestination");
- this.sprayVariableDestinationSelect = registry.byId(this.id + "SprayVariableDestination");
- this.sprayXmlDestinationSelect = registry.byId(this.id + "SprayXmlDestinationSelect");
- this.dropZoneSelect = registry.byId(this.id + "DropZoneTargetSelect");
- this.fileListDialog = registry.byId(this.id + "FileListDialog");
- var context = this;
- this.connect(this.uploader, "onComplete", function () {
- context.fileListDialog.hide();
- context.refreshGrid();
- });
- // Workaround for HPCC-9414 --->
- this.connect(this.uploader, "onError", function (msg, e) {
- if (msg === "Error parsing server result:") {
- context.fileListDialog.hide();
- context.refreshGrid();
- }
- });
- // <--- Workaround for HPCC-9414
- },
- startup: function (args) {
- this.inherited(arguments);
- },
- getTitle: function () {
- return "Landing Zones";
- },
- _handleResponse: function (wuidQualifier, response) {
- if (lang.exists(wuidQualifier, response)) {
- var wu = ESPDFUWorkunit.Get(lang.getObject(wuidQualifier, false, response));
- wu.startMonitor(true);
- var tab = this.ensurePane("dfu", this.id + "_" + wu.ID, wu.ID, {
- Wuid: wu.ID
- });
- if (tab) {
- this.selectChild(tab);
- }
- }
- },
- // Hitched actions ---
- _onRefresh: function (event) {
- this.refreshGrid();
- },
- _onUpload: function (event) {
- this.uploadFileList.hideProgress();
- this.fileListDialog.show();
- },
- _onDownload: function (event) {
- var context = this;
- arrayUtil.forEach(this.landingZonesGrid.getSelected(), function (item, idx) {
- var downloadIframeName = "downloadIframe_" + item.calculatedID;
- var frame = iframe.create(downloadIframeName);
- var url = ESPRequest.getBaseURL("FileSpray") + "/DownloadFile?Name=" + encodeURIComponent(item.partialPath) + "&NetAddress=" + item.DropZone.NetAddress + "&Path=" + encodeURIComponent(item.DropZone.Path) + "&OS=" + item.DropZone.OS;
- iframe.setSrc(frame, url, true);
- });
- },
- _onDelete: function (event) {
- if (confirm('Delete selected files?')) {
- var context = this;
- arrayUtil.forEach(this.landingZonesGrid.getSelected(), function(item, idx) {
- FileSpray.DeleteDropZoneFile({
- request:{
- NetAddress: item.DropZone.NetAddress,
- Path: item.DropZone.Path,
- OS: item.DropZone.OS,
- Names: item.partialPath
- },
- load: function (response) {
- context.refreshGrid();
- }
- });
- });
- }
- },
- _onHexPreview: function (event) {
- var selections = this.landingZonesGrid.getSelected();
- var firstTab = null;
- var context = this;
- arrayUtil.forEach(selections, function (item, idx) {
- var tab = context.ensurePane("hex", context.id + "_" + item.calculatedID, item.displayName, {
- logicalFile: item.getLogicalFile()
- });
- if (firstTab === null) {
- firstTab = tab;
- }
- });
- if (firstTab) {
- this.selectChild(firstTab);
- }
- },
- _onUploadSubmit: function (event) {
- this.uploader.set("uploadUrl", this.uploadUrl);
- this.uploader.upload();
- },
- _onUploadCancel: function (event) {
- registry.byId(this.id + "FileListDialog").hide();
- },
- _onSprayFixed: function (event) {
- var context = this;
- var selections = this.landingZonesGrid.getSelected();
- var context = this;
- arrayUtil.forEach(selections, function (item, idx) {
- var formData = domForm.toObject(context.id + "SprayFixedDialog");
- lang.mixin(formData, {
- sourceIP: item.DropZone.NetAddress,
- sourcePath: item.fullPath
- });
- FileSpray.SprayFixed({
- request: formData
- }).then(function (response) {
- context._handleResponse("SprayFixedResponse.wuid", response);
- })
- });
- registry.byId(this.id + "SprayFixedDropDown").closeDropDown();
- },
- _onSprayFixedCancel: function (event) {
- registry.byId(this.id + "SprayFixedDropDown").closeDropDown();
- },
- _onSprayVariable: function(event) {
- var context = this;
- var selections = this.landingZonesGrid.getSelected();
- var context = this;
- arrayUtil.forEach(selections, function (item, idx) {
- var formData = domForm.toObject(context.id + "SprayVariableDialog");
- lang.mixin(formData, {
- sourceIP: item.DropZone.NetAddress,
- sourcePath: item.DropZone.fullPath
- });
- FileSpray.SprayVariable({
- request: formData
- }).then(function (response) {
- context._handleResponse("SprayResponse.wuid", response);
- });
- });
- registry.byId(this.id + "SprayVariableDropDown").closeDropDown();
- },
- _onSprayVariableCancel: function (event) {
- registry.byId(this.id + "SprayVariableDropDown").closeDropDown();
- },
- _onSprayXml: function(event) {
- var context = this;
- var selections = this.landingZonesGrid.getSelected();
- var context = this;
- arrayUtil.forEach(selections, function (item, idx) {
- var formData = domForm.toObject(context.id + "SprayXmlDialog");
- lang.mixin(formData, {
- sourceIP: item.DropZone.NetAddress,
- sourcePath: item.DropZone.fullPath
- });
- FileSpray.SprayVariable({
- request: formData
- }).then(function (response) {
- context._handleResponse("SprayResponse.wuid", response);
- });
- });
- registry.byId(this.id + "SprayXmlDropDown").closeDropDown();
- },
- _onSprayXmlCancel: function (event) {
- registry.byId(this.id + "SprayXmlDropDown").closeDropDown();
- },
- _onRowDblClick: function (wuid) {
- var wuTab = this.ensurePane(this.id + "_" + wuid, {
- Wuid: wuid
- });
- this.selectChild(wuTab);
- },
- _onRowContextMenu: function (item, colField, mystring) {
- },
- // Implementation ---
- init: function (params) {
- if (this.inherited(arguments))
- return;
- this.initLandingZonesGrid();
- this.selectChild(this.landingZonesTab, true);
- var context = this;
- this.sprayFixedDestinationSelect.init({
- Groups: true
- });
- this.sprayVariableDestinationSelect.init({
- Groups: true
- });
- this.sprayXmlDestinationSelect.init({
- Groups: true
- });
- this.dropZoneSelect.init({
- DropZones: true,
- callback: function (value, item) {
- context.uploadUrl = "/FileSpray/UploadFile.json?upload_&rawxml_=1&NetAddress=" + item.machine.Netaddress + "&OS=" + item.machine.OS + "&Path=" + item.machine.Directory;
- }
- });
-
- },
- initTab: function () {
- var currSel = this.getSelectedChild();
- if (currSel && !currSel.initalized) {
- if (currSel.id == this.landingZonesTab.id) {
- } else {
- if (!currSel.initalized) {
- currSel.init(currSel.params);
- }
- }
- }
- },
- addMenuItem: function (menu, details) {
- var menuItem = new MenuItem(details);
- menu.addChild(menuItem);
- return menuItem;
- },
- initLandingZonesGrid: function () {
- var store = new FileSpray.CreateLandingZonesStore();
- this.landingZonesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
- allowSelectAll: true,
- deselectOnRefresh: false,
- store: store,
- columns: {
- col1: selector({
- width: 27,
- selectorType: 'checkbox',
- disabled: function (item) {
- if (item.type) {
- switch (item.type) {
- case "dropzone":
- case "folder":
- return true;
- }
- }
- return false;
- }
- }),
- displayName: tree({
- label: "Name",
- collapseOnRefresh: true,
- formatter: function (name, row) {
- var img = "../files/img/";
- if (row.isDir === undefined) {
- img += "server.png";
- } else if (row.isDir) {
- img += "folder.png";
- } else {
- img += "file.png";
- }
- return "<img src='" + img + "'/> " + name;
- }
- }),
- filesize: { label: "Size", width: 108 },
- modifiedtime: { label: "Date", width: 180 }
- },
- getSelected: function () {
- var retVal = [];
- var store = FileSpray.CreateFileListStore();
- for (key in this.selection) {
- retVal.push(store.get(key));
- }
- return retVal;
- }
- }, this.id + "LandingZonesGrid");
- this.landingZonesGrid.set("noDataMessage", "<span>Zero Files (Upload Some Files).</span>");
- var context = this;
- on(document, ".WuidClick:click", function (evt) {
- if (context._onRowDblClick) {
- var item = context.landingZonesGrid.row(evt).data;
- context._onRowDblClick(item.Wuid);
- }
- });
- this.landingZonesGrid.on(".dgrid-row:dblclick", function (evt) {
- if (context._onRowDblClick) {
- var item = context.landingZonesGrid.row(evt).data;
- context._onRowDblClick(item.Wuid);
- }
- });
- this.landingZonesGrid.on(".dgrid-row:contextmenu", function (evt) {
- if (context._onRowContextMenu) {
- var item = context.landingZonesGrid.row(evt).data;
- var cell = context.landingZonesGrid.cell(evt);
- var colField = cell.column.field;
- var mystring = "item." + colField;
- context._onRowContextMenu(item, colField, mystring);
- }
- });
- this.landingZonesGrid.onSelectionChanged(function (event) {
- context.refreshActionState();
- });
- this.landingZonesGrid.onContentChanged(function (object, removedFrom, insertedInto) {
- context.refreshActionState();
- });
- this.landingZonesGrid.startup();
- this.refreshActionState();
- },
- refreshGrid: function (args) {
- this.landingZonesGrid.set("query", {
- id: "*"
- });
- },
- refreshActionState: function () {
- var selection = this.landingZonesGrid.getSelected();
- var hasSelection = selection.length;
- registry.byId(this.id + "HexPreview").set("disabled", !hasSelection);
- registry.byId(this.id + "Download").set("disabled", !hasSelection);
- registry.byId(this.id + "Delete").set("disabled", !hasSelection);
- registry.byId(this.id + "SprayFixedDropDown").set("disabled", !hasSelection);
- registry.byId(this.id + "SprayVariableDropDown").set("disabled", !hasSelection);
- registry.byId(this.id + "SprayXmlDropDown").set("disabled", !hasSelection);
- },
- ensurePane: function (type, id, title, params) {
- var retVal = registry.byId(id);
- if (!retVal) {
- var context = this;
- switch (type) {
- case "hex":
- retVal = new HexViewWidget({
- id: id,
- title: title,
- closable: true,
- params: params
- });
- break;
- case "dfu":
- retVal = new DFUWUDetailsWidget.fixCircularDependency({
- id: id,
- title: title,
- closable: true,
- params: params
- });
- break;
- }
- if (retVal) {
- this.addChild(retVal);
- }
- }
- return retVal;
- }
- });
- });
|