From 6a4e36c4f7f58d1ac1faf31507c6acec8c2b6e5d Mon Sep 17 00:00:00 2001 From: juanf <juanf> Date: Fri, 28 Feb 2014 14:39:57 +0000 Subject: [PATCH] BIS-675 / SP-1214 : ELN UI - Ask to save changes if work can be lost (Adding pattern to change views + bugfixes) SVN: 30793 --- .../1/as/webapps/newbrowser/html/index.html | 2 +- .../html/js/controllers/MainController.js | 169 ++++++++++++------ .../newbrowser/html/js/views/Inspector.js | 11 +- .../newbrowser/html/js/views/MainMenu.js | 2 +- .../newbrowser/html/js/views/SampleForm.js | 9 +- .../html/js/views/SampleHierarchy.js | 2 +- .../newbrowser/html/js/views/SampleTable.js | 30 +--- .../html/js/widgets/DataSetViewer.js | 2 +- .../html/js/widgets/NavigationBar.js | 11 +- 9 files changed, 133 insertions(+), 105 deletions(-) diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html index 787c09a14d6..05a0cb508a7 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html @@ -46,7 +46,7 @@ <script type="text/javascript" src="./js/config/Profile.js"></script> - <script type="text/javascript" src="./js/api/ServerFacade.js"></script> + <script type="text/javascript" src="./js/server/ServerFacade.js"></script> <script type="text/javascript" src="./js/util/Util.js"></script> <script type="text/javascript" src="./js/util/BlockScrollUtil.js"></script> diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js index 59e53fa7543..5ea2f47ca82 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js @@ -90,7 +90,7 @@ function MainController(profile) { localReference.navigationBar = new NavigationBar(localReference, "sectionsContainer", null, localReference.profile.menuStructure); localReference.navigationBar.repaint(); - localReference.showMainMenu(); + localReference.changeView("showMainMenu", null); Util.unblockUI(); //Get datastores for automatic DSS configuration, the first one will be used @@ -111,10 +111,67 @@ function MainController(profile) { } // - // Functions that trigger view Changes + // Main View Changer - Everything on the application rely on this method to alter the views // + this.changeView = function(newViewChange, arg) { + + // + // Dirty forms management, to avoid loosing changes. + // + var discardChanges = null; + if( this.currentView && + this.currentView.isDirty && + this.currentView.isDirty()) { + //Ask the user if wants to leave the view in case is dirty + discardChanges = window.confirm("Leaving this window will discard any changes, are you sure?"); + } + + if(discardChanges != null && !discardChanges) { + return; + } + // + // + // + + switch (newViewChange) { + case "showInspectors": + this._showInspectors(); + break; + case "showMainMenu": + this._showMainMenu(); + break; + case "showSearchPage": + this._showSearchPage(arg); + break; + case "showSamplesPage": + this.navigationBar.updateBreadCrumbToSecondLevel(); + this._showSamplesPage(arg); + break; + case "showSampleHierarchyPage": + this._showSampleHierarchyPage(arg); + break; + case "showCreateSamplePage": + this._showCreateSamplePage(arg); + break; + case "showEditSamplePage": + this._showEditSamplePage(arg); + break; + case "showViewSamplePageFromPermId": + this._showViewSamplePageFromPermId(arg); + break; + case "showCreateDataSetPage": + this._showCreateDataSetPage(arg); + break; + default: + window.alert("The system tried to create a non existing view"); + break; + } + } - this.showInspectors = function() { + // + // Functions that trigger view changes, should only be called from the main controller changeView method + // + this._showInspectors = function() { //Update menu this.navigationBar.updateMenu(null); @@ -124,7 +181,7 @@ function MainController(profile) { history.pushState(null, "", ""); //History Push State } - this.showMainMenu = function() { + this._showMainMenu = function() { //Update menu var breadCrumbPage = new BreadCrumbPage('main-menu', 'showMainMenu', null, 'Main Menu'); this.navigationBar.updateBreadCrumbPage(breadCrumbPage); @@ -137,7 +194,7 @@ function MainController(profile) { history.pushState(null, "", ""); //History Push State } - this.showSamplesPage = function(sampleTypeCode) { + this._showSamplesPage = function(sampleTypeCode) { //Update menu var sampleType = this.profile.getTypeForTypeCode(sampleTypeCode); var sampleTypeDisplayName = sampleType.description; @@ -156,53 +213,14 @@ function MainController(profile) { history.pushState(null, "", ""); //History Push State } - this.lastSearchId = 0; //Used to discard search responses that don't pertain to the last search call. - - this.showSearchPage = function(event) { - //Only search with at least 3 characters - if(event.target.value.length < 3) { - return; - } - - this.lastSearchId++; - var localSearchId = this.lastSearchId; - var localReference = this; - - var possibleSearch = function() { - if(localSearchId === localReference.lastSearchId) { //Trigger it if no new have started - //Clean page and update menu - localReference.navigationBar.updateMenu(null); - - //Update Main Container - var sampleTable = new SampleTable(localReference.serverFacade, "mainContainer", localReference.profile, localReference.profile.searchType["TYPE"], true, false, false, true, false, localReference.inspector); - $("#search").addClass("search-query-searching"); - localReference.serverFacade.searchWithText(event.target.value, function(data) { - if(localSearchId === localReference.lastSearchId) { - $("#search").removeClass("search-query-searching"); - sampleTable.reloadWithSamples(data); - localReference.currentView = sampleTable; - Util.unblockUI(); - history.pushState(null, "", ""); //History Push State - } else { - //Discard old response, was triggered but a new one was started - } - }); - } else { - //Discard it - } - } - - setTimeout(possibleSearch, 800); - } - - this.showSampleHierarchyPage = function(sample) { - //Update menu - var breadCrumbPage = new BreadCrumbPage('sample-hierarchy-'+sample.permId, "showSampleHierarchyPage", sample, 'Hierarchy '+sample.code); - this.navigationBar.updateBreadCrumbPage(breadCrumbPage); + this._showSampleHierarchyPage = function(permId) { //Show View var localInstance = this; - this.serverFacade.searchWithUniqueId(sample.permId, function(data) { + this.serverFacade.searchWithUniqueId(permId, function(data) { + var breadCrumbPage = new BreadCrumbPage('sample-hierarchy-'+data[0].permId, "showSampleHierarchyPage", data[0].permId, 'Hierarchy '+data[0].code); + localInstance.navigationBar.updateBreadCrumbPage(breadCrumbPage); + var sampleHierarchy = new SampleHierarchy(localInstance.serverFacade, localInstance.inspector, "mainContainer", localInstance.profile, data[0]); sampleHierarchy.init(); localInstance.currentView = sampleHierarchy; @@ -210,7 +228,7 @@ function MainController(profile) { }); } - this.showCreateSamplePage = function(sampleTypeCode) { + this._showCreateSamplePage = function(sampleTypeCode) { //Update menu var sampleTypeDisplayName = this.profile.getTypeForTypeCode(sampleTypeCode).description; if(sampleTypeDisplayName === null) { @@ -227,7 +245,7 @@ function MainController(profile) { history.pushState(null, "", ""); //History Push State } - this.showEditSamplePage = function(sample) { + this._showEditSamplePage = function(sample) { //Update menu var breadCrumbPage = new BreadCrumbPage('edit-sample-'+sample.permId, "showEditSamplePage", sample, 'Update '+sample.code); this.navigationBar.updateBreadCrumbPage(breadCrumbPage); @@ -243,11 +261,11 @@ function MainController(profile) { }); } - this.showViewSamplePageFromPermId = function(permId) { + this._showViewSamplePageFromPermId = function(permId) { var localInstance = this; this.serverFacade.searchWithUniqueId(permId, function(data) { //Update menu - var breadCrumbPage = new BreadCrumbPage('view-sample-'+data[0].permId, "showViewSamplePage", data[0], 'View '+data[0].code); + var breadCrumbPage = new BreadCrumbPage('view-sample-'+data[0].permId, "showViewSamplePageFromPermId", data[0].permId, 'View '+data[0].code); localInstance.navigationBar.updateBreadCrumbPage(breadCrumbPage); //Show Form @@ -259,11 +277,7 @@ function MainController(profile) { }); } - this.showViewSamplePage = function(sample) { - this.showViewSamplePageFromPermId(sample.permId); - } - - this.showCreateDataSetPage = function(sample) { + this._showCreateDataSetPage = function(sample) { //Update menu var breadCrumbPage = new BreadCrumbPage('new-dataset-'+sample.permId, "showCreateDataSetPage", sample, 'Create Data Set for '+sample.code); this.navigationBar.updateBreadCrumbPage(breadCrumbPage); @@ -274,4 +288,43 @@ function MainController(profile) { this.currentView = datasetForm; history.pushState(null, "", ""); //History Push State } + + this.lastSearchId = 0; //Used to discard search responses that don't pertain to the last search call. + + this._showSearchPage = function(event) { + //Only search with at least 3 characters + if(event.target.value.length < 3) { + return; + } + + this.lastSearchId++; + var localSearchId = this.lastSearchId; + var localReference = this; + + var possibleSearch = function() { + if(localSearchId === localReference.lastSearchId) { //Trigger it if no new have started + //Clean page and update menu + localReference.navigationBar.updateMenu(null); + + //Update Main Container + var sampleTable = new SampleTable(localReference.serverFacade, "mainContainer", localReference.profile, localReference.profile.searchType["TYPE"], true, false, false, true, false, localReference.inspector); + $("#search").addClass("search-query-searching"); + localReference.serverFacade.searchWithText(event.target.value, function(data) { + if(localSearchId === localReference.lastSearchId) { + $("#search").removeClass("search-query-searching"); + sampleTable.reloadWithSamples(data); + localReference.currentView = sampleTable; + Util.unblockUI(); + history.pushState(null, "", ""); //History Push State + } else { + //Discard old response, was triggered but a new one was started + } + }); + } else { + //Discard it + } + } + + setTimeout(possibleSearch, 800); + } } diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/Inspector.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/Inspector.js index 282d09fa0ed..2b743a3c138 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/Inspector.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/Inspector.js @@ -109,15 +109,6 @@ function Inspector(serverFacade, containerId, profile) { this.repaint(); } - this.showViewSamplePage = function(entityPermId) { - for(var i = 0; i < this.inspectedSamples.length; i++) { - if(this.inspectedSamples[i].permId === entityPermId) { - mainController.showViewSamplePage(this.inspectedSamples[i]); - break; - } - } - } - this.printInspector = function(entityPermId) { var newWindow = window.open(null,"print " + entityPermId); @@ -273,7 +264,7 @@ function Inspector(serverFacade, containerId, profile) { if(withLinks) { var printButton = "<span class='btn inspectorToolbar' style='float:right; margin: 2px;' onclick='mainController.inspector.printInspector(\""+entity.permId+"\")'><i class='icon-print'></i></span>"; inspector += printButton; - var viewButton = "<span class='btn inspectorToolbar' style='float:right; margin: 2px' onclick='mainController.inspector.showViewSamplePage(\""+entity.permId+"\")'><i class='icon-eye-open'></i></span>"; + var viewButton = "<span class='btn inspectorToolbar' style='float:right; margin: 2px' onclick='mainController.changeView(\"showViewSamplePageFromPermId\",\""+entity.permId+"\")'><i class='icon-edit'></i></span>"; inspector += viewButton; } diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/MainMenu.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/MainMenu.js index 26f6a3470d2..ebdddbcc1a0 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/MainMenu.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/MainMenu.js @@ -55,7 +55,7 @@ function MainMenu(mainController, containerId, menuStructure, mainMenuContentExt //this is necessary to avoid using the same menuItem reference in all clicks var onClick = function(menuItem) { return function() { - localReference.mainController[menuItem.href](menuItem.hrefArgs); + localReference.mainController.changeView(menuItem.href, menuItem.hrefArgs); } } diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js index e5db36093bc..dec0545c43e 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js @@ -49,6 +49,11 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod this.sample = sample; this.storage = null; this.dataSetViewer = null; + this.isDirty = false; + + this.isDirty = function() { + return this.isDirty; + } this.init = function() { Util.blockUI(); @@ -303,7 +308,7 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod } this.getEditButton = function() { - return "<a id='editButton' class='btn'><i class='icon-edit'></i></a>"; + return "<a id='editButton' class='btn'><i class='icon-edit'></i> Enable Editing</a>"; } this.enableEditButtonEvent = function() { @@ -312,7 +317,7 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod //localReference.mode = SampleFormMode.EDIT; //localReference.init(); mainController.navigationBar.updateBreadCrumbToMinusOne(); - mainController.showEditSamplePage(sample); + mainController.changeView('showEditSamplePage',sample); }); } diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchy.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchy.js index a936621ea9f..cee3eb5b2a2 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchy.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchy.js @@ -313,7 +313,7 @@ function SampleHierarchy(serverFacade, inspector, containerId, profile, sample) 'style' : 'cursor:pointer', })); - var $sampleLink = $('<a>', { 'href' : "javascript:mainController.showViewSamplePageFromPermId('" + sample.permId + "')"}).html(sample.code); + var $sampleLink = $('<a>', { 'href' : "javascript:mainController.changeView('showViewSamplePageFromPermId', '" + sample.permId + "')"}).html(sample.code); diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js index 716bee96db1..c34c45c30f5 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js @@ -67,7 +67,7 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe } this.createNewSample = function() { - mainController.showCreateSamplePage(this.sampleTypeCode); //TO-DO : Fix global access + mainController.changeView("showCreateSamplePage", this.sampleTypeCode); //TO-DO : Fix global access } this.registerSamples = function() { @@ -382,7 +382,7 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe } } else { onClickFunction = function(sample) { - mainController.showSampleHierarchyPage(sample); //TO-DO : Fix Global Access + mainController.changeView("showSampleHierarchyPage", sample.permId); //TO-DO : Fix Global Access } } @@ -452,8 +452,8 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe } if(localReference.enableEdit) { - tableFields[tableFields.length] = "<a class='btn' href=\"javascript:mainController.currentView.openEditWindowForSample('"+sample.code+"', '"+sample.permId+"');\"><i class='icon-eye-open'></i></a>"; - tableFields[tableFields.length] = "<a class='btn' href=\"javascript:mainController.currentView.openEditWindowForSample('"+sample.code+"', '"+sample.permId+"');\"><i class='icon-edit'></i></a>"; + tableFields[tableFields.length] = "<a class='btn' href=\"javascript:mainController.changeView('showViewSamplePageFromPermId','"+sample.permId+"');\"><i class='icon-edit'></i></a>"; + tableFields[tableFields.length] = ""; } else { tableFields[tableFields.length] = ""; tableFields[tableFields.length] = ""; @@ -577,28 +577,6 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe this._reloadWithSamplesAndPagination(0); } - this.openViewWindowForSample = function(code, permId) { - var sample = null; - for(var i = 0; i < this._samplesToPaint.length; i++) { - if (this._samplesToPaint[i].permId === permId) { - sample = this._samplesToPaint[i]; - break; - } - } - mainController.showViewSamplePage(sample); //TO-DO : Fix Global Access - } - - this.openEditWindowForSample = function(code, permId) { - var sample = null; - for(var i = 0; i < this._samplesToPaint.length; i++) { - if (this._samplesToPaint[i].permId === permId) { - sample = this._samplesToPaint[i]; - break; - } - } - mainController.showEditSamplePage(sample); //TO-DO : Fix Global Access - } - this.reloadWithSamples = function(returnedSamples) { var sortedSamples = null; if(this.isSearch) { diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/DataSetViewer.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/DataSetViewer.js index b6b4a8877ce..71fe24da03e 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/DataSetViewer.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/DataSetViewer.js @@ -103,7 +103,7 @@ function DataSetViewer(containerId, sample, serverFacade, datastoreDownloadURL) var localSample = this.sample; $uploadButton.click(function() { - mainController.showCreateDataSetPage(localSample); + mainController.changeView('showCreateDataSetPage',localSample); //TO-DO Fix Global Access } ); //Title diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/NavigationBar.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/NavigationBar.js index 7057ba0635d..9b64086ecc3 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/NavigationBar.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/NavigationBar.js @@ -54,7 +54,7 @@ function NavigationBar(mainController, containerId, activeMenuId, menuStructure) } for(var i = 0; i < groupOfMenuItems.menuItems.length; i++) { var menuItem = groupOfMenuItems.menuItems[i]; - menu += "<li><a href='javascript:mainController.navigationBar.updateBreadCrumbToSecondLevelForQuickMenu(); mainController." + menuItem.href+ "(\"" + menuItem.hrefArgs + "\");'>" + menuItem.displayName + "</a></li>"; + menu += "<li><a href='javascript:mainController.changeView(\"" + menuItem.href+ "\", \"" + menuItem.hrefArgs + "\");'>" + menuItem.displayName + "</a></li>"; } } menu += "</ul>"; @@ -79,9 +79,9 @@ function NavigationBar(mainController, containerId, activeMenuId, menuStructure) menu += "<div class='pull-right'>"; menu += "<ul class='nav'>"; //Pin Button - menu += "<li><a id='pin-button' href='javascript:mainController.showInspectors()'><img src='./img/pin-icon.png' style='width:16px; height:16px;' /><span id='num-pins'>" + this.mainController.inspector.inspectedSamples.length + "</span></a></li>"; + menu += "<li><a id='pin-button' href='javascript:mainController.changeView(\"showInspectors\",null)'><img src='./img/pin-icon.png' style='width:16px; height:16px;' /><span id='num-pins'>" + this.mainController.inspector.inspectedSamples.length + "</span></a></li>"; //Search - menu += "<li><form class='navbar-search' onsubmit='return false;'><input id='search' type='text' onkeyup='mainController.showSearchPage(event);' class='search-query' placeholder='Search'></form></li>"; + menu += "<li><form class='navbar-search' onsubmit='return false;'><input id='search' type='text' onkeyup='mainController.changeView(\"showSearchPage\", event);' class='search-query' placeholder='Search'></form></li>"; //Logout menu += "<li><a id='logout-button' href=''><img src='./img/logout-icon.png' style='width:16px; height:16px;' /></a></li>"; menu += "</ul>"; @@ -118,7 +118,7 @@ function NavigationBar(mainController, containerId, activeMenuId, menuStructure) this.activeMenuId = newActiveId; } - this.updateBreadCrumbToSecondLevelForQuickMenu = function() { //Used by the quick menu + this.updateBreadCrumbToSecondLevel = function() { //Used by the quick menu this.breadcrumb.length = 1; } @@ -129,7 +129,8 @@ function NavigationBar(mainController, containerId, activeMenuId, menuStructure) this.executeBreadCrumb = function(breadCrumbIndex) { var href = this.breadcrumb[breadCrumbIndex].href; var hrefArgs = this.breadcrumb[breadCrumbIndex].hrefArgs; - this.mainController[href](hrefArgs); + //this.mainController[href](hrefArgs); + this.mainController.changeView(href, hrefArgs); } this.updateBreadCrumbPage = function(breadCrumbPage) { -- GitLab