diff --git a/productMods/edit/forms/addPublicationToPerson.jsp b/productMods/edit/forms/addPublicationToPerson.jsp index 701bd385..09fb8f1f 100644 --- a/productMods/edit/forms/addPublicationToPerson.jsp +++ b/productMods/edit/forms/addPublicationToPerson.jsp @@ -33,6 +33,8 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode"%> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> @@ -45,13 +47,52 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers public static String nodeToPubProp = "http://vivoweb.org/ontology/core#linkedInformationResource"; %> <% + VitroRequest vreq = new VitroRequest(request); + + String subjectUri = vreq.getParameter("subjectUri"); + String predicateUri = vreq.getParameter("predicateUri"); + String objectUri = vreq.getParameter("objectUri"); + + Individual obj = (Individual) request.getAttribute("object"); + + EditMode mode = FrontEndEditingUtils.getEditMode(request, nodeToPubProp); + + /* + There are 3 modes that this form can be in: + 1. Add. There is a subject and a predicate but no position and nothing else. + + 2. Repair a bad role node. There is a subject, predicate and object but there is no individual on the + other end of the object's core:linkedInformationResource stmt. This should be similar to an add but the form should be expanded. + + 3. Really bad node. Multiple core:authorInAuthorship statements. + + This form does not currently support normal edit mode where there is a subject, an object, and an individual on + the other end of the object's core:linkedInformationResource statement. We redirect to the publication profile + to edit the publication. + */ + + if( mode == EditMode.ADD ) { + %> <% + } else if(mode == EditMode.EDIT){ + // Because it's edit mode, we already know there's one and only one statement + ObjectPropertyStatement ops = obj.getObjectPropertyStatements(nodeToPubProp).get(0); + String pubUri = ops.getObjectURI(); + String forwardToIndividual = pubUri != null ? pubUri : objectUri; + %> + + + + <% + } else if(mode == EditMode.REPAIR){ + %> <% + } + WebappDaoFactory wdf = vreq.getWebappDaoFactory(); vreq.setAttribute("defaultNamespace", ""); //empty string triggers default new URI behavior - String subjectUri = vreq.getParameter("subjectUri"); - String predicateUri = vreq.getParameter("predicateUri"); - String subjectName = ((Individual) request.getAttribute("subject")).getName(); + Individual subject = (Individual) request.getAttribute("subject"); + String subjectName = subject.getName(); vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri)); vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString())); @@ -59,39 +100,7 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers String intDatatypeUri = XSD.xint.toString(); vreq.setAttribute("intDatatypeUri", intDatatypeUri); vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri)); - - Individual subject = (Individual) request.getAttribute("subject"); - Individual obj = (Individual) request.getAttribute("object"); - - // Check to see if this is an edit of existing, if yes redirect to pub - if( obj != null ){ - List stmts = obj.getObjectPropertyStatements( nodeToPubProp ); - if( stmts != null && stmts.size() > 0 ){ - ObjectPropertyStatement ops = stmts.get(0); - String pubUri = ops.getObjectURI(); - if( pubUri != null ){ - %> - - - - <% - } - } - } - - /* This form is not prepared to deal with editing an existing relationship, so redirect - * to authorship page if no publication was found. This is not ideal, because you can't add - * a linked information resource from that page, but you can at least continue to the back end. - * May want to modify form in a future version to support repair mode. - */ - if (obj != null) { - String objectUri = obj.getURI(); - %> - - - - <% - } + %> @@ -219,10 +228,16 @@ SPARQL queries for existing values. --%> editConfig.addValidator(new PersonHasPublicationValidator()); Model model = (Model) application.getAttribute("jenaOntModel"); - String objectUri = (String) request.getAttribute("objectUri"); - editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing + + if (objectUri != null) { // editing existing (in this case, only repair is currently provided by the form) + editConfig.prepareForObjPropUpdate(model); + } else { // adding new + editConfig.prepareForNonUpdate(model); + } + // Return to person, not publication. See NIHVIVO-1464. // editConfig.setEntityToReturnTo("?pubUri"); + List customJs = new ArrayList(Arrays.asList(JavaScript.JQUERY_UI.path(), JavaScript.CUSTOM_FORM_UTILS.path(), "/js/browserUtils.js", @@ -237,11 +252,28 @@ SPARQL queries for existing values. --%> request.setAttribute("customCss", customCss); %> +<%-- Configure add vs. edit --%> + + + + + + + + + + + -

Create publication entry for <%= subjectName %>

+<% if( mode == EditMode.ERROR ){ %> +
This form is unable to handle the editing of this position because it is associated with + multiple Position individuals.
+<% }else{ %> + +

${titleVerb} publication entry for <%= subjectName %>

<%@ include file="unsupportedBrowserMessage.jsp" %> @@ -261,7 +293,7 @@ SPARQL queries for existing values. --%> -

+

* required fields

@@ -279,7 +311,12 @@ var customFormData = { sparqlForAcFilter: '${sparqlForAcFilter}', sparqlQueryUrl: '${sparqlQueryUrl}', acUrl: '${acUrl}', - submitButtonTextType: 'simple' + submitButtonTextType: 'simple', + editMode: '${editMode}', + defaultTypeName: 'publication' // used in repair mode to generate button text }; + +<% } %> + \ No newline at end of file diff --git a/productMods/edit/forms/js/customFormWithAutocomplete.js b/productMods/edit/forms/js/customFormWithAutocomplete.js index d174c730..91ae75c1 100644 --- a/productMods/edit/forms/js/customFormWithAutocomplete.js +++ b/productMods/edit/forms/js/customFormWithAutocomplete.js @@ -439,8 +439,9 @@ var customForm = { // e.g., 'Create Grant & Principal Investigator' buttonText = 'Create ' + typeText + ' & ' + baseButtonText; } else { - // e.g., 'Create Publication' - buttonText = 'Create ' + baseButtonText; + // In repair mode, baseButtonText is "Edit X". Keep that for this case. + // In add mode, baseButtonText is "X", so we get, e.g., "Create Publication" + buttonText = this.editMode == 'repair' ? baseButtonText : 'Create ' + baseButtonText; } } // Using existing related individual diff --git a/productMods/edit/forms/personHasEducationalTraining.jsp b/productMods/edit/forms/personHasEducationalTraining.jsp index f88b51e1..f5229a31 100644 --- a/productMods/edit/forms/personHasEducationalTraining.jsp +++ b/productMods/edit/forms/personHasEducationalTraining.jsp @@ -492,7 +492,6 @@ type is returned and we don't get a match to the select element options. --%> - ${editMode == "repair" ? "" : "disabled" } @@ -513,7 +512,7 @@ This goes to an experimental FM based form: multiple Position individuals. <% }else{ %> -

${titleVerb} education and training entry for <%= subjectName %>

+

${titleVerb} education and training entry for ${subjectName}

" >