Update for menu management: correct url forwarding from edit request dispatch, updates to javascript for checking all classes when new content type selected, and editing
This commit is contained in:
parent
1dacb70669
commit
e6f4c2a861
6 changed files with 83 additions and 14 deletions
|
@ -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) {
|
||||
|
|
|
@ -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<String, Object> processDeleteMenuItem(VitroRequest vreq) {
|
||||
String menuItem = getMenuItem(vreq);
|
||||
Map<String, Object> data = new HashMap<String,Object>();
|
||||
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<String>());
|
||||
//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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue