Commit b62670e0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when no name is provided for overlay use filename

parent cfe111ca
......@@ -511,9 +511,17 @@ AddProjectDialog.prototype._createOverlayTable = function () {
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (entry.getType() === "OVERLAY") {
var name = entry.getData().name;
if (name === undefined || name === null || name === "") {
name = entry.getFilename().substring(0, entry.getFilename().lastIndexOf('.'));
if (name.indexOf("/") >= 0) {
name = name.substring(name.lastIndexOf("/") + 1);
}
}
var row = [];
row[0] = entry.getFilename();
row[1] = "<input data='" + entry.getFilename() + "' name='overlayName' value='" + entry.getData().name + "'/>";
row[1] = "<input data='" + entry.getFilename() + "' name='overlayName' value='" + name + "'/>";
row[2] = "<input data='" + entry.getFilename() + "' name='overlayDescription' value='" + entry.getData().description + "'/>";
data.push(row);
}
......@@ -1310,9 +1318,16 @@ AddProjectDialog.prototype.checkValidity = function () {
var mappingExist = 0;
for (i = 0; i < self.getZipEntries().length; i++) {
if (self.getZipEntries()[i].getData().mapping) {
var entry = self.getZipEntries()[i];
if (entry.getData().mapping) {
mappingExist++;
}
if (entry.getType() === "OVERLAY") {
if (entry.getData().name === "" || entry.getData().name === undefined) {
error += "<li>overlay name cannot be empty</li>";
isValid = false;
}
}
}
if (mappingExist > 1) {
error += "<li>only one mapping map can be selected</li>";
......@@ -1342,7 +1357,8 @@ AddProjectDialog.prototype.checkValidity = function () {
return Promise.reject(new ValidationError(error));
}
}).finally(GuiConnector.hideProcessing);
};
}
;
/**
*
......
......@@ -6,6 +6,7 @@ var $ = require('jquery');
var AddProjectDialog = require('../../../../main/js/gui/admin/AddProjectDialog');
var ServerConnector = require('../../ServerConnector-mock');
var ValidationError = require('../../../../main/js/ValidationError');
var ZipEntry = require('../../../../main/js/gui/admin/ZipEntry');
var logger = require('../../logger');
......@@ -353,6 +354,28 @@ describe('AddProjectDialog', function () {
});
});
it('validate overlay data', function () {
var dialog = createDialog();
var file = fs.readFileSync("testFiles/map/complex_model_with_overlays.zip");
file.name = "complex_model_with_submaps.zip";
return dialog.init().then(function () {
dialog.setFileContent("");
return dialog.setZipFileContent(file);
}).then(function () {
dialog.setProjectId("invalid_id");
var entry = new ZipEntry({type: "OVERLAY", filename: "file.txt", data: {name: ""}});
dialog.getZipEntries().push(entry);
return dialog.checkValidity();
}).then(function (isValid) {
assert.notOk("exception expected");
}).catch(function (error) {
assert.ok(error instanceof ValidationError);
}).finally(function () {
return dialog.destroy();
});
});
});
describe('isIgnoredZipEntry', function () {
......
Supports Markdown
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