From 4ca1eac0a7adcd495f7c51fa45689706ef6f9e2d Mon Sep 17 00:00:00 2001 From: laurenwalker Date: Wed, 18 Oct 2017 15:33:58 -0400 Subject: [PATCH] Fix bug where the #signup view was not working for the default and KNB themes --- .../src/main/webapp/js/models/AppModel.js | 4 +- .../webapp/js/themes/arctic/routers/router.js | 2 +- .../js/themes/dataone/routers/router.js | 2 +- .../src/main/webapp/js/themes/knb/config.js | 2 +- .../webapp/js/themes/knb/routers/router.js | 458 ++++++++++++++++++ .../src/main/webapp/js/views/SignInView.js | 12 +- 6 files changed, 474 insertions(+), 6 deletions(-) create mode 100644 metacatui/src/main/webapp/js/themes/knb/routers/router.js diff --git a/metacatui/src/main/webapp/js/models/AppModel.js b/metacatui/src/main/webapp/js/models/AppModel.js index bbc56cb14..8fda13a2e 100644 --- a/metacatui/src/main/webapp/js/models/AppModel.js +++ b/metacatui/src/main/webapp/js/models/AppModel.js @@ -54,7 +54,7 @@ define(['jquery', 'underscore', 'backbone'], queryServiceUrl: null, metaServiceUrl: null, registryServiceUrl: null, - //ldapwebServiceUrl: null, + ldapwebServiceUrl: null, metacatBaseUrl: null, metacatServiceUrl: null, objectServiceUrl: null, @@ -98,7 +98,7 @@ define(['jquery', 'underscore', 'backbone'], this.set('metaServiceUrl', this.get('baseUrl') + this.get('context') + this.get('d1Service') + '/meta/'); this.set('objectServiceUrl', this.get('baseUrl') + this.get('context') + this.get('d1Service') + '/object/'); this.set('registryServiceUrl', this.get('baseUrl') + this.get('context') + '/cgi-bin/register-dataset.cgi'); - //this.set('ldapwebServiceUrl', this.get('baseUrl') + this.get('context') + '/cgi-bin/ldapweb.cgi'); + this.set('ldapwebServiceUrl', this.get('baseUrl') + this.get('context') + '/cgi-bin/ldapweb.cgi'); this.set('metacatServiceUrl', this.get('baseUrl') + this.get('context') + '/metacat'); //Add a ? character to the end of the Solr queries when we are appending JSONP parameters (which use ?'s) diff --git a/metacatui/src/main/webapp/js/themes/arctic/routers/router.js b/metacatui/src/main/webapp/js/themes/arctic/routers/router.js index 02ca6c0f4..b4c7a629d 100644 --- a/metacatui/src/main/webapp/js/themes/arctic/routers/router.js +++ b/metacatui/src/main/webapp/js/themes/arctic/routers/router.js @@ -313,7 +313,7 @@ function ($, _, Backbone) { if(!appView.signInView){ require(['views/SignInView'], function(SignInView){ - appView.signInView = new SignInView({ el: "#Content"}); + appView.signInView = new SignInView({ el: "#Content", fullPage: true }); appView.showView(appView.signInView); }); } diff --git a/metacatui/src/main/webapp/js/themes/dataone/routers/router.js b/metacatui/src/main/webapp/js/themes/dataone/routers/router.js index 5db58bd07..98403a210 100644 --- a/metacatui/src/main/webapp/js/themes/dataone/routers/router.js +++ b/metacatui/src/main/webapp/js/themes/dataone/routers/router.js @@ -316,7 +316,7 @@ function ($, _, Backbone) { if(!appView.signInView){ require(["views/SignInView"], function(SignInView){ - appView.signInView = new SignInView({ el: "#Content"}); + appView.signInView = new SignInView({ el: "#Content", fullPage: true }); appView.showView(appView.signInView); }); } diff --git a/metacatui/src/main/webapp/js/themes/knb/config.js b/metacatui/src/main/webapp/js/themes/knb/config.js index c696827b0..5c717376c 100644 --- a/metacatui/src/main/webapp/js/themes/knb/config.js +++ b/metacatui/src/main/webapp/js/themes/knb/config.js @@ -7,7 +7,7 @@ var themeMap = // Resources (js) omit extension //'views/AboutView' : 'themes/' + theme + '/views/AboutView', - //'routers/router' : 'themes/' + theme + '/routers/router', + 'routers/router' : 'themes/' + theme + '/routers/router', 'models/AppModel' : 'themes/' + theme + '/models/AppModel', // Templates include extension diff --git a/metacatui/src/main/webapp/js/themes/knb/routers/router.js b/metacatui/src/main/webapp/js/themes/knb/routers/router.js new file mode 100644 index 000000000..42f54afaf --- /dev/null +++ b/metacatui/src/main/webapp/js/themes/knb/routers/router.js @@ -0,0 +1,458 @@ +/*global Backbone */ +'use strict'; + +define(['jquery', 'underscore', 'backbone'], +function ($, _, Backbone) { + + // MetacatUI Router + // ---------------- + var UIRouter = Backbone.Router.extend({ + routes: { + '' : 'renderIndex', // the default route + 'about(/:anchorId)' : 'renderAbout', // about page + 'help(/:page)(/:anchorId)' : 'renderHelp', + 'tools(/:anchorId)' : 'renderTools', // tools page + 'data/my-data(/page/:page)' : 'renderMyData', // data search page + 'data(/mode=:mode)(/query=:query)(/page/:page)' : 'renderData', // data search page + 'data/my-data' : 'renderMyData', + 'view/*pid' : 'renderMetadata', // metadata page + 'profile(/*username)(/s=:section)(/s=:subsection)' : 'renderProfile', + 'my-profile(/s=:section)(/s=:subsection)' : 'renderMyProfile', + //'my-account' : 'renderUserSettings', + 'external(/*url)' : 'renderExternal', // renders the content of the given url in our UI + 'logout' : 'logout', // logout the user + 'signout' : 'logout', // logout the user + 'signin' : 'renderTokenSignIn', // logout the user + "signinsuccess" : "renderSignInSuccess", + "signinldaperror" : "renderLdapSignInError", + 'signup' : 'renderTokenSignIn', // use ldapweb for registration + 'share(/:stage/*pid)' : 'renderRegistry', // registry page + 'quality(/s=:suiteId)(/:pid)' : 'renderMdqRun', // MDQ page + 'api(/:anchorId)' : 'renderAPI' // API page + }, + + helpPages: { + "search" : "searchTips", + defaultPage : "searchTips" + }, + + initialize: function(){ + this.listenTo(Backbone.history, "routeNotFound", this.navigateToDefault); + this.on("route", this.trackHash); + }, + + //Keep track of navigation movements + routeHistory: new Array(), + hashHistory: new Array(), + + // Will return the last route, which is actually the second to last item in the route history, + // since the last item is the route being currently viewed + lastRoute: function(){ + if((typeof this.routeHistory === "undefined") || (this.routeHistory.length <= 1)) + return false; + else + return this.routeHistory[this.routeHistory.length-2]; + }, + + trackHash: function(e){ + if(_.last(this.hashHistory) != window.location.hash) + this.hashHistory.push(window.location.hash); + }, + + //If the user or app cancelled the last route, call this function to revert the window location hash back to the correct value + undoLastRoute: function(){ + this.routeHistory.pop(); + + //Remove the last route and hash from the history + if(_.last(this.hashHistory) == window.location.hash) + this.hashHistory.pop(); + + //Change the hash in the window location back + this.navigate(_.last(this.hashHistory), {replace: true}); + }, + + renderIndex: function (param) { + this.routeHistory.push("index"); + + if(!appView.indexView){ + require(["views/IndexView"], function(IndexView){ + appView.indexView = new IndexView(); + appView.showView(appView.indexView); + }); + } + else + appView.showView(appView.indexView); + }, + + renderText: function(options){ + if(!appView.textView){ + require(['views/TextView'], function(TextView){ + appView.textView = new TextView(); + appView.showView(appView.textView, options); + }); + } + else + appView.showView(appView.textView, options); + }, + + renderHelp: function(page, anchorId){ + this.routeHistory.push("help"); + appModel.set('anchorId', anchorId); + + if(page) + var pageName = this.helpPages[page]; + else + var pageName = this.helpPages["defaultPage"]; //default + + var options = { + pageName: pageName, + anchorId: anchorId + } + + this.renderText(options); + }, + + renderAbout: function (anchorId) { + this.routeHistory.push("about"); + appModel.set('anchorId', anchorId); + var options = { + pageName: "about", + anchorId: anchorId + } + + this.renderText(options); + }, + + renderAPI: function (anchorId) { + this.routeHistory.push("api"); + appModel.set('anchorId', anchorId); + var options = { + pageName: "api", + anchorId: anchorId + } + + this.renderText(options); + }, + + renderMdqRun: function (suiteId, pid) { + this.routeHistory.push("quality"); + + if (!appView.mdqRunView) { + require(["views/MdqRunView"], function(MdqRunView) { + appView.mdqRunView = new MdqRunView(); + appView.mdqRunView.suiteId = suiteId; + appView.mdqRunView.pid = pid; + appView.showView(appView.mdqRunView); + }); + } else { + appView.mdqRunView.suiteId = suiteId; + appView.mdqRunView.pid = pid; + appView.showView(appView.mdqRunView); + } + }, + + renderTools: function (anchorId) { + this.routeHistory.push("tools"); + appModel.set('anchorId', anchorId); + + var options = { + pageName: "tools", + anchorId: anchorId + } + + this.renderText(options); + }, + + renderMyData: function(page){ + //Only display this is the user is logged in + if(!appUserModel.get("loggedIn") && appUserModel.get("checked")) this.navigate("data", { trigger: true }); + else if(!appUserModel.get("checked")){ + var router = this; + + this.listenToOnce(appUserModel, "change:checked", function(){ + + if(appUserModel.get("loggedIn")) + router.renderMyData(page); + else + this.navigate("data", { trigger: true }); + }); + + return; + } + + this.routeHistory.push("data"); + + ///Check for a page URL parameter + if(typeof page === "undefined") + appModel.set("page", 0); + else + appModel.set('page', page); + + if(!appView.dataCatalogView){ + require(['views/DataCatalogView'], function(DataCatalogView){ + appView.dataCatalogView = new DataCatalogView(); + appView.dataCatalogView.searchModel = appUserModel.get("searchModel").clone(); + appView.showView(appView.dataCatalogView); + }); + } + else{ + appView.dataCatalogView.searchModel = appUserModel.get("searchModel").clone(); + appView.showView(appView.dataCatalogView); + } + }, + + renderData: function (mode, query, page) { + this.routeHistory.push("data"); + + ///Check for a page URL parameter + if((typeof page === "undefined") || !page) + appModel.set("page", 0); + else if(page == 0) + appModel.set('page', 0); + else + appModel.set('page', page-1); + + //Check for a query URL parameter + if((typeof query !== "undefined") && query){ + var customQuery = appSearchModel.get('additionalCriteria'); + customQuery.push(query); + appSearchModel.set('additionalCriteria', customQuery); + } + + if(!appView.dataCatalogView){ + require(['views/DataCatalogView'], function(DataCatalogView){ + appView.dataCatalogView = new DataCatalogView(); + + //Check for a search mode URL parameter + if((typeof mode !== "undefined") && mode) + appView.dataCatalogView.mode = mode; + + appView.showView(appView.dataCatalogView); + }); + } + else{ + //Check for a search mode URL parameter + if((typeof mode !== "undefined") && mode) + appView.dataCatalogView.mode = mode; + + appView.showView(appView.dataCatalogView); + } + }, + + renderMetadata: function (pid) { + this.routeHistory.push("metadata"); + appModel.set('lastPid', appModel.get("pid")); + + //Get the full identifier from the window object since Backbone filters out URL parameters starting with & and ? + pid = window.location.hash.substring(window.location.hash.indexOf("/")+1); + + var seriesId; + + //Check for a seriesId + if(appModel.get("useSeriesId") && (pid.indexOf("version:") > -1)){ + seriesId = pid.substr(0, pid.indexOf(", version:")); + + pid = pid.substr(pid.indexOf(", version: ") + ", version: ".length); + } + + //Save the id in the app model + appModel.set('pid', pid); + + if(!appView.metadataView){ + require(['views/MetadataView'], function(MetadataView){ + appView.metadataView = new MetadataView(); + + //Send the id(s) to the view + appView.metadataView.seriesId = seriesId; + appView.metadataView.pid = pid; + + appView.showView(appView.metadataView); + }); + } + else{ + //Send the id(s) to the view + appView.metadataView.seriesId = seriesId; + appView.metadataView.pid = pid; + + appView.showView(appView.metadataView); + } + }, + + renderProfile: function(username, section, subsection){ + this.closeLastView(); + + var viewChoice; + + if(!username || !appModel.get("userProfiles")){ + this.routeHistory.push("summary"); + + if(!appView.statsView){ + require(["views/StatsView"], function(StatsView){ + appView.statsView = new StatsView(); + + appView.showView(appView.statsView); + }); + } + else + appView.showView(appView.statsView); + } + else{ + this.routeHistory.push("profile"); + appModel.set("profileUsername", username); + + if(section || subsection){ + var viewOptions = { section: section, subsection: subsection } + } + + if(!appView.userView){ + + require(['views/UserView'], function(UserView){ + appView.userView = new UserView(); + + appView.showView(appView.userView, viewOptions); + }); + } + else + appView.showView(appView.userView, viewOptions); + } + }, + + renderMyProfile: function(section, subsection){ + if(appUserModel.get("checked") && !appUserModel.get("loggedIn")) + this.renderTokenSignIn(); + else if(!appUserModel.get("checked")){ + this.listenToOnce(appUserModel, "change:checked", function(){ + if(appUserModel.get("loggedIn")) + this.renderProfile(appUserModel.get("username"), section, subsection); + else + this.renderTokenSignIn(); + }); + } + else if(appUserModel.get("checked") && appUserModel.get("loggedIn")){ + this.renderProfile(appUserModel.get("username"), section, subsection); + } + }, + + renderRegistry: function (stage, pid) { + this.routeHistory.push("registry"); + + if(!appView.registryView){ + require(['views/RegistryView'], function(RegistryView){ + appView.registryView = new RegistryView(); + appView.registryView.stage = stage; + appView.registryView.pid = pid; + appView.showView(appView.registryView); + }); + } + else{ + appView.registryView.stage = stage; + appView.registryView.pid = pid; + appView.showView(appView.registryView); + } + }, + + renderLdap: function (stage) { + this.routeHistory.push("ldap"); + + if(!appView.ldapView){ + require(["views/LdapView"], function(LdapView){ + appView.ldapView = new LdapView(); + appView.ldapView.stage = stage; + appView.showView(appView.ldapView); + }); + }else{ + appView.ldapView.stage = stage; + appView.showView(appView.ldapView); + } + }, + + logout: function (param) { + //Clear our browsing history when we log out + this.routeHistory.length = 0; + + if(((typeof appModel.get("tokenUrl") == "undefined") || !appModel.get("tokenUrl")) && !appView.registryView){ + require(['views/RegistryView'], function(RegistryView){ + appView.registryView = new RegistryView(); + if(appView.currentView.onClose) + appView.currentView.onClose(); + appUserModel.logout(); + }); + } + else{ + if(appView.currentView && appView.currentView.onClose) + appView.currentView.onClose(); + appUserModel.logout(); + } + }, + + renderTokenSignIn: function(){ + this.routeHistory.push("signin"); + + if(!appView.signInView){ + require(['views/SignInView'], function(SignInView){ + appView.signInView = new SignInView({ el: "#Content", fullPage: true }); + appView.showView(appView.signInView); + }); + } + else{ + appView.showView(appView.signInView); + } + }, + + renderSignInSuccess: function(){ + $("body").html("Sign-in successful."); + setTimeout(window.close, 1000); + }, + + renderLdapSignInError: function(){ + this.routeHistory.push("signinldaperror"); + + if(!appView.signInView){ + require(['views/SignInView'], function(SignInView){ + appView.signInView = new SignInView({ el: "#Content"}); + appView.signInView.ldapError = true; + appView.showView(appView.signInView); + }); + } + else{ + appView.signInView.ldapError = true; + appView.showView(appView.signInView); + } + }, + + renderExternal: function(url) { + // use this for rendering "external" content pulled in dynamically + this.routeHistory.push("external"); + + if(!appView.externalView){ + require(['views/ExternalView'], function(ExternalView){ + appView.externalView = new ExternalView(); + appView.externalView.url = url; + appView.showView(appView.externalView); + }); + } + else{ + appView.externalView.url = url; + appView.showView(appView.externalView); + } + }, + + navigateToDefault: function(){ + //Navigate to the default view + this.navigate(appModel.defaultView, {trigger: true}); + }, + + closeLastView: function(){ + //Get the last route and close the view + var lastRoute = _.last(this.routeHistory); + + if(lastRoute == "summary") + appView.statsView.onClose(); + else if(lastRoute == "profile") + appView.userView.onClose(); + } + + }); + + return UIRouter; +}); diff --git a/metacatui/src/main/webapp/js/views/SignInView.js b/metacatui/src/main/webapp/js/views/SignInView.js index 413552cc8..402b4a873 100644 --- a/metacatui/src/main/webapp/js/views/SignInView.js +++ b/metacatui/src/main/webapp/js/views/SignInView.js @@ -16,10 +16,20 @@ define(['jquery', 'underscore', 'backbone', 'fancybox', 'text!templates/login.ht ldapError: false, + /* Set to true if this SignInView is the only thing on the page */ + fullPage: false, + + /* Set to true if this SignInView is in a modal window */ + inPlace: false, + + /*A message to display at the top of the view */ + topMessage: "", + initialize: function(options){ if(typeof options !== "undefined"){ this.inPlace = options.inPlace; this.topMessage = options.topMessage; + this.fullPage = options.fullPage; } }, @@ -88,7 +98,7 @@ define(['jquery', 'underscore', 'backbone', 'fancybox', 'text!templates/login.ht else{ //If it's a full-page sign-in view, then empty it first - if(this.el == appView.el){ + if(this.el == appView.el || this.fullPage){ this.$el.empty(); var container = document.createElement("div"); container.className = "container login";