Commit 3b80906b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

name of uploaded overlay is trimmed of xetension and temporary path

parent 2e2d4c48
......@@ -16,8 +16,8 @@ function OverlayPanel(params) {
params.panelName = "overlays";
params.scrollable = true;
params.helpTip = "<p>Overlays tab allows to display or generate custom coloring of elements and interactions in the map.</p>"
+ "<p>General overlays are overlays accessible for every user viewing the content.</p>"
+ "<p>Custom overlays are user-provided overlays, this menu becomes available upon login (see below).</p>";
+ "<p>General overlays are overlays accessible for every user viewing the content.</p>"
+ "<p>Custom overlays are user-provided overlays, this menu becomes available upon login (see below).</p>";
Panel.call(this, params);
var self = this;
......@@ -26,7 +26,7 @@ function OverlayPanel(params) {
var addButton = this.getControlElement(PanelControlElementType.OVERLAY_ADD_OVERLAY_BUTTON);
addButton.onclick = function() {
addButton.onclick = function () {
self.openAddOverlayDialog();
};
......@@ -38,70 +38,70 @@ function OverlayPanel(params) {
OverlayPanel.prototype = Object.create(Panel.prototype);
OverlayPanel.prototype.constructor = OverlayPanel;
OverlayPanel.prototype._createOverlayPanelGui = function() {
OverlayPanel.prototype._createOverlayPanelGui = function () {
var generalOverlaysDiv = Functions.createElement({
type : "div",
name : "generalOverlays",
className : "searchPanel"
type: "div",
name: "generalOverlays",
className: "searchPanel"
});
this.getElement().appendChild(generalOverlaysDiv);
this.setControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_DIV, generalOverlaysDiv);
var generalOverlaysTitle = Functions.createElement({
type : "h5",
content : "GENERAL OVERLAYS:"
type: "h5",
content: "GENERAL OVERLAYS:"
});
generalOverlaysDiv.appendChild(generalOverlaysTitle);
var generalOverlaysTableDiv = Functions.createElement({
type : "table",
name : "generalOverlaysTab",
className : "table table-bordered",
style : "width:100%"
type: "table",
name: "generalOverlaysTab",
className: "table table-bordered",
style: "width:100%"
});
generalOverlaysDiv.appendChild(generalOverlaysTableDiv);
this.setControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE, generalOverlaysTableDiv);
var customOverlaysDiv = Functions.createElement({
type : "div",
name : "customOverlays",
className : "searchPanel"
type: "div",
name: "customOverlays",
className: "searchPanel"
});
this.getElement().appendChild(customOverlaysDiv);
this.setControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_DIV, customOverlaysDiv);
var customOverlaysTitle = Functions.createElement({
type : "h5",
name : "customOverlaysTitle",
content : "USER-PROVIDED OVERLAYS:"
type: "h5",
name: "customOverlaysTitle",
content: "USER-PROVIDED OVERLAYS:"
});
customOverlaysDiv.appendChild(customOverlaysTitle);
this.setControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TITLE, customOverlaysTitle);
var customOverlaysTableDiv = Functions.createElement({
type : "table",
name : "customOverlaysTab",
className : "table table-bordered",
style : "width:100%"
type: "table",
name: "customOverlaysTab",
className: "table table-bordered",
style: "width:100%"
});
customOverlaysDiv.appendChild(customOverlaysTableDiv);
this.setControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TABLE, customOverlaysTableDiv);
var centerTag = Functions.createElement({
type : "center"
type: "center"
});
customOverlaysDiv.appendChild(centerTag);
var addOverlayButton = Functions.createElement({
type : "button",
name : "addOverlay",
content : "Add overlay"
type: "button",
name: "addOverlay",
content: "Add overlay"
});
centerTag.appendChild(addOverlayButton);
this.setControlElement(PanelControlElementType.OVERLAY_ADD_OVERLAY_BUTTON, addOverlayButton);
};
OverlayPanel.prototype.clear = function() {
OverlayPanel.prototype.clear = function () {
var table = this.getControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE);
while (table.firstChild) {
table.removeChild(table.firstChild);
......@@ -114,7 +114,7 @@ OverlayPanel.prototype.clear = function() {
};
OverlayPanel.prototype.createTableHeader = function(edit) {
OverlayPanel.prototype.createTableHeader = function (edit) {
var result = document.createElement("thead");
var row = document.createElement("tr");
......@@ -141,7 +141,7 @@ OverlayPanel.prototype.createTableHeader = function(edit) {
return result;
};
OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
OverlayPanel.prototype.createOverlayRow = function (overlay, checked) {
var self = this;
var guiUtils = self.getGuiUtils();
var result = document.createElement("tr");
......@@ -159,7 +159,7 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = checked;
checkbox.onclick = function() {
checkbox.onclick = function () {
if (this.checked) {
return self.getMap().openDataOverlay(overlay.getId()).then(null, GuiConnector.alert);
} else {
......@@ -171,7 +171,7 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
var img = guiUtils.createIcon("icons/search.png");
var link = document.createElement("a");
link.href = "#";
link.onclick = function() {
link.onclick = function () {
self.getMap().openDataOverlay(overlay.getId());
$(result).addClass('active').siblings().removeClass('active');
};
......@@ -184,10 +184,10 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
if (overlay.getInputDataAvailable()) {
var button = document.createElement("button");
button.setAttribute("name", "download-overlay-" + overlay.getId());
button.onclick = function() {
button.onclick = function () {
return ServerConnector.getOverlaySourceDownloadUrl({
overlayId : overlay.getId()
}).then(function(url) {
overlayId: overlay.getId()
}).then(function (url) {
return self.downloadFile(url);
}).then(null, GuiConnector.alert);
};
......@@ -201,7 +201,7 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
var editTd = document.createElement("td");
var editButton = document.createElement("button");
editButton.setAttribute("name", "editButton");
editButton.onclick = function() {
editButton.onclick = function () {
self.openEditOverlayDialog(overlay);
};
editButton.innerHTML = "<span class='ui-icon ui-icon-document'></span>";
......@@ -212,147 +212,147 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
return result;
};
OverlayPanel.prototype.openEditOverlayDialog = function(overlay) {
OverlayPanel.prototype.openEditOverlayDialog = function (overlay) {
var self = this;
var guiUtils = self.getGuiUtils();
var content = document.createElement("fieldset");
var nameInput = guiUtils.createInputText(overlay.getName());
var row = guiUtils.createTableRow([ guiUtils.createLabel("Name: "), nameInput ]);
var row = guiUtils.createTableRow([guiUtils.createLabel("Name: "), nameInput]);
content.appendChild(row);
var descriptionInput = guiUtils.createTextArea(overlay.getDescription());
row = guiUtils.createTableRow([ guiUtils.createLabel("Description: "), descriptionInput ]);
row = guiUtils.createTableRow([guiUtils.createLabel("Description: "), descriptionInput]);
content.appendChild(row);
var buttons = [ {
text : "SAVE",
click : function() {
var buttons = [{
text: "SAVE",
click: function () {
var windowSelf = this;
return ServerConnector.updateOverlay({
overlayId : overlay.id,
name : nameInput.value,
description : descriptionInput.value
}).then(function() {
overlayId: overlay.id,
name: nameInput.value,
description: descriptionInput.value
}).then(function () {
return self.refresh();
}).then(function() {
}).then(function () {
$(windowSelf).dialog("close");
}).then(null, GuiConnector.alert);
}
}, {
text : "REMOVE",
click : function() {
text: "REMOVE",
click: function () {
self.getMap().removeSelectedLayout(overlay.getId());
var windowSelf = this;
return ServerConnector.removeOverlay({
overlayId : overlay.getId()
}).then(function() {
overlayId: overlay.getId()
}).then(function () {
return self.refresh();
}).then(function() {
}).then(function () {
$(windowSelf).dialog("close");
}).then(null, GuiConnector.alert);
}
}, {
text : "CANCEL",
click : function() {
text: "CANCEL",
click: function () {
$(this).dialog("close");
}
} ];
}];
self.openDialog(content, {
id : overlay.getId(),
buttons : buttons,
title : "Data overlay: " + overlay.getName(),
className : "minerva-overlay-dialog",
id: overlay.getId(),
buttons: buttons,
title: "Data overlay: " + overlay.getName(),
className: "minerva-overlay-dialog",
});
};
OverlayPanel.prototype.refresh = function() {
OverlayPanel.prototype.refresh = function () {
var self = this;
var user = null;
var overlayTypes = [];
var selectedOverlay = [];
return ServerConnector.getOverlayTypes().then(function(types) {
return ServerConnector.getOverlayTypes().then(function (types) {
overlayTypes = types;
return ServerConnector.getLoggedUser();
}).then(function(loggedUser) {
}).then(function (loggedUser) {
user = loggedUser;
return self.getMap().getVisibleDataOverlays();
}).then(function(visibleDataOverlays) {
}).then(function (visibleDataOverlays) {
for (var j = 0; j < visibleDataOverlays.length; j++) {
selectedOverlay[visibleDataOverlays[j].getId()] = true;
}
return ServerConnector.getOverlays();
}).then(
function(customOverlays) {
function (customOverlays) {
var id = self.getMap().getGoogleMap().getMapTypeId().substring(2);
selectedOverlay[id] = true;
var id = self.getMap().getGoogleMap().getMapTypeId().substring(2);
selectedOverlay[id] = true;
self.clear();
self.clear();
var generalOverlays = [];
var overlay;
var generalOverlays = [];
var overlay;
var overlays = self.getMap().getLayouts();
for (var i = 0; i < overlays.length; i++) {
overlay = overlays[i];
if (overlay.getCreator() === undefined || overlay.getCreator() === "") {
generalOverlays.push(overlay);
}
var overlays = self.getMap().getLayouts();
for (var i = 0; i < overlays.length; i++) {
overlay = overlays[i];
if (overlay.getCreator() === undefined || overlay.getCreator() === "") {
generalOverlays.push(overlay);
}
}
var table = self.getControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE);
table.appendChild(self.createTableHeader());
var table = self.getControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE);
table.appendChild(self.createTableHeader());
var body = document.createElement("tbody");
table.appendChild(body);
for (i = 0; i < generalOverlays.length; i++) {
overlay = generalOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()]));
}
var body = document.createElement("tbody");
table.appendChild(body);
for (i = 0; i < generalOverlays.length; i++) {
overlay = generalOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()]));
}
var title = self.getControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TITLE);
var addButton = self.getControlElement(PanelControlElementType.OVERLAY_ADD_OVERLAY_BUTTON);
if (user.getLogin() === "anonymous") {
title.innerHTML = 'YOU ARE NOT LOGGED IN. PLEASE, <a href="#">LOG IN</a>'
+ 'TO UPLOAD AND VIEW CUSTOM OVERLAYS<br/><center><button>LOGIN</button></center>';
var openLoginDialog = function() {
return self.getParent().getLoginDialog().open();
};
$(title).find("a")[0].onclick = openLoginDialog;
$(title).find("button")[0].onclick = openLoginDialog;
addButton.style.display = "none";
} else {
title.innerHTML = self.getCustomOverlaysMessage();
addButton.style.display = "block";
var title = self.getControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TITLE);
var addButton = self.getControlElement(PanelControlElementType.OVERLAY_ADD_OVERLAY_BUTTON);
if (user.getLogin() === "anonymous") {
title.innerHTML = 'YOU ARE NOT LOGGED IN. PLEASE, <a href="#">LOG IN</a>'
+ 'TO UPLOAD AND VIEW CUSTOM OVERLAYS<br/><center><button>LOGIN</button></center>';
var openLoginDialog = function () {
return self.getParent().getLoginDialog().open();
};
$(title).find("a")[0].onclick = openLoginDialog;
$(title).find("button")[0].onclick = openLoginDialog;
addButton.style.display = "none";
} else {
title.innerHTML = self.getCustomOverlaysMessage();
addButton.style.display = "block";
table = self.getControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TABLE);
table.appendChild(self.createTableHeader(true));
table = self.getControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TABLE);
table.appendChild(self.createTableHeader(true));
body = document.createElement("tbody");
table.appendChild(body);
for (i = 0; i < customOverlays.length; i++) {
overlay = customOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()]));
}
body = document.createElement("tbody");
table.appendChild(body);
for (i = 0; i < customOverlays.length; i++) {
overlay = customOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()]));
}
}
self.onresize();
});
self.onresize();
});
};
OverlayPanel.prototype.setCustomOverlaysMessage = function(customOverlaysMessage) {
OverlayPanel.prototype.setCustomOverlaysMessage = function (customOverlaysMessage) {
this._customOverlaysMessage = customOverlaysMessage;
};
OverlayPanel.prototype.getCustomOverlaysMessage = function() {
OverlayPanel.prototype.getCustomOverlaysMessage = function () {
return this._customOverlaysMessage;
};
OverlayPanel.prototype.parseFile = function(fileContent) {
OverlayPanel.prototype.parseFile = function (fileContent) {
var result = {};
var lines = fileContent.split("\n");
for (var i = 0; i < lines.length; i++) {
......@@ -378,7 +378,7 @@ OverlayPanel.prototype.parseFile = function(fileContent) {
return result;
};
OverlayPanel.prototype.openAddOverlayDialog = function() {
OverlayPanel.prototype.openAddOverlayDialog = function () {
var self = this;
var guiUtils = self.getGuiUtils();
var fileContent = null;
......@@ -399,13 +399,13 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
content.appendChild(guiUtils.createLabel("Upload file: "));
var fileInput = guiUtils.createFileButton();
fileInput.addEventListener("change", function() {
fileInput.addEventListener("change", function () {
fileContent = null;
var file = fileInput.files[0];
if (file) {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function(evt) {
reader.onload = function (evt) {
fileContent = evt.target.result;
var data = self.parseFile(fileContent);
if (data.name !== undefined) {
......@@ -413,7 +413,10 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
} else {
var filename = fileInput.value;
if (filename.indexOf(".") > 0) {
filename.substr(0, filename.indexOf(".") - 1);
filename = filename.substr(0, filename.indexOf("."));
}
if (filename.lastIndexOf("\\") >= 0) {
filename = filename.substr(filename.lastIndexOf("\\") + 1);
}
nameInput.value = filename;
}
......@@ -421,7 +424,7 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
descriptionInput.value = data.description;
}
};
reader.onerror = function() {
reader.onerror = function () {
GuiConnector.alert("Problem reading file");
};
}
......@@ -435,9 +438,9 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
content.appendChild(contentInput);
content.appendChild(guiUtils.createNewLine());
var buttons = [ {
text : "UPLOAD",
click : function() {
var buttons = [{
text: "UPLOAD",
click: function () {
var dialog = this;
if (contentInput.value !== undefined && contentInput.value !== null) {
contentInput.value = contentInput.value.trim();
......@@ -449,19 +452,19 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
GuiConnector.alert("Neither file was selected nor data was enterd");
} else {
var data = {
name : nameInput.value,
description : descriptionInput.value,
content : fileContent,
filename : fileInput.value
name: nameInput.value,
description: descriptionInput.value,
content: fileContent,
filename: fileInput.value
};
GuiConnector.showProcessing();
return ServerConnector.addOverlay(data).then(function(overlay) {
return ServerConnector.addOverlay(data).then(function (overlay) {
self.getMap().getModel().addLayout(overlay);
return self.refresh();
}).then(function() {
}).then(function () {
GuiConnector.hideProcessing();
$(dialog).dialog("close");
}, function(error) {
}, function (error) {
GuiConnector.hideProcessing();
if (error instanceof NetworkError) {
if (error.statusCode === HttpStatus.BAD_REQUEST) {
......@@ -477,19 +480,19 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
}
}
}, {
text : "CANCEL",
click : function() {
text: "CANCEL",
click: function () {
$(this).dialog("close");
}
} ];
}];
self.openDialog(content, {
id : "addOverlay",
modal : true,
buttons : buttons,
id: "addOverlay",
modal: true,
buttons: buttons,
});
};
OverlayPanel.prototype.init = function() {
OverlayPanel.prototype.init = function () {
return this.refresh();
};
module.exports = OverlayPanel;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment