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);
|
||||
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,9 +163,55 @@ 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) {
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -63,14 +63,15 @@ var menuManagementEdit = {
|
|||
_this.classesForClassGroup.empty();
|
||||
_this.classesForClassGroup.append("<ul id='selectedClasses' name='selectedClasses'>");
|
||||
_this.classesForClassGroup.append('<li class="ui-state-default">' +
|
||||
'<input type="checkbox" name="allSelected" id="allSelected" value="all" checked</#if>' +
|
||||
'<input type="checkbox" name="allSelected" id="allSelected" value="all" checked/>' +
|
||||
'<label class="inline" for="All"> All</label>' +
|
||||
'</li>');
|
||||
$.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(' <li class="ui-state-default">' +
|
||||
'<input type="checkbox" name="classInClassGroup" value="' + thisClass.URI + '" />' +
|
||||
'<input type="checkbox" checked name="classInClassGroup" value="' + thisClass.URI + '" />' +
|
||||
'<label class="inline" for="' + thisClassName + '"> ' + thisClassName + '</label>' +
|
||||
'</li>');
|
||||
});
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
<section>
|
||||
<form method="POST" action="${formUrls}">
|
||||
<input type="hidden" name="cmd" id="cmd" value="${menuAction}"/>
|
||||
<input type="hidden" name="menuItem" id="menuItem" value="${menuItem}"/>
|
||||
<input type="hidden" name="switchToDisplayModel" id="switchToDisplayModel" value="true"/>
|
||||
|
||||
<legend>${menuAction} menu item</legend>
|
||||
|
||||
<label for="menu-name">Name *</label>
|
||||
|
@ -76,7 +79,7 @@
|
|||
</li>
|
||||
<#list classGroup as classInClassGroup>
|
||||
<li class="ui-state-default">
|
||||
<input type="checkbox" name="classInClassGroup" value="${classInClassGroup.URI}"
|
||||
<input type="checkbox" id="classInClassGroup" name="classInClassGroup" value="${classInClassGroup.URI}"
|
||||
<#if includeAllClasses = true>checked</#if> />
|
||||
<label class="inline" for="${classInClassGroup.name}"> ${classInClassGroup.name}</label>
|
||||
<span class="ui-icon-sortable"></span> <#--sortable icon for dragging and dropping menu items-->
|
||||
|
|
Loading…
Add table
Reference in a new issue