vivo/productMods/edit/forms/personHasEducationalTraining.jsp

438 lines
17 KiB
Text
Raw Normal View History

<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%-- Custom form for adding an educational attainment to an individual
Classes:
core:EducationalTraining - primary new individual being created
foaf:Person - existing individual
foaf:Organization - new or existing individual
core:AcademicDegree - existing individual
Data properties of EducationalTraining:
core:majorField
core:departmentOrSchool
core:supplementalInformation
Object properties (domain : range)
core:educationalTraining (Person : EducationalTraining) - inverse of core:educationalTrainingOf
core:educationalTrainingOf (EducationalTraining : Person) - inverse of core:educationalTraining
core:degreeEarned (EducationalTraining : AcademicDegree) - inverse of core:degreeOutcomeOf
core:degreeOutcomeOf (AcademicDegree : EducationalTraining) - inverse of core:degreeEarned
core:organizationGrantingDegree (EducationalTraining : Organization) - no inverse
Future version
--------------
Classes:
core:DateTimeValue
core:DateTimeValuePrecision
Object properties:
core:dateTimeValue (EducationalTraining : DateTimeValue)
core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision)
--%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal"%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model"%>
<%@ page import="com.hp.hpl.jena.vocabulary.XSD" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.personHasEducationalBackground.jsp");
%>
<%
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior
request.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString()));
request.setAttribute("gYearDatatypeUriJson", MiscWebUtils.escape(XSD.gYear.toString()));
%>
<c:set var="vivoCore" value="http://vivoweb.org/ontology/core#" />
<c:set var="rdfs" value="<%= VitroVocabulary.RDFS %>" />
<c:set var="label" value="${rdfs}label" />
<c:set var="orgClass" value="http://xmlns.com/foaf/0.1/Organization" />
<c:set var="degreeClass" value="${vivoCore}AcademicDegree" />
<%-- Define predicates used in n3 assertions and sparql queries --%>
<c:set var="majorFieldPred" value="${vivoCore}majorField" />
<c:set var="yearPred" value="${vivoCore}year" />
<c:set var="deptPred" value="${vivoCore}departmentOrSchool" />
<c:set var="infoPred" value="${vivoCore}supplementalInformation" />
<c:set var="degreeEarned" value="${vivoCore}degreeEarned" />
<c:set var="degreeOutcomeOf" value="${vivoCore}degreeOutcomeOf" />
<c:set var="orgGrantingDegree" value="${vivoCore}organizationGrantingDegree" />
<%-- For new datetime handling in ontology - v1.2
<c:set var="dateTimeValue" value="${vivoCore}DateTimeValue" />
<c:set var="hasDateTimeValue" value="${vivoCore}dateTimeValue" />
<c:set var="precisionValue" value="${vivoCore}YearPrecision" />
<c:set var="hasPrecision" value="${vivoCore}dateTimePrecision" />
<v:jsonset var="existingYearQuery" >
SELECT ?existingYear WHERE {
?edTraining <${hasDateTimeValue}> ?existingYear . }
</v:jsonset>
<v:jsonset var="yearAssertion" >
@prefix core: <${vivoCore}> .
?dateTime a core:DateTimeValue ;
core:dateTime ?year ;
core:dateTimeValuePrecision core:YearPrecision .
?edTraining core:dateTimeValue ?dateTime .
</v:jsonset>
--%>
<%-- Assertions for adding a new educational training entry --%>
<v:jsonset var="orgTypeAssertion">
?org a ?orgType .
</v:jsonset>
<v:jsonset var="orgLabelAssertion">
?org <${label}> ?orgLabel .
</v:jsonset>
<v:jsonset var="degreeAssertion" >
?edTraining <${degreeEarned}> ?degree .
?degree <${degreeOutcomeOf}> ?edTraining .
</v:jsonset>
<v:jsonset var="majorFieldAssertion" >
?edTraining <${majorFieldPred}> ?majorField .
</v:jsonset>
<v:jsonset var="yearAssertion" >
?edTraining <${yearPred}> ?year .
</v:jsonset>
<v:jsonset var="deptAssertion" >
?edTraining <${deptPred}> ?dept .
</v:jsonset>
<v:jsonset var="infoAssertion" >
?edTraining <${infoPred}> ?info .
</v:jsonset>
<v:jsonset var="n3ForNewEdTraining">
@prefix core: <${vivoCore}> .
?person core:educationalTraining ?edTraining .
?edTraining a core:EducationalTraining ;
core:educationalTrainingOf ?person ;
<${orgGrantingDegree}> ?org .
</v:jsonset>
<%-- This property has no inverse --%>
<v:jsonset var="n3ForEdTrainingToOrg" >
?edTraining <${orgGrantingDegree}> ?org .
</v:jsonset>
<%-- Queries for editing an existing educational training entry --%>
<v:jsonset var="orgQuery" >
SELECT ?existingOrg WHERE {
?edTraining <${orgGrantingDegree}> ?existingOrg . }
</v:jsonset>
<v:jsonset var="orgLabelQuery" >
SELECT ?existingOrgLabel WHERE {
?edTraining <${orgGrantingDegree}> ?existingOrg .
?existingOrg <${label}> ?existingOrgLabel .
}
</v:jsonset>
<v:jsonset var="orgTypeQuery" >
SELECT ?existingOrgType WHERE {
?edTraining <${orgGrantingDegree}> ?existingOrg .
?existingOrg a ?existingOrgType .
}
</v:jsonset>
<v:jsonset var="degreeQuery" >
SELECT ?existingDegree WHERE {
?edTraining <${degreeEarned}> ?existingDegree . }
</v:jsonset>
<v:jsonset var="majorFieldQuery" >
SELECT ?existingMajorField WHERE {
?edTraining <${majorFieldPred}> ?existingMajorField . }
</v:jsonset>
<v:jsonset var="yearQuery" >
SELECT ?existingYear WHERE {
?edTraining <${yearPred}> ?existingYear . }
</v:jsonset>
<v:jsonset var="deptQuery" >
SELECT ?existingDept WHERE {
?edTraining <${deptPred}> ?existingDept . }
</v:jsonset>
<v:jsonset var="infoQuery" >
SELECT ?existingInfo WHERE {
?edTraining <${infoPred}> ?existingInfo . }
</v:jsonset>
<v:jsonset var="orgClassUriJson">${orgClass}</v:jsonset>
<v:jsonset var="degreeClassUriJson">${degreeClass}</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : ["person", "${subjectUriJson}" ],
"predicate" : ["predicate", "${predicateUriJson}" ],
"object" : ["edTraining", "${objectUriJson}", "URI" ],
"n3required" : [ "${n3ForNewEdTraining}", "${majorFieldAssertion}" ],
"n3optional" : [ "${n3ForEdTrainingToOrg}",
"${orgLabelAssertion}", "${orgTypeAssertion}",
"${degreeAssertion}", "${deptAssertion}", "${infoAssertion}", "${yearAssertion}" ],
"newResources" : { "edTraining" : "${defaultNamespace}",
"org" : "${defaultNamespace}" },
"urisInScope" : { },
"literalsInScope": { },
"urisOnForm" : [ "org", "orgType", "degree" ],
"literalsOnForm" : [ "orgLabel", "majorField", "year", "dept", "info" ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : {
"orgLabel" : "${orgLabelQuery}",
"majorField" : "${majorFieldQuery}",
"year" : "${yearQuery}",
"dept" : "${deptQuery}",
"info" : "${infoQuery}"
},
"sparqlForExistingUris" : {
"org" : "${orgQuery}",
"orgType" : "${orgTypeQuery}",
"degree" : "${degreeQuery}"
},
"fields" : {
"degree" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "INDIVIDUALS_VIA_VCLASS",
"literalOptions" : [ "Select one" ],
"predicateUri" : "",
"objectClassUri" : "${degreeClassUriJson}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${degreeAssertion}" ]
},
"majorField" : {
"newResource" : "false",
"validators" : [ "nonempty", "datatype:${stringDatatypeUriJson}" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
"rangeLang" : "",
"assertions" : [ "${majorFieldAssertion}" ]
},
"year" : {
"newResource" : "false",
"validators" : [ "datatype:${gYearDatatypeUriJson}" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "${gYearDatatypeUriJson}",
"rangeLang" : "",
"assertions" : ["${yearAssertion}"]
},
"org" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "INDIVIDUALS_VIA_VCLASS",
"literalOptions" : [ "Select one" ],
"predicateUri" : "",
"objectClassUri" : "${orgClassUriJson}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${n3ForEdTrainingToOrg}" ]
},
"orgLabel" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
"rangeLang" : "",
"assertions" : [ "${orgLabelAssertion}" ]
},
"orgType" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "CHILD_VCLASSES",
"literalOptions" : [ "Select one" ],
"predicateUri" : "",
"objectClassUri" : "${orgClassUriJson}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${orgTypeAssertion}" ]
},
"dept" : {
"newResource" : "false",
"validators" : [ "datatype:${stringDatatypeUriJson}" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
"rangeLang" : "",
"assertions" : ["${deptAssertion}"]
},
"info" : {
"newResource" : "false",
"validators" : [ "datatype:${stringDatatypeUriJson}" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
"rangeLang" : "",
"assertions" : ["${infoAssertion}"]
}
}
}
</c:set>
<%
log.debug(request.getAttribute("editjson"));
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
if (editConfig == null) {
editConfig = new EditConfiguration((String) request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig,session);
}
Model model = (Model) application.getAttribute("jenaOntModel");
String objectUri = (String) request.getAttribute("objectUri");
if (objectUri != null) { // editing existing
editConfig.prepareForObjPropUpdate(model);
} else { // adding new
editConfig.prepareForNonUpdate(model);
}
String subjectName = ((Individual) request.getAttribute("subject")).getName();
%>
<c:set var="subjectName" value="<%= subjectName %>" />
<%
if (objectUri != null) { // editing existing entry
%>
<c:set var="editMode" value="edit" />
<c:set var="titleVerb" value="Edit" />
<c:set var="title" value="Edit educational background entry for ${subjectName}" />
<c:set var="submitButtonText" value="Edit Educational Training" />
<c:set var="disabledVal" value="disabled" />
<%
} else { // adding new entry
%>
<c:set var="editMode" value="add" />
<c:set var="titleVerb" value="Create" />
<c:set var="submitButtonText" value="Educational Training" />
<c:set var="disabledVal" value="" />
<% }
List<String> customJs = new ArrayList<String>(Arrays.asList(JavaScript.JQUERY_UI.path(),
JavaScript.CUSTOM_FORM_UTILS.path(),
"/edit/forms/js/customFormWithAutocomplete.js"
));
request.setAttribute("customJs", customJs);
List<String> customCss = new ArrayList<String>(Arrays.asList(Css.JQUERY_UI.path(),
Css.CUSTOM_FORM.path(),
"/edit/forms/css/autocomplete.css",
"/edit/forms/css/customFormWithAutocomplete.css"
));
request.setAttribute("customCss", customCss);
%>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<c:set var="yearHint" value="<span class='hint'>(YYYY)</span>" />
<jsp:include page="${preForm}" />
<h2>${titleVerb}&nbsp;educational training entry for <%= subjectName %></h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<p class="inline"><v:input type="select" label="Organization Type ${requiredHint}" name="orgType" disabled="${disabledVal}" id="typeSelector" /></p>
<div class="fullViewOnly">
<p><v:input type="text" id="relatedIndLabel" name="orgLabel" label="Name ${requiredHint}" cssClass="acSelector" disabled="${disabledVal}" size="50" /></p>
<%-- Store these values in hidden fields, because the displayed fields are disabled and don't submit. This ensures that when
returning from a validation error, we retain the values. --%>
<c:if test="${editMode == 'edit'}">
<v:input type="hidden" id="orgType" />
<v:input type="hidden" id="orgLabel" />
</c:if>
<div class="acSelection">
<%-- RY maybe make this a label and input field. See what looks best. --%>
<p class="inline"><label></label><span class="acSelectionInfo"></span> <a href="<c:url value="/individual?uri=" />" class="verifyMatch">(Verify this match)</a></p>
<v:input type="hidden" id="org" cssClass="acUriReceiver" /> <!-- Field value populated by JavaScript -->
</div>
<v:input type="select" label="Degree" id="degree" />
<v:input type="text" label="Major Field of Degree ${requiredHint}" id="majorField" size="30" />
<v:input type="text" label="Year ${yearHint}" id="year" size="4" />
<v:input type="text" label="Department or School Name within the Organization" id="dept" size="50" />
<v:input type="text" label="Supplemental Information" id="info" size="50" />
<p>e.g., <em>Postdoctoral training</em> or <em>Transferred</em></p>
</div>
<p class="submit"><v:input type="submit" id="submit" value="${submitButtonText}" cancel="true"/></p>
<p id="requiredLegend" class="requiredHint">* required fields</p>
</form>
<c:url var="acUrl" value="/autocomplete?tokenize=true&stem=true" />
<script type="text/javascript">
var customFormData = {
acUrl: '${acUrl}',
editMode: '${editMode}',
submitButtonTextType: 'compound'
};
</script>
<jsp:include page="${postForm}"/>