diff --git a/productMods/js/menupage/processDataGetterUtils.js b/productMods/js/menupage/processDataGetterUtils.js new file mode 100644 index 00000000..277b72ba --- /dev/null +++ b/productMods/js/menupage/processDataGetterUtils.js @@ -0,0 +1,31 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +//This class is responsible for the product-specific form processing/content selection that might be possible +//Overrides the usual behavior of selecting the specific JavaScript class needed to convert the form inputs +//into a JSON object for submission based on the page content type +//VIVO Specific version includes individuals for classes data getter in addition to the others +//The internal class specific processor class is in VIVO, while all other javascript files are in Vitro + +var processDataGetterUtils = { + dataGetterProcessorMap:{"browseClassGroup": processClassGroupDataGetterContent, + "sparqlQuery": processSparqlDataGetterContent, + "fixedHtml":processFixedHTMLDataGetterContent, + "internalClass":processInternalClassDataGetterContent}, + selectDataGetterType:function(pageContentSection) { + var contentType = pageContentSection.attr("contentType"); + //The form can provide "browse class group" as content type but need to check + //whether this is in fact individuals for classes instead + if(contentType == "browseClassGroup") { + //Is ALL NOT selected and there are other classes, pick one + //this SHOULD be an array + var allClassesSelected = pageContentSection.find("input[name='allSelected']:checked"); + var isInternalSelected = pageContentSection.find("input[name='display-internalClass']:checked"); + //If all NOT selected then need to pick a different content type OR if internal class selected + if( isInternalSelected.length > 0 || allClassesSelected.length == 0) { + contentType = "internalClass"; + } + } + + return contentType; + } +}; \ No newline at end of file diff --git a/productMods/js/menupage/processInternalClassDataGetterContent.js b/productMods/js/menupage/processInternalClassDataGetterContent.js new file mode 100644 index 00000000..17cdf132 --- /dev/null +++ b/productMods/js/menupage/processInternalClassDataGetterContent.js @@ -0,0 +1,30 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var processIndividualsForClassesDataGetterContent = { + dataGetterClass:null, + //can use this if expect to initialize from elsewhere + initProcessor:function(dataGetterClassInput) { + this.dataGetterClass = dataGetterClassInput; + }, + //Do we need a separate content type for each of the others? + processPageContentSection:function(pageContentSection) { + //Get classes selected + var classesSelected = []; + pageContentSection.find("input[name='classInClassGroup']:checked").each(function(){ + //Need to make sure that the class is also saved as a URI + classesSelected.push($(this).val()); + }); + //If internal class selected, include here + var isInternal:false; + //if this checkbox is checked, then isInternal should be true + pageContentSection.find("input[name='display-internalClass']:checked").each(function() { + isInternal:true; + }); + var returnObject = {classGroup:classGroup, + classesSelectedInClassGroup:classesSelected, + isInternal:isInternal, + dataGetterClass:this.dataGetterClass}; + return returnObject; + } + +} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java new file mode 100644 index 00000000..fd69cdb6 --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java @@ -0,0 +1,101 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; + +import java.util.Collection; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import com.hp.hpl.jena.rdf.model.Literal; + +import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import net.sf.json.JSONSerializer; +//Returns the appropriate n3 for selection of classes from within class group +public class ProcessInternalClassDataGetterN3 extends ProcessIndividualsForClassesDataGetterN3 { + private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.InternalClassesDataGetter"; + + private static String internalClassVarNameBase = "isInternal"; + public ProcessInternalClassDataGetterN3(JSONObject jsonObject){ + super(jsonObject); + + } + //Pass in variable that represents the counter + + //Original menu managemenet didn't include the top level class group as type for internal classes + //That can be included here if need be, but for now just adding the type alone + public List retrieveN3Required(int counter) { + List requiredN3 = new ArrayList(); + String partialN3 = this.getN3ForTypePartial(counter) + "."; + requiredN3.add(getPrefixes() + partialN3); + requiredN3.addAll(this.addIndividualClassesN3(counter)); + return requiredN3; + + } + + + //returns n3 defining internal class + private List addInternalClassN3(int counter) { + List internalClassN3 = new ArrayList(); + String dataGetterVar = getDataGetterVar(counter); + internalClassN3.add(dataGetterVar + "<" + DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL + "> " + + this.getN3VarName(internalClassVarNameBase, counter) + " ."); + return internalClassN3; + + } + + public List retrieveN3Optional(int counter) { + List optionalN3 = new ArrayList(); + //If internal add that as well + optionalN3.addAll(this.addInternalClassN3(counter)); + return optionalN3; + } + + //These methods will return the literals and uris expected within the n3 + //and the counter is used to ensure they are numbered correctly + + public List retrieveLiteralsOnForm(int counter) { + //no literals, just the class group URI + List literalsOnForm = new ArrayList(); + literalsOnForm.add(getVarName(internalClassVarNameBase, counter)); + return literalsOnForm; + + } + + //URIs on form are same as individuals for class group so no need to reimplement + + + + public List retrieveFields(int counter) { + List fields = super.retrieveFields(counter); + fields.add(new FieldVTwo().setName(getVarName(internalClassVarNameBase, counter))); + + return fields; + } + + //These var names match the names of the elements within the json object returned with the info required for the data getter + + public List getLiteralVarNamesBase() { + return Arrays.asList(internalClassVarNameBase); + } + + //these are for the fields ON the form + public List getUriVarNamesBase() { + return Arrays.asList(individualClassVarNameBase); + } + + @Override + public String getClassType() { + return classType; + } + + +} + +