From b773a880a3776478c0ab2282b230c999adc9867c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 1 Oct 2018 17:36:05 +0200 Subject: [PATCH] when opening project window data in the popup is refreshed --- .../main/js/gui/admin/EditProjectDialog.js | 89 ++++++++++++------- .../src/main/js/gui/admin/MapsAdminPanel.js | 4 +- .../test/js/gui/admin/MapsAdminPanel-test.js | 34 +++++++ 3 files changed, 94 insertions(+), 33 deletions(-) diff --git a/frontend-js/src/main/js/gui/admin/EditProjectDialog.js b/frontend-js/src/main/js/gui/admin/EditProjectDialog.js index 109a71b2f8..e58edeb518 100644 --- a/frontend-js/src/main/js/gui/admin/EditProjectDialog.js +++ b/frontend-js/src/main/js/gui/admin/EditProjectDialog.js @@ -87,7 +87,6 @@ EditProjectDialog.prototype.createGui = function () { */ EditProjectDialog.prototype.createGeneralTabContent = function () { var self = this; - var project = self.getProject(); var result = Functions.createElement({ type: "div", @@ -113,7 +112,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function () { projectIdRow.appendChild(Functions.createElement({ type: "div", style: "display:table-cell", - content: project.getProjectId() + name: "projectId" })); var mapCanvasTypeRow = Functions.createElement({ @@ -169,7 +168,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function () { nameRow.appendChild(Functions.createElement({ type: "div", style: "display:table-cell", - content: "<input name='projectName' value='" + xss(project.getName()) + "'/>", + content: "<input name='projectName'/>", xss: false })); @@ -186,7 +185,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function () { versionRow.appendChild(Functions.createElement({ type: "div", style: "display:table-cell", - content: "<input name='projectVersion' value='" + xss(project.getVersion()) + "'/>", + content: "<input name='projectVersion'/>", xss: false })); @@ -200,14 +199,10 @@ EditProjectDialog.prototype.createGeneralTabContent = function () { style: "display:table-cell", content: "Disease" })); - var disease = ""; - if (project.getDisease() !== undefined) { - disease = xss(project.getDisease().getResource()); - } diseaseRow.appendChild(Functions.createElement({ type: "div", style: "display:table-cell", - content: "<input name='projectDisease' value='" + disease + "'/>", + content: "<input name='projectDisease'/>", xss: false })); @@ -221,14 +216,10 @@ EditProjectDialog.prototype.createGeneralTabContent = function () { style: "display:table-cell", content: "Organism" })); - var organism = ""; - if (project.getOrganism() !== undefined) { - organism = xss(project.getOrganism().getResource()); - } organismRow.appendChild(Functions.createElement({ type: "div", style: "display:table-cell", - content: "<input name='projectOrganism' value='" + organism + "'/>", + content: "<input name='projectOrganism'/>", xss: false })); @@ -242,14 +233,10 @@ EditProjectDialog.prototype.createGeneralTabContent = function () { style: "display:table-cell", content: "Notify email" })); - var email = ""; - if (project.getNotifyEmail() !== undefined) { - email = xss(project.getNotifyEmail()); - } emailRow.appendChild(Functions.createElement({ type: "div", style: "display:table-cell", - content: "<input name='projectNotifyEmail' value='" + email + "'/>", + content: "<input name='projectNotifyEmail'/>", xss: false })); @@ -525,9 +512,59 @@ EditProjectDialog.prototype.createUserPrivilegeColumns = function () { */ EditProjectDialog.prototype.init = function () { var self = this; + var select = $("[name='project-map-canvas-type']", self.getElement())[0]; + var licenceCheckbox = $("[name='project-google-maps-license']", self.getElement())[0]; + var licenceDiv = licenceCheckbox.parentElement.parentElement; + + $(select).change(function () { + $("option:selected", select).each(function () { + if ($(this).val() === "GOOGLE_MAPS_API") { + $(licenceDiv).css("display", "table-row"); + } else { + $(licenceDiv).css("display", "none"); + } + self.setLicenseAccepted(false); + }); + }); + return self.initUsersTab().then(function () { - return self.refreshUsers(); + return self.refresh() }).then(function () { + $(window).trigger('resize'); + }); +}; + +/** + * + * @returns {Promise} + */ +EditProjectDialog.prototype.refresh = function () { + var self = this; + var element = self.getElement(); + var project = self.getProject(); + $("[name='projectName']", element).val(xss(project.getName())); + $("[name='projectId']", element).val(project.getProjectId()); + $("[name='projectVersion']", element).val(xss(project.getVersion())); + + var disease = ""; + if (project.getDisease() !== undefined) { + disease = xss(project.getDisease().getResource()); + } + $("[name='projectDisease']", element).val(disease); + var organism = ""; + if (project.getOrganism() !== undefined) { + organism = xss(project.getOrganism().getResource()); + } + $("[name='projectOrganism']", element).val(organism); + + var email = ""; + if (project.getNotifyEmail() !== undefined) { + email = xss(project.getNotifyEmail()); + } + $("[name='projectNotifyEmail']", element).val(email); + + + return self.refreshUsers().then(function () { return self.refreshMaps(); }).then(function () { return self.refreshOverlays(); @@ -559,18 +596,6 @@ EditProjectDialog.prototype.init = function () { } select.appendChild(option); } - $(select).change(function () { - $("option:selected", select).each(function () { - if ($(this).val() === "GOOGLE_MAPS_API") { - $(licenceDiv).css("display", "table-row"); - } else { - $(licenceDiv).css("display", "none"); - } - self.setLicenseAccepted(false); - }); - }); - - $(window).trigger('resize'); }); }; diff --git a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js index 6de38bff30..e6b503e605 100644 --- a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js @@ -425,7 +425,9 @@ MapsAdminPanel.prototype.getDialog = function (project) { return dialog; }); } else { - return Promise.resolve(dialog); + return dialog.refresh().then(function () { + return Promise.resolve(dialog); + }); } }; diff --git a/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js b/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js index 970db1e3b3..bb98eef61d 100644 --- a/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js +++ b/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js @@ -73,4 +73,38 @@ describe('MapsAdminPanel', function () { }); }); + describe('showEditDialog', function () { + it('default', function () { + var mapTab = createMapsAdminPanel(); + return mapTab.init().then(function () { + return mapTab.showEditDialog("sample"); + }).then(function () { + return mapTab.destroy(); + }); + }); + it('reopen after data changed', function () { + var mapTab = createMapsAdminPanel(); + var originalFunction = ServerConnector.getProject; + return mapTab.init().then(function () { + return mapTab.showEditDialog("sample"); + }).then(function () { + return ServerConnector.getProject("sample"); + }).then(function (project) { + project.setName("new name"); + ServerConnector.getProject = function () { + return Promise.resolve(project); + }; + return mapTab.showEditDialog("sample"); + }).then(function () { + var inputs = $('input').filter(function () { + return this.value === 'new name' + }); + assert.ok(inputs.length > 0, "Data wasn't updated after reopening popup"); + return mapTab.destroy(); + }).finally(function () { + ServerConnector.getProject = originalFunction; + }); + }); + }); + }); -- GitLab