updates for menu management

This commit is contained in:
hjkhjk54 2011-07-13 13:43:25 +00:00
parent 8b7225db9d
commit 9290ed6204
4 changed files with 79 additions and 44 deletions

View file

@ -85,10 +85,10 @@ public class MenuManagementEdit extends VitroHttpServlet {
System.out.println("Command is null"); System.out.println("Command is null");
} }
//Need to redirect correctly //Need to redirect correctly
//if(!isReorder(command)){ if(!isReorder(command)){
//RequestDispatcher rd = rawRequest.getRequestDispatcher(REDIRECT_URL); RequestDispatcher rd = rawRequest.getRequestDispatcher(REDIRECT_URL);
//rd.forward(rawRequest, resp); rd.forward(rawRequest, resp);
//} }
} }
@ -234,11 +234,13 @@ public class MenuManagementEdit extends VitroHttpServlet {
private void processAdd(String menuItem, OntModel displayModel, String command, VitroRequest vreq) { private void processAdd(String menuItem, OntModel displayModel, String command, VitroRequest vreq) {
Resource menuItemResource = createNewMenuItem(menuItem, displayModel); String menuName = vreq.getParameter("menuName");
Resource menuItemResource = createNewMenuItem(menuName, displayModel);
Resource pageResource = createNewPage(menuItemResource, displayModel); Resource pageResource = createNewPage(menuItemResource, displayModel);
associateMenuItemToPage(menuItemResource, pageResource);
//no statements to remove, just to add //no statements to remove, just to add
addStatements = getStatementsToAdd(vreq, command, displayModel, menuItemResource, pageResource); addStatements = getStatementsToAdd(vreq, command, displayModel, menuItemResource, pageResource);
addStatements.add(associateMenuItemToPage(menuItemResource, pageResource));
} }
//Get last menu item positin //Get last menu item positin
@ -285,7 +287,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
String classGroup = vreq.getParameter("selectClassGroup"); String classGroup = vreq.getParameter("selectClassGroup");
//Selected class //Selected class
String allClasses = vreq.getParameter("allSelected");
//For this, need to check whether All or not b/c this will identify the data getter type //For this, need to check whether All or not b/c this will identify the data getter type
//There should be a "specify data getter" method that specifices the data getter //There should be a "specify data getter" method that specifices the data getter
Resource dataGetterResource = getDataGetter(vreq, addModel, displayModel, pageResource); Resource dataGetterResource = getDataGetter(vreq, addModel, displayModel, pageResource);
@ -299,7 +301,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
classGroupResource)); classGroupResource));
//If "All selected" then use class group else use individuals for classes //If "All selected" then use class group else use individuals for classes
Model dataGetterModel = ModelFactory.createDefaultModel(); Model dataGetterModel = ModelFactory.createDefaultModel();
if(allClasses != null && !allClasses.isEmpty()) { if(!internalClassSelected(vreq) && allClassesSelected(vreq)) {
dataGetterModel = getClassGroupDataGetter(vreq, dataGetterResource, addModel, displayModel); dataGetterModel = getClassGroupDataGetter(vreq, dataGetterResource, addModel, displayModel);
} else { } else {
dataGetterModel = getIndividualsForClassesDataGetter(vreq, dataGetterResource, addModel, displayModel); dataGetterModel = getIndividualsForClassesDataGetter(vreq, dataGetterResource, addModel, displayModel);
@ -311,6 +313,16 @@ public class MenuManagementEdit extends VitroHttpServlet {
} }
private boolean allClassesSelected(VitroRequest vreq) {
String allClasses = vreq.getParameter("allSelected");
return (allClasses != null && !allClasses.isEmpty());
}
private boolean internalClassSelected(VitroRequest vreq) {
String internalClass = vreq.getParameter("display-internalClass");
return (internalClass != null && !internalClass.isEmpty());
}
private Model getIndividualsForClassesDataGetter(VitroRequest vreq, Resource dataGetterResource, private Model getIndividualsForClassesDataGetter(VitroRequest vreq, Resource dataGetterResource,
Model addModel, OntModel displayModel) { Model addModel, OntModel displayModel) {
String[] selectedClasses = vreq.getParameterValues("classInClassGroup"); String[] selectedClasses = vreq.getParameterValues("classInClassGroup");
@ -322,9 +334,10 @@ public class MenuManagementEdit extends VitroHttpServlet {
ResourceFactory.createProperty(DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS), ResourceFactory.createProperty(DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS),
ResourceFactory.createResource(classUri))); ResourceFactory.createResource(classUri)));
} }
//Also check if internal class checked //Also check if internal class checked
String internalClass = vreq.getParameter("display-internalClass"); if(internalClassSelected(vreq)) {
if(internalClass != null && !internalClass.isEmpty()) { String internalClass = vreq.getParameter("display-internalClass");
//The value should be the internal class uri //The value should be the internal class uri
dgModel.add(dgModel.createStatement( dgModel.add(dgModel.createStatement(
dataGetterResource, dataGetterResource,
@ -445,7 +458,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
String dataGetterUriBase = pageResource.getURI() + "-dataGetter"; String dataGetterUriBase = pageResource.getURI() + "-dataGetter";
String dataGetterUri = dataGetterUriBase; String dataGetterUri = dataGetterUriBase;
int counter = 0; int counter = 0;
while(displayModel.getResource(dataGetterUriBase) != null) { while(displayModel.getIndividual(dataGetterUriBase) != null) {
dataGetterUri = dataGetterUriBase + counter; dataGetterUri = dataGetterUriBase + counter;
counter++; counter++;
} }
@ -510,8 +523,10 @@ public class MenuManagementEdit extends VitroHttpServlet {
} }
//Create connection //Create connection
private void associateMenuItemToPage(Resource menuItemResource, Resource pageResource) { private Model associateMenuItemToPage(Resource menuItemResource, Resource pageResource) {
menuItemResource.addProperty(DisplayVocabulary.TO_PAGE, pageResource); Model m = ModelFactory.createDefaultModel();
m.add(m.createStatement(menuItemResource, DisplayVocabulary.TO_PAGE, pageResource));
return m;
} }
//Add to model //Add to model
@ -522,7 +537,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
String menuUriBase = DisplayVocabulary.DISPLAY_NS + menuName.replaceAll(" ", "") + "MenuItem"; String menuUriBase = DisplayVocabulary.DISPLAY_NS + menuName.replaceAll(" ", "") + "MenuItem";
String menuUri = menuUriBase; String menuUri = menuUriBase;
int counter = 0; int counter = 0;
while(displayModel.getResource(menuUri) != null) { while(displayModel.getIndividual(menuUri) != null) {
menuUri = menuUriBase + counter; menuUri = menuUriBase + counter;
counter++; counter++;
} }

View file

@ -59,12 +59,8 @@ public class MenuManagementController extends FreemarkerHttpServlet {
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
//Parameters should include the menu item being edited/added/removed/reordered //Parameters should include the menu item being edited/added/removed/reordered
Map<String, Object> data = new HashMap<String,Object>(); Map<String, Object> data = new HashMap<String,Object>();
//if no menu item passed, return empty data //if no menu item passed, return empty data
//TODO: Check if exception needs to be thrown //TODO: Check if exception needs to be thrown
String cmd = getCommand(vreq); String cmd = getCommand(vreq);
if(cmd.equals(ADD_PARAM_VALUE)) { if(cmd.equals(ADD_PARAM_VALUE)) {
@ -76,13 +72,18 @@ public class MenuManagementController extends FreemarkerHttpServlet {
} else { } else {
//Throw some kind of error or do nothing //Throw some kind of error or do nothing
} }
this.initializeData(data, vreq);
return new TemplateResponseValues(EDIT_FORM, data);
}
//Certain parameters are always passed
private void initializeData(Map<String, Object> data, VitroRequest vreq) {
//Form url submission //Form url submission
data.put("formUrls", vreq.getContextPath() + SUBMIT_FORM); data.put("formUrls", vreq.getContextPath() + SUBMIT_FORM);
data.put("cancelUrl", vreq.getContextPath() + CANCEL_FORM); data.put("cancelUrl", vreq.getContextPath() + CANCEL_FORM);
//This will be reset if internal class exists data.put("internalClassUri", "");
data.put("internalClass", "");
return new TemplateResponseValues(EDIT_FORM, data);
} }
//Based on parameters, ascertain command //Based on parameters, ascertain command
@ -105,6 +106,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
Map<String, Object> data = new HashMap<String,Object>(); Map<String, Object> data = new HashMap<String,Object>();
data.put("menuItem", menuItem); data.put("menuItem", menuItem);
data.put("menuAction", "Remove"); data.put("menuAction", "Remove");
this.getMenuItemData(vreq, menuItem, data); this.getMenuItemData(vreq, menuItem, data);
this.getPageData(vreq, data); this.getPageData(vreq, data);
return data; return data;
@ -126,7 +128,8 @@ public class MenuManagementController extends FreemarkerHttpServlet {
data.put("classGroups", this.getClassGroups()); data.put("classGroups", this.getClassGroups());
data.put("selectedTemplateType", "default"); data.put("selectedTemplateType", "default");
//defaults to regular class group page //defaults to regular class group page
//Check whether institutional internal class exists
this.checkInstitutionalInternalClass(data);
return data; return data;
} }
@ -138,12 +141,11 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//Get parameter for menu item //Get parameter for menu item
String menuItem = getMenuItem(vreq); String menuItem = getMenuItem(vreq);
data.put("menuItem", menuItem); data.put("menuItem", menuItem);
data.put("menuAction", "Edit"); data.put("menuAction", "Edit");
//Get All class groups //Get All class groups
data.put("classGroups", this.getClassGroups()); data.put("classGroups", this.getClassGroups());
//Check whether institutional internal class exists
this.checkInstitutionalInternalClass(data);
//Get data for menu item and associated page //Get data for menu item and associated page
this.getMenuItemData(vreq, menuItem, data); this.getMenuItemData(vreq, menuItem, data);
this.getPageData(vreq, data); this.getPageData(vreq, data);
@ -244,6 +246,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//All items will have data getter except for Browse or Home page //All items will have data getter except for Browse or Home page
//Home can be edited but not removed //Home can be edited but not removed
private void getPageDataGetterInfo(OntModel writeModel, Resource page, Map<String, Object> data) { private void getPageDataGetterInfo(OntModel writeModel, Resource page, Map<String, Object> data) {
//Alternative is to do this via sparql query //Alternative is to do this via sparql query
StmtIterator dataGetterIt = writeModel.listStatements(page, ResourceFactory.createProperty(DisplayVocabulary.HAS_DATA_GETTER), (RDFNode) null); StmtIterator dataGetterIt = writeModel.listStatements(page, ResourceFactory.createProperty(DisplayVocabulary.HAS_DATA_GETTER), (RDFNode) null);
while(dataGetterIt.hasNext()) { while(dataGetterIt.hasNext()) {
@ -272,8 +275,6 @@ public class MenuManagementController extends FreemarkerHttpServlet {
this.getClassesForDataGetter(writeModel, dataGetter, data); this.getClassesForDataGetter(writeModel, dataGetter, data);
//Also save the class group for display //Also save the class group for display
this.getClassGroupForDataGetter(writeModel, dataGetter, data); this.getClassGroupForDataGetter(writeModel, dataGetter, data);
//Check whether institutional internal class exists
this.checkInstitutionalInternalClass(writeModel, data);
this.checkIfPageInternal(writeModel, data); this.checkIfPageInternal(writeModel, data);
} }
@ -295,6 +296,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//This is a class group page so //This is a class group page so
data.put("isClassGroupPage", true); data.put("isClassGroupPage", true);
data.put("includeAllClasses", true); data.put("includeAllClasses", true);
//Get the class group //Get the class group
this.getClassGroupForDataGetter(writeModel, dataGetter, data); this.getClassGroupForDataGetter(writeModel, dataGetter, data);
@ -337,8 +339,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//Check whether any classes exist with internal class restrictions //Check whether any classes exist with internal class restrictions
private void checkInstitutionalInternalClass(OntModel writeModel, private void checkInstitutionalInternalClass(Map<String, Object> data) {
Map<String, Object> data) {
OntModel mainModel = (OntModel) getServletContext().getAttribute("jenaOntModel"); OntModel mainModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
StmtIterator internalIt = mainModel.listStatements(null, ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), (RDFNode) null); StmtIterator internalIt = mainModel.listStatements(null, ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), (RDFNode) null);
//List<String> internalClasses = new ArrayList<String>(); //List<String> internalClasses = new ArrayList<String>();
@ -346,6 +347,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//internalClasses.add(internalIt.nextStatement().getResource().getURI()); //internalClasses.add(internalIt.nextStatement().getResource().getURI());
String internalClass = internalIt.nextStatement().getResource().getURI(); String internalClass = internalIt.nextStatement().getResource().getURI();
data.put("internalClass", internalClass); data.put("internalClass", internalClass);
data.put("internalClassUri", internalClass);
} }
} }

View file

@ -13,6 +13,7 @@ var menuManagementEdit = {
this.classesForClassGroup = $('#classesInSelectedGroup'); this.classesForClassGroup = $('#classesInSelectedGroup');
this.selectedGroupForPage = $('#selectedContentTypeValue'); this.selectedGroupForPage = $('#selectedContentTypeValue');
this.selectClassesMessage = $('#selectClassesMessage'); this.selectClassesMessage = $('#selectClassesMessage');
this.allClassesSelectedCheckbox = $('#allSelected');
}, },
bindEventListeners: function() { bindEventListeners: function() {
@ -24,6 +25,9 @@ var menuManagementEdit = {
this.selectClassGroupDropdown.change(function() { this.selectClassGroupDropdown.change(function() {
menuManagementEdit.chooseClassGroup(); menuManagementEdit.chooseClassGroup();
}); });
this.allClassesSelectedCheckbox.change(function() {
menuManagementEdit.toggleClassSelection();
});
}, },
showClassGroups: function() { showClassGroups: function() {
if(!this.existingContentType.hasClass("hidden")) { if(!this.existingContentType.hasClass("hidden")) {
@ -43,6 +47,17 @@ var menuManagementEdit = {
this.selectClassesMessage.removeClass("hidden"); this.selectClassesMessage.removeClass("hidden");
this.classesForClassGroup.removeClass("hidden"); this.classesForClassGroup.removeClass("hidden");
}, },
toggleClassSelection:function() {
/*To do: please fix so selecting all selects all classes and deselecting
* any class will deselect all
*/
/*
if(this.allClassesSelectedCheckbox.is(':checked')) {
$('#classInClassGroup').attr('checked', 'checked');
} else {
$('#classInClassGroup').removeAttr('checked');
}*/
},
chooseClassGroup: function() { chooseClassGroup: function() {
var url = "dataservice?getVClassesForVClassGroup=1&classgroupUri="; var url = "dataservice?getVClassesForVClassGroup=1&classgroupUri=";
@ -61,21 +76,23 @@ var menuManagementEdit = {
menuManagementEdit.selectedGroupForPage.html(results.classGroupName); menuManagementEdit.selectedGroupForPage.html(results.classGroupName);
//retrieve classes for class group and display with all selected //retrieve classes for class group and display with all selected
menuManagementEdit.classesForClassGroup.empty(); menuManagementEdit.classesForClassGroup.empty();
menuManagementEdit.classesForClassGroup.append('<ul id="selectedClasses" name="selectedClasses">'); var appendHtml = '<ul id="selectedClasses" name="selectedClasses">';
menuManagementEdit.classesForClassGroup.append('<li class="ui-state-default">' + appendHtml += '<ul id="selectedClasses" name="selectedClasses">';
'<input type="checkbox" name="allSelected" id="allSelected" value="all" checked/>' + appendHtml += '<li class="ui-state-default">' +
'<input type="checkbox" name="allSelected" id="allSelected" value="all" checked="checked" />' +
'<label class="inline" for="All"> All</label>' + '<label class="inline" for="All"> All</label>' +
'</li>'); '</li>';
$.each(results.classes, function(i, item) { $.each(results.classes, function(i, item) {
var thisClass = results.classes[i]; var thisClass = results.classes[i];
var thisClassName = thisClass.name; var thisClassName = thisClass.name;
//When first selecting new content type, all classes should be selected //When first selecting new content type, all classes should be selected
menuManagementEdit.classesForClassGroup.append(' <li class="ui-state-default">' + appendHtml += ' <li class="ui-state-default">' +
'<input type="checkbox" checked name="classInClassGroup" value="' + thisClass.URI + '" />' + '<input type="checkbox" checked="checked" name="classInClassGroup" value="' + thisClass.URI + '" />' +
'<label class="inline" for="' + thisClassName + '"> ' + thisClassName + '</label>' + '<label class="inline" for="' + thisClassName + '"> ' + thisClassName + '</label>' +
'</li>'); '</li>';
}); });
menuManagementEdit.classesForClassGroup.append("</ul>"); appendHtml += "</ul>";
menuManagementEdit.classesForClassGroup.append(appendHtml);
} }

View file

@ -94,14 +94,15 @@
<section id="internal-class" role="region"> <section id="internal-class" role="region">
<#if internalClass?has_content> <#if internalClass?has_content>
<#assign enableInternalClass = '<p>To enable this option, you must first select an institutional internal class for your instance</p>' /> <#assign enableInternalClass = '' />
<#assign disableClass = 'class="disable"' />
<#else>
<#assign enableInternalClass = '' />
<#assign disableClass = '' /> <#assign disableClass = '' />
<#else>
<#assign enableInternalClass = '<p>To enable this option, you must first select an institutional internal class for your instance</p>' />
<#assign disableClass = 'class="disable"' />
</#if> </#if>
<input type="checkbox" ${disableClass} name="display-internalClass" value="${internalClass}" id="display-internalClass" <#if pageInternalOnly?has_content>checked</#if> /> <input type="checkbox" ${disableClass} name="display-internalClass" value="${internalClassUri}" id="display-internalClass" <#if pageInternalOnly?has_content>checked</#if> />
<label ${disableClass} class="inline" for="display-internalClass">Only display <em>${associatedPage}</em> within my institution</label> <label ${disableClass} class="inline" for="display-internalClass">Only display <em>${associatedPage}</em> within my institution</label>
${enableInternalClass} ${enableInternalClass}