NIHVIVO-517 Fix identification of active tab in main menu

This commit is contained in:
rjy7 2010-05-27 22:12:24 +00:00
parent 6bfab4e431
commit b26d294ea1
4 changed files with 36 additions and 16 deletions

View file

@ -105,6 +105,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
// body template. // body template.
portalId = portal.getPortalId(); portalId = portal.getPortalId();
root.put("portalId", portalId); root.put("portalId", portalId);
System.out.println("PORTAL ID: " + portalId);
appName = portal.getAppName(); appName = portal.getAppName();
setSharedVariable("siteName", appName); setSharedVariable("siteName", appName);

View file

@ -127,14 +127,17 @@ public class UrlBuilder {
} }
public static String getUrl(String path, Params params) { public static String getUrl(String path, Params params) {
path = getPath(path, params);
String url = getUrl(path); return getUrl(path);
}
public static String getPath(String path, Params params) {
String glue = "?"; String glue = "?";
for (String key : params.keySet()) { for (String key : params.keySet()) {
url += glue + key + "=" + urlEncode(params.get(key)); path += glue + key + "=" + urlEncode(params.get(key));
glue = "&"; glue = "&";
} }
return url; return path;
} }
public static String urlEncode(String url) { public static String urlEncode(String url) {

View file

@ -24,16 +24,16 @@ public class MainMenu extends Menu {
} }
public void addItem(String text, String path) { public void addItem(String text, String path) {
boolean active = isActiveItem(path); boolean isActive = isActiveItem(path);
MainMenuItem i = new MainMenuItem(text, path, active); addItem(text, path, isActive);
items.add(i);
} }
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: protected boolean isActiveItem(String path) {
// 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) {
return vreq.getServletPath().equals(path); return vreq.getServletPath().equals(path);
} }
} }

View file

@ -10,7 +10,8 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Tab; import edu.cornell.mannlib.vitro.webapp.beans.Tab;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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; import edu.cornell.mannlib.vitro.webapp.web.TabWebUtil;
/** A main menu constructed from persisted tab data /** 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 long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(TabMenu.class.getName()); 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) { public TabMenu(VitroRequest vreq, int portalId) {
super(vreq); super(vreq);
@ -37,14 +41,26 @@ public class TabMenu extends MainMenu {
Tab tab; Tab tab;
while (primaryTabIterator.hasNext()) { while (primaryTabIterator.hasNext()) {
tab = (Tab) primaryTabIterator.next(); 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. // 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 // 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"); 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();
}
} }