updates to internal class form and menu edit
This commit is contained in:
parent
a4f90721f3
commit
aa0de11f90
3 changed files with 35 additions and 20 deletions
|
@ -130,7 +130,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
|
|||
log.error("Display model not being retrieved correctly");
|
||||
}
|
||||
//if Add, then create new menu item and new page elements, and use the values above
|
||||
|
||||
String errorMessage = "";
|
||||
if(isAdd(command)){
|
||||
processAdd(menuItem, displayModel, command, vreq);
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
|
|||
} else if(isDelete(command)) {
|
||||
processDelete(menuItem, displayModel, command, vreq);
|
||||
} else if(isReorder(command)) {
|
||||
processReorder(displayModel, vreq, resp);
|
||||
errorMessage = processReorder(displayModel, vreq);
|
||||
}
|
||||
|
||||
//Edits to model occur here
|
||||
|
@ -161,32 +161,39 @@ public class MenuManagementEdit extends VitroHttpServlet {
|
|||
displayModel.add(addStatements);
|
||||
|
||||
} catch(Exception ex) {
|
||||
|
||||
log.error("An error occurred in processing command", ex);
|
||||
errorMessage += "An error occurred and the operation could not be completed successfully.";
|
||||
}finally {
|
||||
displayModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
//if reorder, need to send back an AJAX response
|
||||
if(isReorder(command)){
|
||||
sendReorderResponse(errorMessage, resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processReorder(OntModel displayModel, VitroRequest vreq, HttpServletResponse resp) {
|
||||
//Get the new menu positions for all the elements
|
||||
String predicate = vreq.getParameter("predicate");
|
||||
//Assuming these two are in the same order
|
||||
private String processReorder(OntModel displayModel, VitroRequest vreq) {
|
||||
//Assuming individual uris passed in the order of their new menu positions
|
||||
String[]individuals = vreq.getParameterValues("individuals");
|
||||
String[] positions = vreq.getParameterValues("positions");
|
||||
String errorMessage = null;
|
||||
if(individuals.length > 0 && positions.length > 0 && individuals.length == positions.length) {
|
||||
if(individuals.length > 0 ) {
|
||||
removeStatements = removePositionStatements(displayModel, individuals);
|
||||
addStatements = addPositionStatements(displayModel, individuals, positions);
|
||||
addStatements = addPositionStatements(displayModel, individuals);
|
||||
} else {
|
||||
errorMessage = "Number of individuals and positions is out of synch";
|
||||
errorMessage = "No individuals passed";
|
||||
}
|
||||
try{
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
private void sendReorderResponse(String errorMessage, HttpServletResponse resp) {
|
||||
try{
|
||||
JSONObject rObj = new JSONObject();
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
if( errorMessage != null ){
|
||||
if( errorMessage != null && !errorMessage.isEmpty()){
|
||||
rObj.put("errorMessage", errorMessage);
|
||||
resp.setStatus(500 /*HttpURLConnection.HTTP_SERVER_ERROR*/);
|
||||
}else{
|
||||
|
@ -197,7 +204,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
|
|||
} catch(Exception ex) {
|
||||
log.error("Error creating JSON object for response", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Model removePositionStatements(OntModel displayModel,
|
||||
|
@ -218,14 +225,13 @@ public class MenuManagementEdit extends VitroHttpServlet {
|
|||
}
|
||||
|
||||
private Model addPositionStatements(OntModel displayModel,
|
||||
String[] individuals, String[] positions) {
|
||||
String[] individuals) {
|
||||
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();
|
||||
|
||||
int position = index + 1;
|
||||
addPositionStatements.add(addPositionStatements.createStatement(
|
||||
individualResource,
|
||||
DisplayVocabulary.MENU_POSITION,
|
||||
|
|
|
@ -17,6 +17,10 @@ public class DisplayVocabulary {
|
|||
/** <p>The ontology model that holds the vocabulary terms</p> */
|
||||
private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
|
||||
|
||||
//URL for menu management
|
||||
public static final String PROCESS_MENU_MANAGEMENT_URL = "/processEditDisplayModel";
|
||||
public static final String REORDER_MENU_URL = PROCESS_MENU_MANAGEMENT_URL + "?cmd=Reorder";
|
||||
|
||||
/*Uris for Models for Display*/
|
||||
|
||||
public static final String DISPLAY_TBOX_MODEL_URI = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadataTBOX";
|
||||
|
|
|
@ -19,22 +19,27 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu
|
|||
<section>
|
||||
<form method="POST" action="${formUrl}" class="customForm">
|
||||
<input type="hidden" name="submitForm" id="submitForm" value="true" />
|
||||
<#--If no local ontologies, display message for user to create a local ontology-->
|
||||
<#if ontologiesExist = false>
|
||||
<section id="noLocalOntologyExists">
|
||||
<p>${noLocalOntologiesMessage}</p>
|
||||
</section>
|
||||
|
||||
<#elseif useExistingInternalClass?has_content>
|
||||
<#--else if local ontologies exist and local classes exist, show drop-down of local classes-->
|
||||
<#elseif useExistingLocalClass?has_content>
|
||||
<section id="existingLocalClass">
|
||||
<#--Populated based on class list returned-->
|
||||
<select id="existingLocalClasses" name="existingLocalClasses">
|
||||
<#assign classUris = existingLocalClasses?keys />
|
||||
<#--If internal class exists, check against value in drop-down and select option-->
|
||||
<#list classUris as localClassUri>
|
||||
<option value="${localClassUri}" <#if existingInternalClass = localClassUri>selected</#if> >${existingLocalClasses[localClassUri]}</option>
|
||||
</#list>
|
||||
</select>
|
||||
<p>Can't find an appropriate class? Create a <a href="${formUrl}?cmd=createClass">new one</a>.</p>
|
||||
</section>
|
||||
|
||||
<#--if parameter to create new class passed or if there are local ontologies but no local classes, show create new class page-->
|
||||
<#elseif createNewClass?has_content>
|
||||
<section id="createNewLocalClass">
|
||||
<h2>Create a new class</h2>
|
||||
|
@ -54,14 +59,14 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu
|
|||
</#if>
|
||||
|
||||
</section>
|
||||
<#--this case is an error case-->
|
||||
<#else>
|
||||
Problematic section as above should all have been handled
|
||||
</#if>
|
||||
|
||||
<#--only show submit and cancel if ontologies exist-->
|
||||
<#if ontologiesExist = true>
|
||||
<input type="submit" name="submit-internalClass" value="${submitAction}" class="submit" /> or <a class="cancel" href="${cancelUrl}">Cancel</a>
|
||||
<p class="requiredHint">* required fields</p>
|
||||
|
||||
</#if>
|
||||
|
||||
</form>
|
||||
|
|
Loading…
Add table
Reference in a new issue