diff --git a/frontend-js/src/main/css/global.css b/frontend-js/src/main/css/global.css index c72de9f83c7cbc4dc258674be5bef70f29f49d7c..b6304476ec3ff9aa6b514b556979258d57345d41 100644 --- a/frontend-js/src/main/css/global.css +++ b/frontend-js/src/main/css/global.css @@ -515,6 +515,22 @@ h1 { margin: 5px; } +.minerva-edit-project-dialog .tab-pane { + overflow: auto; +} + +.minerva-edit-project-dialog > .parentTabs { + position: absolute; + top: 10px; + bottom: 40px; + left: 10px; + right: 10px +} + +.minerva-edit-project-dialog > .parentTabs > .tab-content { + height: 100%; +} + .minerva-no-close .ui-dialog-titlebar-close { display: none } diff --git a/frontend-js/src/main/js/gui/admin/AddProjectDialog.js b/frontend-js/src/main/js/gui/admin/AddProjectDialog.js index 00bf2533ae0ecf84245cac06d1d360302d7eab3e..c3c79221e18ce603f331f65360db27a913b218a4 100644 --- a/frontend-js/src/main/js/gui/admin/AddProjectDialog.js +++ b/frontend-js/src/main/js/gui/admin/AddProjectDialog.js @@ -21,6 +21,15 @@ var guiUtils = new (require('../leftPanel/GuiUtils'))(); var UserPreferences = require("../../map/data/UserPreferences"); var ValidationError = require("../../ValidationError"); +/** + * + * @param params + * @param {HTMLElement} params.element + * @param {Configuration} params.configuration + * @param {ServerConnector} params.serverConnector + * @constructor + * @extends {AbstractGuiElement} + */ function AddProjectDialog(params) { AbstractGuiElement.call(this, params); var self = this; @@ -37,93 +46,45 @@ function AddProjectDialog(params) { AddProjectDialog.prototype = Object.create(AbstractGuiElement.prototype); AddProjectDialog.prototype.constructor = AddProjectDialog; +/** + * + */ AddProjectDialog.prototype.createGui = function () { var self = this; - var element = self.getElement(); - var tabDiv = Functions.createElement({ - type: "div", - name: "tabView", - className: "tabbable boxed parentTabs", - style: "position:absolute;top:10px;bottom:40px;left:10px;right:10px" - }); - element.appendChild(tabDiv); - - var tabMenuDiv = Functions.createElement({ - type: "ul", - className: "nav nav-tabs" - }); - tabDiv.appendChild(tabMenuDiv); - - var tabContentDiv = Functions.createElement({ - type: "div", - className: "tab-content", - style: "height:100%" - }); - tabDiv.appendChild(tabContentDiv); - - self.createGeneralTab(tabMenuDiv, tabContentDiv); - self.createOverlaysTab(tabMenuDiv, tabContentDiv); - self.createSubmapsTab(tabMenuDiv, tabContentDiv); - self.createOverviewImagesTab(tabMenuDiv, tabContentDiv); - - - $("a", tabMenuDiv).bind("click", function () { - //workaround for some css issues... - tabDiv.style.top = "40px"; - tabDiv.style.bottom = "10px"; - }); -}; + guiUtils.initTabContent(self); -AddProjectDialog.prototype.createGeneralTab = function (tabMenuDiv, tabContentDiv) { - var self = this; - self.addTab({ - tabMenuDiv: tabMenuDiv, - tabContentDiv: tabContentDiv, + guiUtils.addTab(self, { name: "GENERAL", - id: "add_project_general_tab", content: self.createGeneralTabContent() }); - -}; - -AddProjectDialog.prototype.addTab = function (params) { - var navLi = guiUtils.createTabMenuObject({ - id: params.id, - name: params.name, - navigationBar: params.tabMenuDiv + guiUtils.addTab(self, { + name: "OVERLAYS", + content: self.createOverlaysTabContent(), + disabled: true }); - params.tabMenuDiv.appendChild(navLi); - - - var contentDiv = guiUtils.createTabContentObject({ - id: params.id, - navigationObject: navLi, - navigationBar: params.tabMenuDiv + guiUtils.addTab(self, { + name: "SUBMAPS", + content: self.createSubmapsTabContent(), + disabled: true + }); + guiUtils.addTab(self, { + name: "IMAGES", + content: self.createOverviewImagesTabContent(), + disabled: true }); - contentDiv.style.overflow = "auto"; - - - if (params.content !== undefined) { - contentDiv.appendChild(params.content); - } - - params.tabContentDiv.appendChild(contentDiv); - - if (params.disabled) { - this.disableTab(params); - } -}; - -AddProjectDialog.prototype.disableTab = function (params) { - $("a[href='#" + params.id + "']", this.getElement()).hide(); -}; -AddProjectDialog.prototype.enableTab = function (params) { - $("a[href='#" + params.id + "']", this.getElement()).show(); + $(".nav-tabs > li > a", self.getElement()).bind("click", function () { + //workaround for some css issues... + $(".parentTabs", self.getElement()).css("top", "40px"); + $(".parentTabs", self.getElement()).css("bottom", "10px"); + }); }; - +/** + * + * @returns {Promise} + */ AddProjectDialog.prototype.showAnnotatorsDialog = function () { var self = this; var promise; @@ -142,6 +103,11 @@ AddProjectDialog.prototype.showAnnotatorsDialog = function () { return self._annotatorsDialog.open(); }); }; + +/** + * + * @returns {Promise} + */ AddProjectDialog.prototype.showValidatorsDialog = function () { var self = this; var promise; @@ -160,11 +126,17 @@ AddProjectDialog.prototype.showValidatorsDialog = function () { return self._validatorsDialog.open(); }); }; + +/** + * + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createGeneralTabContent = function () { var self = this; var result = Functions.createElement({ - type: "div" + type: "div", + className: "minerva-project-general-tab" }); var table = Functions.createElement({ @@ -351,6 +323,16 @@ AddProjectDialog.prototype.createGeneralTabContent = function () { return result; }; + +/** + * + * @param {string} [params.defaultValue=""] + * @param {string} params.labelName + * @param {string} params.inputName + * @param {string} [params.help] + * + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createInputRow = function (params) { if (params.defaultValue === undefined) { params.defaultValue = ""; @@ -373,6 +355,15 @@ AddProjectDialog.prototype.createInputRow = function (params) { return this.createRow(elements); }; +/** + * + * @param {string} params.labelName + * @param {boolean} [params.defaultValue=false] + * @param {string} params.inputName + * @param {HTMLElement[]} [params.elements] + * @param {string} [params.help] + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createCheckboxRow = function (params) { var labelName = params.labelName; var defaultValue = params.defaultValue; @@ -411,6 +402,11 @@ AddProjectDialog.prototype.createCheckboxRow = function (params) { return this.createRow(rowElements); }; +/** + * + * @param {HTMLElement[]} elements + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createRow = function (elements) { var result = Functions.createElement({ type: "div", @@ -435,27 +431,25 @@ AddProjectDialog.prototype.createRow = function (elements) { return result; }; -AddProjectDialog.prototype.createOverlaysTab = function (tabMenuDiv, tabContentDiv) { - var self = this; - self.addTab({ - tabMenuDiv: tabMenuDiv, - tabContentDiv: tabContentDiv, - name: "OVERLAYS", - id: "project_overlays_tab", - content: self.createOverlaysTabContent(), - disabled: true - }); -}; - +/** + * + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createOverlaysTabContent = function () { var self = this; var result = Functions.createElement({ - type: "div" + type: "div", + className: "minerva-project-overlays-tab" }); result.appendChild(self._createOverlayTable()); return result; }; +/** + * + * @returns {HTMLElement} + * @private + */ AddProjectDialog.prototype._createOverlayTable = function () { var self = this; var result = Functions.createElement({ @@ -513,22 +507,15 @@ AddProjectDialog.prototype._createOverlayTable = function () { return result; }; -AddProjectDialog.prototype.createSubmapsTab = function (tabMenuDiv, tabContentDiv) { - var self = this; - self.addTab({ - tabMenuDiv: tabMenuDiv, - tabContentDiv: tabContentDiv, - name: "SUBMAPS", - id: "project_submaps_tab", - content: self.createSubmapsTabContent(), - disabled: true - }); -}; - +/** + * + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createSubmapsTabContent = function () { var self = this; var result = Functions.createElement({ type: "div", + className: "minerva-project-submaps-tab", style: "margin-top:10px;" }); var submapsTable = Functions.createElement({ @@ -596,85 +583,75 @@ AddProjectDialog.prototype.createSubmapsTabContent = function () { $(submapsTable).on("change", "[name='submapType']", function () { var input = this; var filename = $(input).attr("data"); - return ServerConnector.getConfiguration().then(function (configuration) { - var mapTypes = configuration.getMapTypes(); - for (var j = 0; j < mapTypes.length; j++) { - var mapType = mapTypes[j]; - if (mapType.id === $(input).val()) { - self.getEntryByFilename(filename).getData().type = mapType; - } + var configuration = self.getConfiguration(); + var mapTypes = configuration.getMapTypes(); + for (var j = 0; j < mapTypes.length; j++) { + var mapType = mapTypes[j]; + if (mapType.id === $(input).val()) { + self.getEntryByFilename(filename).getData().type = mapType; } - }); + } }); self.addListener("onZipFileUpload", function () { - return ServerConnector.getConfiguration().then(function (configuration) { - - var entries = self.getZipEntries(); - var dataTable = $($("[name='submapsTable']", self.getElement())[0]).DataTable(); - var data = []; - for (var i = 0; i < entries.length; i++) { - var entry = entries[i]; - if (entry.getType() === "MAP") { - var row = []; - var rootCheckbox; - if (entry.getData().root) { - rootCheckbox = "<input name='submapRoot' type='checkbox' data='" + entry.getFilename() + "' checked='checked'/>"; - } else { - rootCheckbox = "<input name='submapRoot' type='checkbox' data='" + entry.getFilename() + "'/>"; - } - var mappingCheckbox; - if (entry.getData().mapping) { - mappingCheckbox = "<input name='submapMapping' type='checkbox' data='" + entry.getFilename() + "' checked='checked'/>"; - } else { - mappingCheckbox = "<input name='submapMapping' type='checkbox' data='" + entry.getFilename() + "'/>"; - } + var configuration = self.getConfiguration(); + var entries = self.getZipEntries(); + var dataTable = $($("[name='submapsTable']", self.getElement())[0]).DataTable(); + var data = []; + for (var i = 0; i < entries.length; i++) { + var entry = entries[i]; + if (entry.getType() === "MAP") { + var row = []; + var rootCheckbox; + if (entry.getData().root) { + rootCheckbox = "<input name='submapRoot' type='checkbox' data='" + entry.getFilename() + "' checked='checked'/>"; + } else { + rootCheckbox = "<input name='submapRoot' type='checkbox' data='" + entry.getFilename() + "'/>"; + } + var mappingCheckbox; + if (entry.getData().mapping) { + mappingCheckbox = "<input name='submapMapping' type='checkbox' data='" + entry.getFilename() + "' checked='checked'/>"; + } else { + mappingCheckbox = "<input name='submapMapping' type='checkbox' data='" + entry.getFilename() + "'/>"; + } - var typeSelect = "<select data='" + entry.getFilename() + "' name='submapType'>"; + var typeSelect = "<select data='" + entry.getFilename() + "' name='submapType'>"; - typeSelect += "<option value='" + entry.getData().type.id + "' selected>" + entry.getData().type.name + "</option>"; - var mapTypes = configuration.getMapTypes(); - for (var j = 0; j < mapTypes.length; j++) { - var mapType = mapTypes[j]; - if (mapType !== entry.getData().type) { - typeSelect += "<option value='" + mapType.id + "' >" + mapType.name + "</option>"; - } + typeSelect += "<option value='" + entry.getData().type.id + "' selected>" + entry.getData().type.name + "</option>"; + var mapTypes = configuration.getMapTypes(); + for (var j = 0; j < mapTypes.length; j++) { + var mapType = mapTypes[j]; + if (mapType !== entry.getData().type) { + typeSelect += "<option value='" + mapType.id + "' >" + mapType.name + "</option>"; } - typeSelect += "</select>"; + } + typeSelect += "</select>"; - row[0] = entry.getFilename(); - row[1] = "<input data='" + entry.getFilename() + "' name='submapName' value='" + entry.getData().name + "'/>"; - row[2] = rootCheckbox; - row[3] = mappingCheckbox; - row[4] = typeSelect; - data.push(row); - } + row[0] = entry.getFilename(); + row[1] = "<input data='" + entry.getFilename() + "' name='submapName' value='" + entry.getData().name + "'/>"; + row[2] = rootCheckbox; + row[3] = mappingCheckbox; + row[4] = typeSelect; + data.push(row); } - dataTable.clear().rows.add(data).draw(); - }); + } + dataTable.clear().rows.add(data).draw(); }); return result; }; -AddProjectDialog.prototype.createOverviewImagesTab = function (tabMenuDiv, tabContentDiv) { - var self = this; - self.addTab({ - tabMenuDiv: tabMenuDiv, - tabContentDiv: tabContentDiv, - name: "IMAGES", - id: "project_overview_images_tab", - content: self.createOverviewImagesTabContent(), - disabled: true - }); -}; - +/** + * + * @returns {HTMLElement} + */ AddProjectDialog.prototype.createOverviewImagesTabContent = function () { var self = this; var result = Functions.createElement({ type: "div", - style: "margin-top:10px;" + style: "margin-top:10px;", + className: "minerva-project-overview-images-tab" }); var imagesTable = Functions.createElement({ @@ -715,14 +692,13 @@ AddProjectDialog.prototype.createOverviewImagesTabContent = function () { */ AddProjectDialog.prototype.init = function () { var self = this; - return ServerConnector.getConfiguration().then(function (configuration) { - var select = $("[name='project-format']", self.getElement())[0]; - self._fillProjectFormatSelectOptions(select, configuration); - - select = $("[name='project-map-canvas-type']", self.getElement())[0]; - self._fillMapCanvasTypeSelectOptions(select, configuration); - return ServerConnector.getLoggedUser(); - }).then(function (user) { + var configuration = self.getConfiguration(); + var select = $("[name='project-format']", self.getElement())[0]; + self._fillProjectFormatSelectOptions(select, configuration); + + select = $("[name='project-map-canvas-type']", self.getElement())[0]; + self._fillMapCanvasTypeSelectOptions(select, configuration); + return self.getServerConnector().getLoggedUser().then(function (user) { self.setNotifyEmail(user.getEmail()); self.bindProjectUploadPreferences(user, "annotateModel", "project-annotate-automatically"); self.bindProjectUploadPreferences(user, "autoResize", "project-auto-margin"); @@ -799,7 +775,12 @@ AddProjectDialog.prototype._fillMapCanvasTypeSelectOptions = function (select, c }); }; - +/** + * + * @param {User} user + * @param {string} type + * @param {string} elementName + */ AddProjectDialog.prototype.bindProjectUploadPreferences = function (user, type, elementName) { var element = $("[name='" + elementName + "']", this.getElement()); @@ -813,6 +794,9 @@ AddProjectDialog.prototype.bindProjectUploadPreferences = function (user, type, }); }; +/** + * + */ AddProjectDialog.prototype.destroy = function () { var self = this; var div = self.getElement(); @@ -841,6 +825,9 @@ AddProjectDialog.prototype.destroy = function () { }; +/** + * + */ AddProjectDialog.prototype.open = function () { var self = this; var div = self.getElement(); @@ -854,11 +841,18 @@ AddProjectDialog.prototype.open = function () { $(div).dialog("open"); }; +/** + * + */ AddProjectDialog.prototype.close = function () { var self = this; $(self.getElement()).dialog("close"); }; +/** + * + * @returns {Promise} + */ AddProjectDialog.prototype.clear = function () { var self = this; $("input", self.getElement()).val(""); @@ -866,9 +860,14 @@ AddProjectDialog.prototype.clear = function () { return Promise.resolve(); }; +/** + * + * @param file + * @returns {Promise} + */ AddProjectDialog.prototype.processFile = function (file) { var self = this; - self.setFileContent(null); + self.setFileContent(undefined); if (file) { return new Promise(function (resolve, reject) { var reader = new FileReader(); @@ -890,10 +889,18 @@ AddProjectDialog.prototype.processFile = function (file) { } }; +/** + * + * @param {string|undefined} fileContent + */ AddProjectDialog.prototype.setFileContent = function (fileContent) { this._fileContent = fileContent; }; +/** + * + * @param {boolean} isLicenseAccepted + */ AddProjectDialog.prototype.setLicenseAccepted = function (isLicenseAccepted) { $("[name='project-google-maps-license']", this.getElement()).prop("checked", isLicenseAccepted); }; @@ -906,10 +913,18 @@ AddProjectDialog.prototype.isLicenseAccepted = function () { return $("[name='project-google-maps-license']", this.getElement()).is(":checked"); }; +/** + * + * @returns {string|undefined} + */ AddProjectDialog.prototype.getFileContent = function () { return this._fileContent; }; +/** + * + * @param {string} projectId + */ AddProjectDialog.prototype.setProjectId = function (projectId) { $("[name='project-id']", this.getElement()).val(projectId); }; @@ -932,75 +947,137 @@ AddProjectDialog.prototype.getMapCanvasTypeId = function () { return $("[name='project-map-canvas-type']", this.getElement()).val(); }; - +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getProjectId = function () { return $("[name='project-id']", this.getElement()).val(); }; +/** + * + * @param {string} name + */ AddProjectDialog.prototype.setName = function (name) { $("[name='project-name']", this.getElement()).val(name); }; + +/** + * + * @param {string} email + */ AddProjectDialog.prototype.setNotifyEmail = function (email) { $("[name='project-notify-email']", this.getElement()).val(email); }; +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getName = function () { return $("[name='project-name']", this.getElement()).val(); }; +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getDisease = function () { return $("[name='project-disease']", this.getElement()).val(); }; + +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getOrganism = function () { return $("[name='project-organism']", this.getElement()).val(); }; + +/** + * + * @param {string} organism + */ AddProjectDialog.prototype.setOrganism = function (organism) { $("[name='project-organism']", this.getElement()).val(organism); }; +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getVersion = function () { return $("[name='project-version']", this.getElement()).val(); }; + +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getNotifyEmail = function () { return $("[name='project-notify-email']", this.getElement()).val(); }; + +/** + * + * @returns {boolean} + */ AddProjectDialog.prototype.isAnnotateAutomatically = function () { return $("[name='project-annotate-automatically']", this.getElement()).is(':checked'); }; -AddProjectDialog.prototype.setAnnotateAutomatically = function (value) { - $("[name='project-annotate-automatically']", this.getElement()).prop('checked', value); -}; + +/** + * + * @returns {boolean} + */ AddProjectDialog.prototype.isVerifyAnnotations = function () { return $("[name='project-verify-annotations']", this.getElement()).is(':checked'); }; -AddProjectDialog.prototype.setVerifyAnnotations = function (value) { - $("[name='project-verify-annotations']", this.getElement()).prop('checked', value); -}; + +/** + * + * @returns {boolean} + */ AddProjectDialog.prototype.isCache = function () { return $("[name='project-cache-data']", this.getElement()).is(':checked'); }; + +/** + * + * @param {boolean} value + */ AddProjectDialog.prototype.setCache = function (value) { return $("[name='project-cache-data']", this.getElement()).prop('checked', value).trigger("change"); }; +/** + * + * @returns {boolean} + */ AddProjectDialog.prototype.isAutoMargin = function () { return $("[name='project-auto-margin']", this.getElement()).is(':checked'); }; -AddProjectDialog.prototype.setAutoMargin = function (value) { - $("[name='project-auto-margin']", this.getElement()).prop('checked', value); -}; + +/** + * + * @returns {boolean} + */ AddProjectDialog.prototype.isSbgn = function () { return $("[name='project-sbgn-visualization']", this.getElement()).is(':checked'); }; -AddProjectDialog.prototype.setSbgn = function (value) { - $("[name='project-sbgn-visualization']", this.getElement()).prop('checked', value); -}; + +/** + * + * @returns {boolean} + */ AddProjectDialog.prototype.isSemanticZooming = function () { return $("[name='project-semantic-zooming']", this.getElement()).is(':checked'); }; -AddProjectDialog.prototype.setSemanticZooming = function (value) { - $("[name='project-semantic-zooming']", this.getElement()).prop('checked', value); -}; +/** + * + * @param {string} filename + */ AddProjectDialog.prototype.setFileParserForFilename = function (filename) { var self = this; self._filename = filename; @@ -1018,20 +1095,24 @@ AddProjectDialog.prototype.setFileParserForFilename = function (filename) { } options[optionId].selected = true; }; + +/** + * + * @returns {*} + */ AddProjectDialog.prototype.getConverter = function () { var self = this; var select = $("[name='project-format']", self.getElement)[0]; - return ServerConnector.getConfiguration().then(function (configuration) { - var handler = select.options[select.selectedIndex].value; - var converters = configuration.getModelConverters(); - for (var i = 0; i < converters.length; i++) { - var converter = converters[i]; - if (handler === converter.handler) { - return converter; - } + var configuration = self.getConfiguration(); + var handler = select.options[select.selectedIndex].value; + var converters = configuration.getModelConverters(); + for (var i = 0; i < converters.length; i++) { + var converter = converters[i]; + if (handler === converter.handler) { + return converter; } - return null; - }); + } + return null; }; /** @@ -1048,7 +1129,7 @@ AddProjectDialog.prototype.onSaveClicked = function () { parserClass = converter.handler; } GuiConnector.showProcessing("Uploading..."); - return ServerConnector.uploadFile({filename: self._filename, content: self.getFileContent()}); + return self.getServerConnector().uploadFile({filename: self._filename, content: self.getFileContent()}); }).then(function (file) { var options = { "projectId": self.getProjectId(), @@ -1076,6 +1157,10 @@ AddProjectDialog.prototype.onSaveClicked = function () { }); }; +/** + * + * @returns {Promise} + */ AddProjectDialog.prototype.checkValidity = function () { var self = this; var isValid = true; @@ -1089,22 +1174,21 @@ AddProjectDialog.prototype.checkValidity = function () { } } - if (self.getFileContent() === null || self.getFileContent() === undefined) { + if (self.getFileContent() === undefined) { error += "<li>Please select file before uploading</li>"; isValid = false; } - return self.getConverter().then(function (converter) { - if (converter === null) { - error += "<li>Please select converter before uploading</li>"; - isValid = false; - } - var projectId = self.getProjectId(); - if (!(/^[a-z0-9A-Z\-_]+$/.test(projectId))) { - error += "<li>projectId can contain only alphanumeric characters and -_</li>"; - isValid = false; - } - return ServerConnector.getProject(self.getProjectId()); - }).then(function (project) { + var converter = self.getConverter(); + if (converter === null) { + error += "<li>Please select converter before uploading</li>"; + isValid = false; + } + var projectId = self.getProjectId(); + if (!(/^[a-z0-9A-Z\-_]+$/.test(projectId))) { + error += "<li>projectId can contain only alphanumeric characters and -_</li>"; + isValid = false; + } + return self.getServerConnector().getProject(self.getProjectId()).then(function (project) { if (project !== null) { error += "<li>Project with given id already exists</li>"; isValid = false; @@ -1118,6 +1202,11 @@ AddProjectDialog.prototype.checkValidity = function () { }); }; +/** + * + * @param file + * @returns {Promise} + */ AddProjectDialog.prototype.setZipFileContent = function (file) { var self = this; if (file.name.toLowerCase().endsWith("zip")) { @@ -1151,32 +1240,39 @@ AddProjectDialog.prototype.setZipFileContent = function (file) { } } if (overlays > 0) { - self.enableTab({id: "project_overlays_tab"}); + guiUtils.showTab(self, $(".minerva-project-overlays-tab", self.getElement())[0]); } else { - self.disableTab({id: "project_overlays_tab"}); + guiUtils.hideTab(self, $(".minerva-project-overlays-tab", self.getElement())[0]); } if (maps > 1) { - self.enableTab({id: "project_submaps_tab"}); + guiUtils.showTab(self, $(".minerva-project-submaps-tab", self.getElement())[0]); } else { - self.disableTab({id: "project_submaps_tab"}); + guiUtils.hideTab(self, $(".minerva-project-submaps-tab", self.getElement())[0]); } if (images > 1) { - self.enableTab({id: "project_overview_images_tab"}); + guiUtils.showTab(self, $(".minerva-project-overview-images-tab", self.getElement())[0]); } else { - self.disableTab({id: "project_overview_images_tab"}); + guiUtils.hideTab(self, $(".minerva-project-overview-images-tab", self.getElement())[0]); } return self.setZipEntries(entries); }); } else { - self.disableTab({id: "project_overlays_tab"}); - self.disableTab({id: "project_submaps_tab"}); - self.disableTab({id: "project_overview_images_tab"}); + guiUtils.hideTab(self, $(".minerva-project-overlays-tab", self.getElement())[0]); + guiUtils.hideTab(self, $(".minerva-project-submaps-tab", self.getElement())[0]); + guiUtils.hideTab(self, $(".minerva-project-overview-images-tab", self.getElement())[0]); return self.setZipEntries([]); } }; +/** + * + * @param jsZipEntry + * @param zipObject + * @returns {Promise} + */ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) { + var self = this; if (jsZipEntry.dir) { return null; } @@ -1230,17 +1326,16 @@ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) { data.name = name; processingPromise = processingPromise.then(function () { - return ServerConnector.getConfiguration().then(function (configuration) { - var mapTypes = configuration.getMapTypes(); - for (var i = 0; i < mapTypes.length; i++) { - if (mapTypes[i].id === "UNKNOWN") { - data.type = mapTypes[i]; - } - } - if (data.type === undefined) { - data.type = mapTypes[0]; + var configuration = self.getConfiguration(); + var mapTypes = configuration.getMapTypes(); + for (var i = 0; i < mapTypes.length; i++) { + if (mapTypes[i].id === "UNKNOWN") { + data.type = mapTypes[i]; } - }); + } + if (data.type === undefined) { + data.type = mapTypes[0]; + } }); } @@ -1253,16 +1348,30 @@ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) { }); }; +/** + * + * @returns {Array} + */ AddProjectDialog.prototype.getZipEntries = function () { return this._zipEntries; }; + +/** + * + * @param entries + * @returns {PromiseLike|Promise} + */ AddProjectDialog.prototype.setZipEntries = function (entries) { var self = this; self._zipEntries = entries; return self.callListeners("onZipFileUpload", entries); - }; +/** + * + * @param {string} filename + * @returns {boolean} + */ AddProjectDialog.prototype.isIgnoredZipEntry = function (filename) { var lowercaseString = filename.toLowerCase(); // noinspection SpellCheckingInspection @@ -1274,6 +1383,11 @@ AddProjectDialog.prototype.isIgnoredZipEntry = function (filename) { return false; }; +/** + * + * @param filename + * @returns {ZipEntry} + */ AddProjectDialog.prototype.getEntryByFilename = function (filename) { var self = this; var entries = self.getZipEntries(); @@ -1286,6 +1400,10 @@ AddProjectDialog.prototype.getEntryByFilename = function (filename) { return null; }; +/** + * + * @returns {string} + */ AddProjectDialog.prototype.getFilename = function () { return this._filename; }; diff --git a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js index 65deeac5baf2f2fa5a10b750909e66bd201da28b..d391cdac1efdb11072edae34bb31ec5b06263fe3 100644 --- a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js +++ b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js @@ -980,8 +980,10 @@ GuiUtils.prototype.initTabContent = function (abstractGuiElement) { * @param {AbstractGuiElement} abstractGuiElement * @param {Object} params * @param {string} params.name + * @param {HTMLElement} [params.content] + * @param {boolean} [params.disabled = false] + * @param {function} [params.panelClass] * @param {Object} [params.options] - optional parameters passed to the panel constructor - * @param {function} params.panelClass */ GuiUtils.prototype.addTab = function (abstractGuiElement, params) { var tabId = "panel_tab_" + tabIdCounter; @@ -1004,20 +1006,67 @@ GuiUtils.prototype.addTab = function (abstractGuiElement, params) { contentElement.appendChild(contentDiv); - var options = { - element: contentDiv, - name: params.name, - configuration: this.getConfiguration(), - serverConnector: abstractGuiElement.getServerConnector(), - customMap: abstractGuiElement.getMap(), - project: abstractGuiElement.getProject() - }; + if (params.content !== undefined) { + contentDiv.appendChild(params.content); + if (params.disabled) { + this.hideTab(abstractGuiElement, params.content); + } + } else { + + var options = { + element: contentDiv, + name: params.name, + configuration: this.getConfiguration(), + serverConnector: abstractGuiElement.getServerConnector(), + customMap: abstractGuiElement.getMap(), + project: abstractGuiElement.getProject() + }; - if (params.options !== undefined) { - options = jQuery.extend(options, params.options); + if (params.options !== undefined) { + options = jQuery.extend(options, params.options); + } + + var panel = new params.panelClass(options); + abstractGuiElement._panels.push(panel); + + if (params.disabled) { + this.hideTab(abstractGuiElement, panel); + } + } +}; + +/** + * + * @param {Panel|HTMLElement} panel + * @returns {string} + */ +function getPanelId(panel) { + var panelId; + if (Functions.isDomElement(panel)) { + if (panel.className.indexOf("tab-pane") >= 0) { + panelId = panel.id; + } else { + panelId = panel.parentNode.id; + } + } else { + panelId = panel.getElement().id; } + return panelId; +} - abstractGuiElement._panels.push(new params.panelClass(options)); +/** + * + * @param {AbstractGuiElement} abstractGuiElement + * @param {Panel|HTMLElement} panel + */ +GuiUtils.prototype.hideTab = function (abstractGuiElement, panel) { + var panelId = getPanelId(panel); + var liElement = $("li:has(a[href='#" + panelId + "'])", $(abstractGuiElement.getElement()))[0]; + if (liElement !== undefined) { + $(liElement).hide(); + } else { + logger.warn("Cannot find tab link for panel: " + panel); + } }; /** @@ -1025,12 +1074,13 @@ GuiUtils.prototype.addTab = function (abstractGuiElement, params) { * @param {AbstractGuiElement} abstractGuiElement * @param {Panel} panel */ -GuiUtils.prototype.hideTab = function (abstractGuiElement, panel) { - var liElement = $("li:has(a[href='#" + panel.getElement().id + "'])", $(abstractGuiElement.getElement()))[0]; +GuiUtils.prototype.showTab = function (abstractGuiElement, panel) { + var panelId = getPanelId(panel); + var liElement = $("li:has(a[href='#" + panelId + "'])", $(abstractGuiElement.getElement()))[0]; if (liElement !== undefined) { - liElement.style.display = "none"; + $(liElement).show(); } else { - logger.warn("Cannot find tab link for panel: " + panel.getPanelName()); + logger.warn("Cannot find tab link for panel: " + panel); } };