NIHVIVO-647 Continued work on publication form

This commit is contained in:
rjy7 2010-07-09 16:29:00 +00:00
parent 602a62053e
commit de1ee320f5
6 changed files with 97 additions and 25 deletions

View file

@ -24,7 +24,6 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor
<%@ page import="java.util.ArrayList" %> <%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %> <%@ page import="java.util.Arrays" %>
<%@ page import="java.util.Collections" %> <%@ page import="java.util.Collections" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="com.hp.hpl.jena.vocabulary.XSD" %> <%@ page import="com.hp.hpl.jena.vocabulary.XSD" %>
@ -42,6 +41,7 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ 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.controller.freemarker.UrlBuilder.Css" %>
<%@ page import="org.json.JSONObject" %>
<%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %> <%@ page import="org.apache.commons.logging.LogFactory" %>
@ -397,7 +397,7 @@ SPARQL queries for existing values. --%>
<div id="selectedAuthor" class="acSelection"> <div id="selectedAuthor" class="acSelection">
<%-- RY maybe make this a label and input field. See what looks best. --%> <%-- RY maybe make this a label and input field. See what looks best. --%>
<p class="inline"><label>Selected author: </label><span class="acSelectionName" id="selectedAuthorName"></span></p> <p class="inline"><label>Selected author: </label><span class="acSelectionInfo" id="selectedAuthorName"></span></p>
<input type="hidden" id="personUri" name="personUri" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="personUri" name="personUri" value="" /> <!-- Field value populated by JavaScript -->
</div> </div>

View file

@ -19,22 +19,17 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers
<%@ page import="java.util.List" %> <%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %> <%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %> <%@ page import="java.util.Arrays" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="com.hp.hpl.jena.vocabulary.XSD" %> <%@ page import="com.hp.hpl.jena.vocabulary.XSD" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@ 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.PublicationHasAuthorValidator" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PersonHasPublicationValidator" %>
<%@ 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" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.StringUtils" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ 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.controller.freemarker.UrlBuilder.Css" %>
@ -180,6 +175,8 @@ SPARQL queries for existing values. --%>
EditConfiguration.putConfigInSession(editConfig,session); EditConfiguration.putConfigInSession(editConfig,session);
} }
editConfig.addValidator(new PersonHasPublicationValidator());
Model model = (Model) application.getAttribute("jenaOntModel"); Model model = (Model) application.getAttribute("jenaOntModel");
String objectUri = (String) request.getAttribute("objectUri"); String objectUri = (String) request.getAttribute("objectUri");
editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing
@ -203,20 +200,25 @@ SPARQL queries for existing values. --%>
request.setAttribute("customCss", customCss); request.setAttribute("customCss", customCss);
%> %>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<jsp:include page="${preForm}" /> <jsp:include page="${preForm}" />
<h2>Create a new publication entry for <%= subjectName %></h2> <h2>Create a new publication entry for <%= subjectName %></h2>
<form id="addPublicationForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" > <form id="addPublicationForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<p class="inline"><v:input type="select" label="Publication Type" name="pubType" id="typeSelector" /></p> <div id="infoForJs">
<span class="acUrl" id="<c:url value="/autocomplete?stem=true" />"></span>
</div>
<p class="inline"><v:input type="select" label="Publication Type ${requiredHint}" name="pubType" id="typeSelector" /></p>
<div id="fullViewOnly"> <div id="fullViewOnly">
<v:input type="text" id="label" name="title" label="Title" cssClass="acSelector" size="50" /> <v:input type="text" id="label" name="title" label="Title" cssClass="acSelector" size="50" />
<div class="acSelection"> <div class="acSelection">
<%-- RY maybe make this a label and input field. See what looks best. --%> <%-- RY maybe make this a label and input field. See what looks best. --%>
<p class="inline"><label>Selected :</label><span class="acSelectionName"></span></p> <p class="inline"><label></label><span class="acSelectionInfo"></span></p>
<input type="hidden" id="pubUri" name="pubUri" class="acReceiver" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="pubUri" name="pubUri" class="acReceiver" value="" /> <!-- Field value populated by JavaScript -->
</div> </div>
</div> </div>

View file

@ -4,7 +4,7 @@
display: none; display: none;
} }
.acSelectionName { .acSelectionInfo {
background-color: #d9d9d9; background-color: #d9d9d9;
padding: .5em 1em; padding: .5em 1em;
} }

View file

@ -9,6 +9,11 @@
display: none; display: none;
} }
/* Always hidden, JS or no JS */
#infoForJs {
display: none;
}
#content form p.inline label { #content form p.inline label {
display: inline; display: inline;
clear: none; clear: none;

View file

@ -226,7 +226,7 @@ var addAuthorForm = {
this.hideFields(this.firstNameWrapper); this.hideFields(this.firstNameWrapper);
this.hideFields(this.middleNameWrapper); this.hideFields(this.middleNameWrapper);
// Cancel restores form to initial state // Cancel restores initial form view
this.cancel.unbind('click'); this.cancel.unbind('click');
this.cancel.bind('click', function() { this.cancel.bind('click', function() {
addAuthorForm.initFormView(); addAuthorForm.initFormView();

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
var customFormWATS = { var customForm = {
/* *** Initial page setup *** */ /* *** Initial page setup *** */
@ -31,8 +31,7 @@ var customFormWATS = {
// These are classed rather than id'd in case we want more than one autocomplete on a form. // These are classed rather than id'd in case we want more than one autocomplete on a form.
this.acSelector = this.form.find('.acSelector'); this.acSelector = this.form.find('.acSelector');
this.acSelection = this.form.find('.acSelection'); this.acSelection = this.form.find('.acSelection');
}, },
// Set up the form on page load // Set up the form on page load
@ -40,15 +39,16 @@ var customFormWATS = {
this.initFormTypeView(); this.initFormTypeView();
this.bindEventListeners(); this.bindEventListeners();
this.initAutocomplete(); //this.initAutocomplete();
}, },
initFormTypeView: function() { initFormTypeView: function() {
this.hideFields(this.fullViewOnly);
this.button.hide(); this.button.hide();
this.or.hide();
this.requiredLegend.hide(); this.requiredLegend.hide();
this.or.hide();
this.cancel.unbind('click'); this.cancel.unbind('click');
@ -62,8 +62,10 @@ var customFormWATS = {
this.button.show(); this.button.show();
this.button.val('Create Publication'); this.button.val('Create Publication');
this.cancel.unbind('click');
this.cancel.click(function() { this.cancel.click(function() {
customFormWATS.initFormTypeView(); customForm.initFormTypeView();
return false;
}); });
}, },
@ -82,24 +84,87 @@ var customFormWATS = {
labelField = $('#label'); labelField = $('#label');
labelFieldLabel = $('label[for=' + labelField.attr('id') + ']'); labelFieldLabel = $('label[for=' + labelField.attr('id') + ']');
labelText = labelFieldLabel.html(); labelText = labelFieldLabel.html();
selectedText = $(this).find(':selected').html(); labelFieldLabel.html(customForm.getSelectedTypeName() + ' ' + labelText);
labelFieldLabel.html(selectedText + ' ' + labelText);
customFormWATS.initFormFullView(); customForm.initFormFullView();
// set ac type // set ac type
} }
// do we need else case? i.e. if user has set back to "select one", we should undo
// above settings?
}); });
}, },
initAutocomplete: function() { initAutocomplete: function() {
// Make cache a property of this so we can access it after removing
// an author.
this.acCache = {};
this.baseAcUrl = $('.acUrl').attr('id');
// ac selection: disable typeSelector and acSelector this.acSelector.autocomplete({
minLength: 3,
source: function(request, response) {
if (request.term in customForm.acCache) {
// console.log('found term in cache');
response(customForm.acCache[request.term]);
return;
}
// console.log('not getting term from cache');
// If the url query params are too long, we could do a post
// here instead of a get. Add the exclude uris to the data
// rather than to the url.
$.ajax({
url: customForm.acUrl,
dataType: 'json',
data: request,
complete: function(xhr) {
// Not sure why, but we need an explicit json parse here. jQuery
// should parse the response text and return an json object.
var results = jQuery.parseJSON(xhr.responseText);
customForm.acCache[request.term] = results;
response(results);
}
});
},
select: function(event, ui) {
customForm.showAutocompleteSelection(ui);
}
});
},
showAutocompleteSelection: function(ui) {
this.acSelector.hide();
this.acSelector.attr('disabled', 'disabled');
this.acSelection.find('label').html('Selected ' + this.getSelectedTypeName() + ':');
this.acSelection.show();
this.acReceiver.val(ui.item.uri);
this.acSelectionInfo.html(ui.item.label);
this.button.val('Add Publication');
this.cancel.unbind('click');
this.cancel.click(function() {
// TODO Check out cancel action for authors form. Need to undo/empty some of the stuff above.
// do we do it in the initfullview method, or here?
customForm.initFormFullView();
return false;
});
},
getSelectedTypeName: function() {
return this.typeSelector.find(':selected').html();
} }
}; };
$(document).ready(function() { $(document).ready(function() {
customFormWATS.onLoad(); customForm.onLoad();
}); });