NIHVIVO-646 Adding an existing person as an author on the add authors to publications form

This commit is contained in:
rjy7 2010-06-22 17:52:37 +00:00
parent ac6ccc2981
commit 98c027b00c
6 changed files with 172 additions and 61 deletions

View file

@ -3,7 +3,7 @@
xmlns:j.0="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#" > xmlns:j.0="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#" >
<rdf:Description rdf:about="http://vivoweb.org/ontology/core#pmcid"> <rdf:Description rdf:about="http://vivoweb.org/ontology/core#pmcid">
<j.0:hiddenFromDisplayBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/> <j.0:hiddenFromDisplayBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/>
<j.0:prohibitedFromUpdateBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/> <j.0:prohibitedFrinformationResourceHasomUpdateBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about="http://vivoweb.org/ontology/core#nihmsid"> <rdf:Description rdf:about="http://vivoweb.org/ontology/core#nihmsid">
<j.0:hiddenFromDisplayBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/> <j.0:hiddenFromDisplayBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/>
@ -1796,6 +1796,7 @@
<j.0:offerCreateNewOptionAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:offerCreateNewOptionAnnot> <j.0:offerCreateNewOptionAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:offerCreateNewOptionAnnot>
<j.0:objectIndividualSortProperty rdf:resource="http://vivoweb.org/ontology/core#authorRank"/> <j.0:objectIndividualSortProperty rdf:resource="http://vivoweb.org/ontology/core#authorRank"/>
<j.0:prohibitedFromUpdateBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/> <j.0:prohibitedFromUpdateBelowRoleLevelAnnot rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/role#public"/>
<j.0:customEntryFormAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#string">addAuthorsToInformationResource.jsp</j.0:customEntryFormAnnot>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about="http://purl.org/ontology/bibo/isbn10"> <rdf:Description rdf:about="http://purl.org/ontology/bibo/isbn10">
<j.0:displayLimitAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</j.0:displayLimitAnnot> <j.0:displayLimitAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</j.0:displayLimitAnnot>

View file

@ -32,7 +32,7 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> <%@ 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.edit.n3editing.EditConfiguration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.CreateLabelFromNameFields"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ 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.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
@ -69,6 +69,7 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor
<c:set var="rdfs" value="<%= VitroVocabulary.RDFS %>" /> <c:set var="rdfs" value="<%= VitroVocabulary.RDFS %>" />
<c:set var="label" value="${rdfs}label" /> <c:set var="label" value="${rdfs}label" />
<c:set var="foaf" value="http://xmlns.com/foaf/0.1/" /> <c:set var="foaf" value="http://xmlns.com/foaf/0.1/" />
<c:set var="personClassUri" value="${foaf}Person" />
<%-- Unlike other custom forms, this form does not allow edits of existing authors, so there are no <%-- Unlike other custom forms, this form does not allow edits of existing authors, so there are no
SPARQL queries for existing values. --%> SPARQL queries for existing values. --%>
@ -125,6 +126,8 @@ SPARQL queries for existing values. --%>
?newPerson core:authorInAuthorship ?authorshipUri . ?newPerson core:authorInAuthorship ?authorshipUri .
</v:jsonset> </v:jsonset>
<v:jsonset var="personClassUriJson">${personClassUri}</v:jsonset>
<c:set var="returnPathAfterSubmit" value="/edit/editRequestDispatch.jsp?subjectUri=${subjectUri}&predicateUri=${predicateUri}" /> <c:set var="returnPathAfterSubmit" value="/edit/editRequestDispatch.jsp?subjectUri=${subjectUri}&predicateUri=${predicateUri}" />
<c:set var="editjson" scope="request"> <c:set var="editjson" scope="request">
@ -169,7 +172,7 @@ SPARQL queries for existing values. --%>
}, },
"firstName" : { "firstName" : {
"newResource" : "false", "newResource" : "false",
"validators" : [ "nonempty", "datatype:${stringDatatypeUriJson}" ], "validators" : [ "datatype:${stringDatatypeUriJson}" ],
"optionsType" : "UNDEFINED", "optionsType" : "UNDEFINED",
"literalOptions" : [ ], "literalOptions" : [ ],
"predicateUri" : "", "predicateUri" : "",
@ -191,7 +194,7 @@ SPARQL queries for existing values. --%>
}, },
"lastName" : { "lastName" : {
"newResource" : "false", "newResource" : "false",
"validators" : [ "nonempty", "datatype:${stringDatatypeUriJson}" ], "validators" : [ "datatype:${stringDatatypeUriJson}" ],
"optionsType" : "UNDEFINED", "optionsType" : "UNDEFINED",
"literalOptions" : [ ], "literalOptions" : [ ],
"predicateUri" : "", "predicateUri" : "",
@ -210,6 +213,17 @@ SPARQL queries for existing values. --%>
"rangeDatatypeUri" : "${intDatatypeUriJson}", "rangeDatatypeUri" : "${intDatatypeUriJson}",
"rangeLang" : "", "rangeLang" : "",
"assertions" : ["${authorshipRankAssertion}"] "assertions" : ["${authorshipRankAssertion}"]
},
"personUri" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "${personClassUriJson}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : ["${n3ForExistingPerson}"]
} }
} }
} }
@ -224,11 +238,7 @@ SPARQL queries for existing values. --%>
EditConfiguration.putConfigInSession(editConfig,session); EditConfiguration.putConfigInSession(editConfig,session);
} }
// Doing this in Javascript instead. //editConfig.addValidator(new PublicationHasAuthorValidator());
// For now the field names in CreateLabelFromFieldNames.processEditSubmission() are
// hard-coded. If we want flexibility in naming them, we can pass in a map of
// the field names when creating the preprocessor.
// editConfig.addEditSubmissionPreprocessor(new CreateLabelFromNameFields(editConfig));
Model model = (Model) application.getAttribute("jenaOntModel"); Model model = (Model) application.getAttribute("jenaOntModel");
String objectUri = (String) request.getAttribute("objectUri"); String objectUri = (String) request.getAttribute("objectUri");
@ -295,22 +305,33 @@ SPARQL queries for existing values. --%>
</ul> </ul>
<%
if (authorships.size() == 0) {
%><p>This publication currently has no authors specified.</p><%
}
%>
<div id="showAddForm"> <div id="showAddForm">
<v:input type="submit" value="Add Author" id="showAddFormButton" cancel="true" cancelLabel="Return to Publication" cancelUrl="/individual" /> <v:input type="submit" value="Add Author" id="showAddFormButton" cancel="true" cancelLabel="Return to Publication" cancelUrl="/individual" />
</div> </div>
<form id="addAuthorForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" > <form id="addAuthorForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<h3>Add an Author</h3>
<p class="inline"><v:input type="text" id="lastName" label="Last name ${requiredHint}" size="30" /></p> <p class="inline"><v:input type="text" id="lastName" label="Last name ${requiredHint}" size="30" /></p>
<p class="inline"><v:input type="text" id="firstName" label="First name ${requiredHint}" size="20" />${initialHint}</p> <p class="inline"><v:input type="text" id="firstName" label="First name ${requiredHint}" size="20" />${initialHint}</p>
<p class="inline"><v:input type="text" id="middleName" label="Middle name" size="20" />${initialHint}</p> <p class="inline"><v:input type="text" id="middleName" label="Middle name" size="20" />${initialHint}</p>
<input type="hidden" id="label" name="label" value="" /> <!-- Field value populated by JavaScript -->
<div id="selectedAuthor">
<%-- RY maybe make this a label and input field. See what looks best. --%>
<p class="inline"><label>Selected author: </label><span id="selectedAuthorName"></span></p>
<input type="hidden" id="personUri" name="personUri" value="" /> <!-- Field value populated by JavaScript -->
</div>
<input type="hidden" name="rank" value="${rank}" /> <input type="hidden" name="rank" value="${rank}" />
<input type="hidden" name="acUrl" id="acUrl" value="<c:url value="/autocomplete?type=${foaf}Person" />" /> <input type="hidden" name="acUrl" id="acUrl" value="<c:url value="/autocomplete?type=${foaf}Person" />" />
<!-- Field values populated by JavaScript -->
<input type="hidden" id="label" name="label" value="" />
<input type="hidden" id="personUri" name="personUri" value="" />
<p class="submit"><v:input type="submit" id="submit" value="Add Author" cancel="true" /></p> <p class="submit"><v:input type="submit" id="submit" value="Add Author" cancel="true" /></p>

View file

@ -16,7 +16,8 @@
/* Hide elements not used in non-JS version of form */ /* Hide elements not used in non-JS version of form */
#showAddForm, #showAddForm,
a.remove { a.remove,
#selectedAuthor {
display: none; display: none;
} }
@ -28,6 +29,10 @@ a.remove {
margin-left: 2em; margin-left: 2em;
} }
form h3 {
margin-bottom: .5em;
}
form a:link.cancel, form a:visited.cancel, form a:link.cancel, form a:visited.cancel,
#authors a:link.remove, #authors a:visited.remove, #authors a:link.remove, #authors a:visited.remove,
#showAddForm a:link.cancel, #showAddForm a:visited.cancel { #showAddForm a:link.cancel, #showAddForm a:visited.cancel {
@ -67,3 +72,7 @@ form a:hover.cancel,
#content form p.inline span.hint { #content form p.inline span.hint {
margin-left: .5em; margin-left: .5em;
} }
#selectedAuthor {
clear: left;
}

View file

@ -103,3 +103,14 @@ option {
#content form textarea { #content form textarea {
width: 30%; width: 30%;
} }
/* jQuery UI autocomplete */
ul.ui-autocomplete {
font-size: .95em;
}
li.ui-menu-item a.ui-corner-all {
text-align: left;
padding-left: .25em;
}

View file

@ -6,8 +6,7 @@ var addAuthorForm = {
this.mixIn(); this.mixIn();
this.initObjects(); this.initObjects();
this.adjustForJs(); this.initPage();
this.initForm();
}, },
mixIn: function() { mixIn: function() {
@ -15,12 +14,12 @@ var addAuthorForm = {
vitro.utils.borrowMethods(vitro.customFormUtils, this); vitro.utils.borrowMethods(vitro.customFormUtils, this);
}, },
// On page load, create references within the customForm scope to DOM elements. // On page load, create references within the addAuthorForm scope to DOM elements.
// NB These must be assigned after the elements have been loaded onto the page. // NB These must be assigned after the elements have been loaded onto the page.
initObjects: function() { initObjects: function() {
this.form = $('#addAuthorForm'); this.form = $('#addAuthorForm');
this.showFormDiv = $('#showAddForm'); this.showFormButtonWrapper = $('#showAddForm');
this.showFormButton = $('#showAddFormButton'); this.showFormButton = $('#showAddFormButton');
this.removeLinks = $('a.remove'); this.removeLinks = $('a.remove');
this.submit = this.form.find(':submit'); this.submit = this.form.find(':submit');
@ -32,42 +31,103 @@ var addAuthorForm = {
this.personUriField = $('#personUri'); this.personUriField = $('#personUri');
this.firstNameWrapper = this.firstNameField.parent(); this.firstNameWrapper = this.firstNameField.parent();
this.middleNameWrapper = this.middleNameField.parent(); this.middleNameWrapper = this.middleNameField.parent();
this.lastNameWrapper = this.lastNameField.parent();
this.selectedAuthor = $('#selectedAuthor');
this.selectedAuthorName = $('#selectedAuthorName');
}, },
// On page load, make changes to the non-Javascript version for the Javascript version. // Initial page setup. Called only at page load.
// These are features that will NOT CHANGE throughout the workflow of the Javascript version. initPage: function() {
adjustForJs: function() {
// Show elements that are hidden by css on load since not used in non-JS version // Show elements hidden by CSS for the non-JavaScript-enabled version.
this.showFormDiv.show(); // NB The non-JavaScript version of this form is currently not functional.
this.removeLinks.show(); this.removeLinks.show();
this.form.hide(); this.bindEventListeners();
this.setUpAutocomplete();
this.initAuthorListOnlyView();
}, },
initForm: function() { bindEventListeners: function() {
this.firstNameWrapper.hide();
this.middleNameWrapper.hide();
this.showFormButton.click(function() { this.showFormButton.click(function() {
addAuthorForm.showFormDiv.hide(); addAuthorForm.initFormView();
addAuthorForm.form.show();
return false; return false;
}); });
this.submit.click(function() { this.submit.click(function() {
addAuthorForm.insertLabel(); // might be insertLabelOrPersonUri addAuthorForm.prepareFieldValuesForSubmit();
}); });
},
this.cancel.click(function() { // This view shows the list of existing authors and hides the form.
addAuthorForm.hideFields(addAuthorForm.form); // There is a button to show the form.
addAuthorForm.showFormDiv.show(); initAuthorListOnlyView: function() {
this.hideForm();
this.showFormButtonWrapper.show();
},
// Initial view of add author form
initFormView: function() {
// Hide the button that shows the form
this.showFormButtonWrapper.hide();
// Hide form fields that shouldn't display on first view.
// Includes clearing their contents.
this.hideFields(this.firstNameWrapper);
this.hideFields(this.middleNameWrapper);
this.hideSelectedAuthor();
this.cancel.unbind('click');
this.cancel.bind('click', function() {
addAuthorForm.initAuthorListOnlyView();
return false; return false;
}); });
this.setUpAutocomplete(); // Reset the last name field. It had been hidden if we selected an author from
// the autocomplete field.
this.lastNameWrapper.show();
// This shouldn't be needed, because calling this.hideFormFields(this.lastNameWrapper)
// from showSelectedAuthor should do it. However, it doesn't work from there,
// or in the cancel action, or if referring to this.lastNameField. None of those work,
// however.
$('#lastName').val('');
// Show the form
this.form.show();
return false;
},
// Action taken after selecting an author from the autocomplete list
showSelectedAuthor: function(ui) {
this.personUriField.val(ui.item.uri);
this.selectedAuthor.show();
// Transfer the name from the autocomplete field to the selected author
// name display, and hide the last name field.
this.selectedAuthorName.html(this.lastNameField.val());
// NB For some reason this doesn't delete the value from the last name
// field when the form is redisplayed. Need to do in initFormView.
this.hideFields(this.lastNameWrapper);
// Cancel restores form to initial state
this.cancel.unbind('click');
this.cancel.bind('click', function() {
addAuthorForm.initFormView();
return false;
});
},
hideSelectedAuthor: function() {
this.selectedAuthor.hide();
this.selectedAuthorName.html('');
this.personUriField.val('');
}, },
setUpAutocomplete: function() { setUpAutocomplete: function() {
@ -84,45 +144,53 @@ var addAuthorForm = {
$.ajax({ $.ajax({
url: url, url: url,
dataType: "json", dataType: 'json',
data: request, data: request,
success: function(data) { success: function(data) {
cache[request.term] = data; cache[request.term] = data;
response(data); response(data);
} }
// on select: fill in person uri
}); });
},
select: function(event, ui) {
addAuthorForm.showSelectedAuthor(ui);
} }
}); });
}, },
insertLabel: function() { prepareFieldValuesForSubmit: function() {
var firstName, var firstName,
middleName, middleName,
lastName, lastName,
name; name;
if (!this.firstNameField.is(':hidden')) { // If selecting an existing person, don't submit name fields
if (this.personUriField.val() != '') {
this.firstNameField.attr('disabled', 'disabled');
this.middleNameField.attr('disabled', 'disabled');
this.lastNameField.attr('disabled', 'disabled');
}
else {
firstName = this.firstNameField.val(); firstName = this.firstNameField.val();
middleName = this.middleNameField.val(); middleName = this.middleNameField.val();
lastName = this.lastNameField.val(); lastName = this.lastNameField.val();
name = lastName; name = lastName;
if (firstName) { if (firstName) {
name += ", " + firstName; name += ', ' + firstName;
} }
if (middleName) { if (middleName) {
name += " " + middleName; name += ' ' + middleName;
} }
this.labelField.val(name); this.labelField.val(name);
} }
else {
}
}, },
// RY To be implemented later.
toggleRemoveLink: function() { toggleRemoveLink: function() {
// when clicking remove: remove the author, and change link text to "undo" // 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" // when clicking undo: add the author back, and change link text to "remove"

View file

@ -26,6 +26,7 @@
<#-- We don't do title here because some pages don't get a title, or it may not be the same as the <title> text. <#-- We don't do title here because some pages don't get a title, or it may not be the same as the <title> text.
<h2>${title}</h2> --> <h2>${title}</h2> -->
${body} ${body}
<#-- <@dumpDataModel /> -->
</div> <!-- content --> </div> <!-- content -->
</div> <!-- contentwrap --> </div> <!-- contentwrap -->