From 6f5636a9c5adc11b3e099cf86420912b5f49db63 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 11 Jun 2010 21:11:19 +0000 Subject: [PATCH] NIHVIVO-646 add authors to publications custom form --- .../forms/addAuthorsToInformationResource.jsp | 142 ++++++++++++++++++ .../css/addAuthorsToInformationResource.css | 47 ++++++ productMods/edit/forms/css/customForm.css | 4 - .../js/addAuthorsToInformationResource.js | 49 ++++++ productMods/edit/forms/js/customForm.js | 2 +- .../forms/personHasEducationalBackground.jsp | 108 +++++++------ 6 files changed, 300 insertions(+), 52 deletions(-) create mode 100644 productMods/edit/forms/addAuthorsToInformationResource.jsp create mode 100644 productMods/edit/forms/css/addAuthorsToInformationResource.css create mode 100644 productMods/edit/forms/js/addAuthorsToInformationResource.js diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp new file mode 100644 index 00000000..fbe81e6e --- /dev/null +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -0,0 +1,142 @@ +<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> + +<%-- Custom form for adding authors to information resources + +Classes: +core:InformationResource - the information resource being edited +core:Authorship - primary new individual being created +foaf:Person - new or existing individual + +Data properties of Authorship: +core:authorRank + +Object properties (domain : range) + +core:informationResourceInAuthorship (InformationResource : Authorship) +core:linkedInformationResource (Authorship : InformationResource) - inverse of informationResourceInAuthorship + +core:linkedAuthor (Authorship : Person) +core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor + +--%> + +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="java.util.Arrays" %> + +<%@ 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" %> + +<%@ 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.addAuthorsToInformationResource.jsp"); +%> +<% + VitroRequest vreq = new VitroRequest(request); + WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior + + String flagUri = null; + if (wdf.getApplicationDao().isFlag1Active()) { + flagUri = VitroVocabulary.vitroURI+"Flag1Value"+vreq.getPortal().getPortalId()+"Thing"; + } else { + flagUri = wdf.getVClassDao().getTopConcept().getURI(); // fall back to owl:Thing if not portal filtering + } + vreq.setAttribute("flagUri",flagUri); + + vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); + + String subjectUri = vreq.getParameter("subjectUri"); + String predicateUri = vreq.getParameter("predicateUri"); + Individual infoResource = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); + List authorships = infoResource.getRelatedIndividuals(predicateUri); + vreq.setAttribute("infoResourceName", infoResource.getName()); + + String linkedAuthorProperty = "http://vivoweb.org/ontology/core#linkedAuthor"; + + List customJs = new ArrayList(Arrays.asList("forms/js/addAuthorsToInformationResource.js")); + request.setAttribute("customJs", customJs); + + List customCss = new ArrayList(Arrays.asList("forms/css/customForm.css", + "forms/css/addAuthorsToInformationResource.css" + )); + request.setAttribute("customCss", customCss); +%> + + + + + + + +

${title}

+ +
    + <% + for ( Individual authorship : authorships ) { + List authors = authorship.getRelatedIndividuals(linkedAuthorProperty); + if ( !authors.isEmpty() ) { + Individual author = authors.get(0); + String authorName = getAuthorName(author); + %> + +
  • <%= authorName %>Remove
  • + + <% + } + } + + %> + +
+ + + +
" > + +

+

${initialHint}

+

${initialHint}

+ + + +

+ +

* required fields

+
+ + + +<%! +public String getAuthorName(Individual author) { + String name; + + String lastName = author.getDataValue("http://xmlns.com/foaf/0.1/lastName"); + String firstName = author.getDataValue("http://xmlns.com/foaf/0.1/firstName"); + + if (lastName != null && firstName != null) { + name = lastName + ", " + firstName; + String middleName = author.getDataValue("http://vivoweb.org/ontology/core#middleName"); + if (middleName != null) { + name += " " + middleName; + } + } + else { + name = author.getName(); + } + return name; +} + +%> diff --git a/productMods/edit/forms/css/addAuthorsToInformationResource.css b/productMods/edit/forms/css/addAuthorsToInformationResource.css new file mode 100644 index 00000000..481a4760 --- /dev/null +++ b/productMods/edit/forms/css/addAuthorsToInformationResource.css @@ -0,0 +1,47 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +ul.authors { + margin-left: 0; +} + +ul.authors li { + list-style: none; + margin-bottom: .75em; +} + +ul.authors span.authorName { + display: inline-block; + width: 15em; +} + +/* Hide elements not used in non-JS version of form */ +#showFormButton, +a.remove { + display: none; +} + +#content form p.inline { + clear: left; + margin-bottom: 0; + padding-top: 1em; +} + +#content form p.inline input, +#content form p.inline label { + float: left; + clear: none; +} + +#content form p.inline label { + width: 10em; + margin-top: 0; + +} + +#content form p.inline input { + margin-bottom: 0; +} + +#content form p.inline span.hint { + margin-left: .5em; +} diff --git a/productMods/edit/forms/css/customForm.css b/productMods/edit/forms/css/customForm.css index d81f9a69..e914ae7d 100644 --- a/productMods/edit/forms/css/customForm.css +++ b/productMods/edit/forms/css/customForm.css @@ -1,9 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -#content form { -/* width: 50%;*/ -} - #content form div { clear: left; } diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js new file mode 100644 index 00000000..7ccb6a1b --- /dev/null +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -0,0 +1,49 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var addAuthorForm = { + + onLoad: function() { + + this.initObjects(); + this.adjustForJs(); + this.initForm(); + }, + + + // On page load, create references within the customForm scope to DOM elements. + // NB These must be assigned after the elements have been loaded onto the page. + initObjects: function() { + + this.form = $('#addAuthorForm'); + this.showFormButton = $('#showAddForm'); + this.removeLinks = $('a.remove'); + }, + + // On page load, make changes to the non-Javascript version for the Javascript version. + // These are features that will NOT CHANGE throughout the workflow of the Javascript version. + adjustForJs: function() { + + // Show elements that are hidden by css on load since not used in non-JS version + this.showFormButton.show(); + this.removeLinks.show(); + + this.form.hide(); + }, + + initForm: function() { + + this.showFormButton.bind('click', function() { + $(this).hide(); + addAuthorForm.form.show(); + }); + }, + + toggleRemoveLink: function() { + // when clicking remove: remove the author, and change link text to "undo" + // when clicking undo: add the author back, and change link text to "remove" + } +} + +$(document).ready(function() { + addAuthorForm.onLoad(); +}); \ No newline at end of file diff --git a/productMods/edit/forms/js/customForm.js b/productMods/edit/forms/js/customForm.js index 3a3a058c..7d4d6d97 100644 --- a/productMods/edit/forms/js/customForm.js +++ b/productMods/edit/forms/js/customForm.js @@ -479,6 +479,6 @@ var customForm = { }; -$(document).ready(function(){ +$(document).ready(function() { customForm.onLoad(); }); diff --git a/productMods/edit/forms/personHasEducationalBackground.jsp b/productMods/edit/forms/personHasEducationalBackground.jsp index a2758f88..523c7f1a 100644 --- a/productMods/edit/forms/personHasEducationalBackground.jsp +++ b/productMods/edit/forms/personHasEducationalBackground.jsp @@ -1,5 +1,34 @@ <%-- $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:EducationalAttainment - primary new individual being created +foaf:Person - existing individual +foaf:Organization - new or existing individual +core:AcademicDegree - existing individual +core:DateTimeValue +core:DateTimeValuePrecision + +Data properties of EducationalAttainment: +core:majorField +core:departmentOrSchool +core:supplementalInformation + +Object properties (domain : range) + +core:educationalBackground (Person : EducationalAttainment) - inverse of educationalBackgroundOf +core:educationalBackgroundOf (EducationalAttainment : Person) - inverse of educationalBackground + +core:degreeTypeAwarded (EducationalAttainment : AcademicDegree) - inverse of awardedTo +core:awardedTo (AcademicDegree : EducationalAttainment) - inverse of degreeTypeAwarded + +core:organizationGrantingDegree (EducationalAttainment : Organization) - no inverse + +core:dateTimeValue (EducationalAttainment : DateTimeValue) +core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) +--%> + <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> @@ -42,34 +71,11 @@ %> - - + -<%-- -Classes: -core:EducationalAttainment - primary new individual being created -foaf:Person - existing individual -foaf:Organization - new or existing individual -core:AcademicDegree - existing individual - -Data properties of EducationalAttainment: -core:majorField -core:year -core:departmentOrSchool -core:supplementalInformation - -Object properties (domain : range) - -core:educationalBackground (Person : EducationalAttainment) - inverse of educationalBackgroundOf -core:educationalBackgroundOf (EducationalAttainment : Person) - inverse of educationalBackground - -core:degreeTypeAwarded (EducationalAttainment : AcademicDegree) - inverse of awardedTo -core:awardedTo (AcademicDegree : EducationalAttainment) - inverse of degreeTypeAwarded - -core:organizationGrantingDegree (EducationalAttainment : Organization) - no inverse <%-- Data properties --%> <%-- Then enter a SPARQL query for each field, by convention concatenating the field id with "Existing" @@ -79,41 +85,49 @@ core:organizationGrantingDegree (EducationalAttainment : Organization) - no inve SELECT ?majorFieldExisting WHERE { - ?edBackgroundUri <${majorFieldPred}> ?majorFieldExisting } + ?edAttainmentUri <${majorFieldPred}> ?majorFieldExisting } <%-- Pair the "existing" query with the skeleton of what will be asserted for a new statement involving this field. The actual assertion inserted in the model will be created via string substitution into the ? variables. NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%> - ?edBackgroundUri <${majorFieldPred}> ?majorField . + ?edAttainmentUri <${majorFieldPred}> ?majorField . - + + + + + SELECT ?existingYear WHERE { - ?edBackgroundUri <${yearPred}> ?existingYear } + ?edAttainmentUri <${hasDateTimeValue}> ?existingYear } - - ?edBackgroundUri <${yearPred}> ?year . + + @prefix core: <${vivoCore}> . + ?dateTime a core:DateTimeValue ; + core:dateTime ?year ; + core:dateTimeValuePrecision core:YearPrecision . + ?edAttainmentUri core:dateTimeValue ?dateTime . SELECT ?existingDept WHERE { - ?edBackgroundUri <${deptPred}> ?existingDept } + ?edAttainmentUri <${deptPred}> ?existingDept } - ?edBackgroundUri <${deptPred}> ?dept . + ?edAttainmentUri <${deptPred}> ?dept . SELECT ?existingInfo WHERE { - ?edBackgroundUri <${infoPred}> ?existingInfo } + ?edAttainmentUri <${infoPred}> ?existingInfo } - ?edBackgroundUri <${infoPred}> ?info . + ?edAttainmentUri <${infoPred}> ?info . <%-- Object properties --%> @@ -124,21 +138,21 @@ core:organizationGrantingDegree (EducationalAttainment : Organization) - no inve SELECT ?existingDegreeUri WHERE { - ?edBackgroundUri <${hasDegree}> ?existingDegreeUri } + ?edAttainmentUri <${hasDegree}> ?existingDegreeUri } - ?edBackgroundUri <${hasDegree}> ?degreeUri . - ?degreeUri <${degreeFor}> ?edBackgroundUri . + ?edAttainmentUri <${hasDegree}> ?degreeUri . + ?degreeUri <${degreeFor}> ?edAttainmentUri . <%-- This property has no inverse --%> SELECT ?existingOrgUri WHERE { - ?edBackgroundUri <${orgGrantingDegree}> ?existingOrgUri } + ?edAttainmentUri <${orgGrantingDegree}> ?existingOrgUri } - ?edBackgroundUri <${orgGrantingDegree}> ?organizationUri . + ?edAttainmentUri <${orgGrantingDegree}> ?organizationUri . @@ -153,9 +167,9 @@ the org type still gets asserted. --%> @prefix core: <${vivoCore}> . - ?person core:educationalBackground ?edBackgroundUri . + ?person core:educationalBackground ?edAttainmentUri . - ?edBackgroundUri core:educationalBackgroundOf ?person ; + ?edAttainmentUri core:educationalBackgroundOf ?person ; a core:EducationalAttainment , <${flagURI}> . @@ -165,10 +179,10 @@ the org type still gets asserted. --%> a ?newOrgType , <${flagURI}> . - ?edBackgroundUri <${orgGrantingDegree}> ?newOrg . + ?edAttainmentUri <${orgGrantingDegree}> ?newOrg . -${edBackgroundClass} +${edAttainmentClass} ${orgClass} ${degreeClass} @@ -180,7 +194,7 @@ the org type still gets asserted. --%> "subject" : ["person", "${subjectUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ], - "object" : ["edBackgroundUri", "${objectUriJson}", "URI" ], + "object" : ["edAttainmentUri", "${objectUriJson}", "URI" ], "n3required" : [ "${n3ForStmtToPerson}", "${degreeAssertion}", "${majorFieldAssertion}", "${yearAssertion}" ], @@ -188,7 +202,7 @@ the org type still gets asserted. --%> "${n3ForNewOrg}", "${newOrgNameAssertion}", "${newOrgTypeAssertion}", "${deptAssertion}", "${infoAssertion}" ], - "newResources" : { "edBackgroundUri" : "${defaultNamespace}", + "newResources" : { "edAttainmentUri" : "${defaultNamespace}", "newOrg" : "${defaultNamespace}" }, "urisInScope" : { }, @@ -233,12 +247,12 @@ the org type still gets asserted. --%> }, "year" : { "newResource" : "false", - "validators" : [ "nonempty", "datatype:${gYearDatatypeUriJson}" ], + "validators" : [ "nonempty" ], "optionsType" : "UNDEFINED", "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", - "rangeDatatypeUri" : "${gYearDatatypeUriJson}", + "rangeDatatypeUri" : "http://www.w3.org/2001/XMLSchema#dateTime", "rangeLang" : "", "assertions" : ["${yearAssertion}"] },