diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java index 67fde50b2..f57003a20 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java @@ -55,7 +55,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; *then process the parameters and then make the necessary changes to the model. */ public class MenuManagementEdit extends VitroHttpServlet { - private static final String CMD_PARAM = "CMD"; + private static final String CMD_PARAM = "cmd"; private final static String EDIT_FORM = "testMenuManagement.ftl"; private final static String EDIT_PARAM_VALUE = "Edit"; private final static String DELETE_PARAM_VALUE = "Remove"; @@ -73,8 +73,17 @@ public class MenuManagementEdit extends VitroHttpServlet { .getRequestDispatcher("/edit/postEditCleanUp.jsp"); rd.forward(request, resp);*/ VitroRequest vreq = new VitroRequest(rawRequest); + java.util.Enumeration paramNames = vreq.getParameterNames(); + while(paramNames.hasMoreElements()) { + String pName = (String)paramNames.nextElement(); + System.out.println("Param name is " + pName + " -a nd value is " + vreq.getParameter(pName)); + } String command = getCommand(vreq); - processCommand(command, vreq); + if(command != null) { + processCommand(command, vreq); + } else { + System.out.println("Command is null"); + } //Need to redirect correctly //if(!isReorder(command)){ //RequestDispatcher rd = rawRequest.getRequestDispatcher(REDIRECT_URL); @@ -114,6 +123,10 @@ public class MenuManagementEdit extends VitroHttpServlet { //Get parameters for menu item being edited String menuItem = vreq.getParameter("menuItem"); OntModel displayModel = getDisplayModel(vreq); + if(displayModel == null) { + //Throw some kind of exception + System.out.println("Display model not being retrieved correctly"); + } //if Add, then create new menu item and new page elements, and use the values above if(isAdd(command)){ @@ -150,10 +163,56 @@ public class MenuManagementEdit extends VitroHttpServlet { private void processReorder(OntModel displayModel, VitroRequest vreq) { //Get the new menu positions for all the elements - + String predicate = vreq.getParameter("predicate"); + //Assuming these two are in the same order + String[]individuals = vreq.getParameterValues("individuals"); + String[] positions = vreq.getParameterValues("positions"); + if(individuals.length > 0 && positions.length > 0 && individuals.length == positions.length) { + removeStatements = removePositionStatements(displayModel, individuals); + addStatements = addPositionStatements(displayModel, individuals, positions); + } else { + //Throw an error? + } } + private Model removePositionStatements(OntModel displayModel, + String[] individuals) { + Model removePositionStatements = ModelFactory.createDefaultModel(); + + for(String individual: individuals) { + Resource individualResource = ResourceFactory.createResource(individual); + + removePositionStatements.add(displayModel.listStatements( + individualResource, + DisplayVocabulary.MENU_POSITION, + (RDFNode) null)); + + } + + return removePositionStatements; + } + + private Model addPositionStatements(OntModel displayModel, + String[] individuals, String[] positions) { + Model addPositionStatements = ModelFactory.createDefaultModel(); + int index = 0; + int len = individuals.length; + for(index = 0; index < len; index++) { + Resource individualResource = ResourceFactory.createResource(individuals[index]); + int position = new Integer(positions[index]).intValue(); + + addPositionStatements.add(addPositionStatements.createStatement( + individualResource, + DisplayVocabulary.MENU_POSITION, + addPositionStatements.createTypedLiteral(position))); + + } + return addPositionStatements; + } + + + private void processDelete(String menuItem, OntModel displayModel, String command, VitroRequest vreq) { Resource menuItemResource = getExistingMenuItem(menuItem, displayModel); @@ -254,7 +313,7 @@ public class MenuManagementEdit extends VitroHttpServlet { private Model getIndividualsForClassesDataGetter(VitroRequest vreq, Resource dataGetterResource, Model addModel, OntModel displayModel) { - String[] selectedClasses = vreq.getParameterValues("selectedClasses"); + String[] selectedClasses = vreq.getParameterValues("classInClassGroup"); Model dgModel = ModelFactory.createDefaultModel(); dgModel.add(dgModel.createStatement(dataGetterResource, RDF.type, DisplayVocabulary.CLASSINDIVIDUALS_PAGE_TYPE)); for(String classUri: selectedClasses) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java index b67eb160f..1c5b48366 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java @@ -75,7 +75,7 @@ public class MenuManagementController extends FreemarkerHttpServlet { //Throw some kind of error or do nothing } //Form url submission - data.put("formUrls", SUBMIT_FORM); + data.put("formUrls", vreq.getContextPath() + SUBMIT_FORM); return new TemplateResponseValues(EDIT_FORM, data); } @@ -98,6 +98,7 @@ public class MenuManagementController extends FreemarkerHttpServlet { private Map processDeleteMenuItem(VitroRequest vreq) { String menuItem = getMenuItem(vreq); Map data = new HashMap(); + data.put("menuItem", menuItem); data.put("menuAction", "Remove"); this.getMenuItemData(vreq, menuItem, data); this.getPageData(vreq, data); @@ -110,11 +111,16 @@ public class MenuManagementController extends FreemarkerHttpServlet { //Generate empty values for fields data.put("menuName", ""); data.put("prettyUrl", ""); + data.put("associatedPage", ""); + data.put("associatedPageURI", ""); + data.put("classGroup", new ArrayList()); + //not a page already assigned a class group + data.put("isClassGroupPage", false); + data.put("includeAllClasses", false); data.put("classGroups", this.getClassGroups()); data.put("selectedTemplateType", "default"); //defaults to regular class group page - data.put("associatedPage", ""); - data.put("associatedPageURI", ""); + return data; } @@ -125,7 +131,7 @@ public class MenuManagementController extends FreemarkerHttpServlet { } //Get parameter for menu item String menuItem = getMenuItem(vreq); - + data.put("menuItem", menuItem); data.put("menuAction", "Edit"); //Get All class groups diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index 004290d53..e726fd94a 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -31,7 +31,7 @@ if(request.getParameter("switchToDisplayModel") != null) { //forward to Edit Request Dispatch Controller String queryString = request.getQueryString(); - response.sendRedirect("http://localhost:8080/vivo/editRequestDispatch?" + queryString); + response.sendRedirect(request.getContextPath() + "/editRequestDispatch?" + queryString); } // Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, predicateUriJson in request diff --git a/webapp/web/edit/editRequestDispatch.jsp b/webapp/web/edit/editRequestDispatch.jsp index e5d9dddaa..5f09e7f1b 100644 --- a/webapp/web/edit/editRequestDispatch.jsp +++ b/webapp/web/edit/editRequestDispatch.jsp @@ -30,8 +30,8 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. //forward to Edit Request Dispatch Controller String queryString = request.getQueryString(); //Instead of edit request which is what we'll do later, here we'll forward to Menu Management Controller - //response.sendRedirect("http://localhost:8080/vivo/editRequestDispatch?" + queryString); - response.sendRedirect("http://localhost:8080/vivo/editDisplayModel?" + queryString); + //response.sendRedirect("editRequestDispatch?" + queryString); + response.sendRedirect(request.getContextPath() + "/editDisplayModel?" + queryString); } /* Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, and predicateUriJson in request. diff --git a/webapp/web/js/menupage/menumanagement_edit.js b/webapp/web/js/menupage/menumanagement_edit.js index 2b617dd35..1143470ba 100644 --- a/webapp/web/js/menupage/menumanagement_edit.js +++ b/webapp/web/js/menupage/menumanagement_edit.js @@ -63,14 +63,15 @@ var menuManagementEdit = { _this.classesForClassGroup.empty(); _this.classesForClassGroup.append("
    "); _this.classesForClassGroup.append('
  • ' + - '' + + '' + '' + '
  • '); $.each(results.classes, function(i, item) { var thisClass = results.classes[i]; var thisClassName = thisClass.name; + //When first selecting new content type, all classes should be selected menuManagementEdit.classesForClassGroup.append('
  • ' + - '' + + '' + '' + '
  • '); }); diff --git a/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl b/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl index 55166c913..934936ce6 100644 --- a/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl +++ b/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl @@ -17,6 +17,9 @@
    + + + ${menuAction} menu item @@ -76,7 +79,7 @@ <#list classGroup as classInClassGroup>
  • - checked /> <#--sortable icon for dragging and dropping menu items-->