NIHVIVO-517 Fix identification of active tab in main menu
This commit is contained in:
parent
6bfab4e431
commit
b26d294ea1
4 changed files with 36 additions and 16 deletions
|
@ -105,6 +105,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
|
|||
// body template.
|
||||
portalId = portal.getPortalId();
|
||||
root.put("portalId", portalId);
|
||||
System.out.println("PORTAL ID: " + portalId);
|
||||
|
||||
appName = portal.getAppName();
|
||||
setSharedVariable("siteName", appName);
|
||||
|
|
|
@ -127,14 +127,17 @@ public class UrlBuilder {
|
|||
}
|
||||
|
||||
public static String getUrl(String path, Params params) {
|
||||
|
||||
String url = getUrl(path);
|
||||
path = getPath(path, params);
|
||||
return getUrl(path);
|
||||
}
|
||||
|
||||
public static String getPath(String path, Params params) {
|
||||
String glue = "?";
|
||||
for (String key : params.keySet()) {
|
||||
url += glue + key + "=" + urlEncode(params.get(key));
|
||||
path += glue + key + "=" + urlEncode(params.get(key));
|
||||
glue = "&";
|
||||
}
|
||||
return url;
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String urlEncode(String url) {
|
||||
|
|
|
@ -24,16 +24,16 @@ public class MainMenu extends Menu {
|
|||
}
|
||||
|
||||
public void addItem(String text, String path) {
|
||||
boolean active = isActiveItem(path);
|
||||
MainMenuItem i = new MainMenuItem(text, path, active);
|
||||
items.add(i);
|
||||
boolean isActive = isActiveItem(path);
|
||||
addItem(text, path, isActive);
|
||||
}
|
||||
|
||||
public void addItem(String text, String path, boolean isActive) {
|
||||
MainMenuItem i = new MainMenuItem(text, path, isActive);
|
||||
items.add(i);
|
||||
}
|
||||
|
||||
// RY NEED TO FIX: doesn't work for Home and other generated tabs:
|
||||
// vreq.getServletPath() = /templates/page/basicPage.jsp
|
||||
// vreq.getRequestURL() = http://localhost:8080/vivo/templates/page/basicPage.jsp
|
||||
// vreq.getRequestURI() = /vivo/templates/page/basicPage.jsp
|
||||
private boolean isActiveItem(String path) {
|
||||
protected boolean isActiveItem(String path) {
|
||||
return vreq.getServletPath().equals(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Tab;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Params;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.TabWebUtil;
|
||||
|
||||
/** A main menu constructed from persisted tab data
|
||||
|
@ -22,6 +23,9 @@ public class TabMenu extends MainMenu {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(TabMenu.class.getName());
|
||||
|
||||
private static String TAB_PARAM = "primary";
|
||||
private static String PATH = "/index.jsp";
|
||||
|
||||
public TabMenu(VitroRequest vreq, int portalId) {
|
||||
super(vreq);
|
||||
|
@ -37,14 +41,26 @@ public class TabMenu extends MainMenu {
|
|||
Tab tab;
|
||||
while (primaryTabIterator.hasNext()) {
|
||||
tab = (Tab) primaryTabIterator.next();
|
||||
addItem(tab.getTitle(), "/index.jsp?primary=" + tab.getTabId());
|
||||
addItem(tab);
|
||||
// RY Also need to loop through nested tab levels, but not doing that now.
|
||||
}
|
||||
|
||||
// Hard-coded tabs. It's not really a good idea to have these here, since any menu item that doesn't
|
||||
// Hard-coded tabs. It's not a good idea to have these here, since any menu item that doesn't
|
||||
// come from the db should be accessible to the template to change the text. But we need them here
|
||||
// to apply the "active" mechanism.
|
||||
// (rather than adding directly from the template) to apply the "active" mechanism.
|
||||
addItem("Index", "/browse");
|
||||
}
|
||||
|
||||
private void addItem(Tab tab) {
|
||||
boolean isActive = isActiveItem(tab);
|
||||
String text = tab.getTitle();
|
||||
String path = UrlBuilder.getPath(PATH, new Params(TAB_PARAM, "" + tab.getTabId()));
|
||||
addItem(text, path, isActive);
|
||||
}
|
||||
|
||||
private boolean isActiveItem(Tab tab) {
|
||||
String requestedTabId = vreq.getParameter(TAB_PARAM);
|
||||
return requestedTabId != null && Integer.parseInt(requestedTabId) == tab.getTabId();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue