NIHVIVO-2051 Fix currentPage value sent to template: make home page value consistent regardless of the requested url, and change from servletPath to requestURI so we get full path value below the context path. Also add urls.currentPage to replace ${urls.base}/${currentPage} in templates. This value is similarly normalized for the home page.
This commit is contained in:
parent
f07999fc14
commit
a05a001704
4 changed files with 24 additions and 20 deletions
|
@ -242,16 +242,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
|
||||
// Define the URLs that are accessible to the templates. Note that we do not create menus here,
|
||||
// because we want the templates to be free to define the link text and where the links are displayed.
|
||||
private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder) {
|
||||
// The urls that are accessible to the templates.
|
||||
// NB We are not using our menu object mechanism to build menus here, because we want the
|
||||
// view to control which links go where, and the link text and title.
|
||||
private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder, VitroRequest vreq) {
|
||||
Map<String, String> urls = new HashMap<String, String>();
|
||||
|
||||
urls.put("home", urlBuilder.getHomeUrl());
|
||||
|
||||
// Templates use this to construct urls.
|
||||
urls.put("base", urlBuilder.contextPath);
|
||||
urls.put("base", UrlBuilder.contextPath);
|
||||
|
||||
urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT));
|
||||
if (ContactMailServlet.getSmtpHostFromProperties() != null) {
|
||||
|
@ -264,9 +261,12 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN));
|
||||
urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons")); // deprecated
|
||||
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
|
||||
urls.put("images", urlBuilder.getUrl("/images"));
|
||||
urls.put("theme", urlBuilder.getUrl(themeDir));
|
||||
urls.put("index", urlBuilder.getUrl("/browse"));
|
||||
urls.put("images", UrlBuilder.getUrl("/images"));
|
||||
urls.put("theme", UrlBuilder.getUrl(themeDir));
|
||||
urls.put("index", UrlBuilder.getUrl("/browse"));
|
||||
|
||||
//urls.put("currentPage", vreq.getRequestURI());
|
||||
urls.put("currentPage", getCurrentPageValue(vreq));
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
@ -353,15 +353,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
String themeDir = getThemeDir(portal);
|
||||
UrlBuilder urlBuilder = new UrlBuilder(portal);
|
||||
|
||||
map.put("urls", getUrls(themeDir, urlBuilder));
|
||||
map.put("urls", getUrls(themeDir, urlBuilder, vreq));
|
||||
|
||||
map.put("themeDir", themeDir);
|
||||
map.put("currentTheme", themeDir.substring(themeDir.lastIndexOf('/')+1));
|
||||
map.put("stylesheets", getStylesheetList(themeDir));
|
||||
map.put("scripts", getScriptList(themeDir));
|
||||
map.put("headScripts", getScriptList(themeDir));
|
||||
|
||||
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
|
||||
|
||||
map.putAll(getDirectives());
|
||||
map.putAll(getMethods());
|
||||
|
@ -395,13 +393,23 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
}
|
||||
|
||||
// Let the page template know which page it's processing.
|
||||
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
|
||||
String currentPage = getCurrentPageValue(vreq).replaceFirst(vreq.getContextPath() + "/", "");
|
||||
map.put("currentPage", currentPage);
|
||||
|
||||
// Allow template to send domain name to JavaScript (needed for AJAX calls)
|
||||
map.put("requestedPage", vreq.getRequestURL().toString());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private String getCurrentPageValue(HttpServletRequest request) {
|
||||
String currentPage = request.getRequestURI();
|
||||
// Return a uniform value for the home page
|
||||
if (currentPage.equals("") || currentPage.equals("index.jsp")) {
|
||||
currentPage = "home";
|
||||
}
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
private TabMenu getTabMenu(VitroRequest vreq) {
|
||||
int portalId = vreq.getPortal().getPortalId();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</#if>
|
||||
|
||||
<#if menuN3??>
|
||||
<form class="" action="${urls.base}/${currentPage}" method="post">
|
||||
<form class="" action="${urls.currentPage}" method="post">
|
||||
<label for="navigatioN3">Setup the primary navigation menu for your website</label>
|
||||
<textarea name="navigationN3" id="navigationN3" cols="45" rows="40" class="maxWidth">
|
||||
${menuN3}<#t><#-- The trim directive here is to trim leading and trailing white-space -->
|
||||
|
|
|
@ -15,10 +15,6 @@ ${stylesheets.add("/css/browseClassGroups.css")}
|
|||
<#if !firstPopulatedClassGroup??>
|
||||
<#assign firstPopulatedClassGroup = group />
|
||||
</#if>
|
||||
<#-- Remove "index.jsp" from URL (should verify with RY if this can be taken care of in the controller) -->
|
||||
<#if currentPage == "index.jsp">
|
||||
<#assign currentPage = "" />
|
||||
</#if>
|
||||
<#-- Determine the active (selected) group -->
|
||||
<#assign activeGroup = "" />
|
||||
<#if !classGroup??>
|
||||
|
@ -28,7 +24,7 @@ ${stylesheets.add("/css/browseClassGroups.css")}
|
|||
<#elseif classGroup.uri == group.uri>
|
||||
<#assign activeGroup = selected />
|
||||
</#if>
|
||||
<li role="listitem"><a ${activeGroup}href="${urls.base}/${currentPage}?classgroupUri=${group.uri?url}#browse" title="Browse ${group.publicName?capitalize}" data-uri="${group.uri}" data-count="${group.individualCount}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li>
|
||||
<li role="listitem"><a ${activeGroup}href="${urls.currentPage}?classgroupUri=${group.uri?url}#browse" title="Browse ${group.publicName?capitalize}" data-uri="${group.uri}" data-count="${group.individualCount}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li>
|
||||
</#if>
|
||||
</#list>
|
||||
</#assign>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<ul id="browse-classgroups" role="list">
|
||||
<#list vclassGroupList as group>
|
||||
<#if (group.individualCount > 0)>
|
||||
<li role="listitem"><a href="${urls.base}/${currentPage}?classgroupUri=${group.uri?url}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li>
|
||||
<li role="listitem"><a href="${urls.currentPage}?classgroupUri=${group.uri?url}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li>
|
||||
</#if>
|
||||
</#list>
|
||||
</ul>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<ul id="classes-in-classgroup" role="list">
|
||||
<#list classes as class>
|
||||
<#if (class.individualCount > 0)>
|
||||
<li role="listitem"><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.uri?url}&vclassUri=${class.uri?url}">${class.name} <span class="count-individuals"> (${class.individualCount})</span></a></li>
|
||||
<li role="listitem"><a href="${urls.currentPage}?classgroupUri=${classGroup.uri?url}&vclassUri=${class.uri?url}">${class.name} <span class="count-individuals"> (${class.individualCount})</span></a></li>
|
||||
</#if>
|
||||
</#list>
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue