NIHVIVO-725 Initial work on autocomplete filter for existing publications for the author

This commit is contained in:
rjy7 2010-07-11 17:31:41 +00:00
parent 67a3e7a86c
commit d1c8d701c2
3 changed files with 53 additions and 17 deletions

View file

@ -47,14 +47,24 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers
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();
vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri));
String vivoOnt = "http://vivoweb.org/ontology";
String vivoCore = vivoOnt + "/core#";
vreq.setAttribute("vivoOnt", vivoOnt);
vreq.setAttribute("vivoCore", vivoCore);
vreq.setAttribute("vivoCoreJson", MiscWebUtils.escape(vivoCore));
vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString()));
String intDatatypeUri = XSD.xint.toString();
vreq.setAttribute("intDatatypeUri", intDatatypeUri);
vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri));
%>
<c:set var="vivoOnt" value="http://vivoweb.org/ontology" />
<c:set var="vivoCore" value="${vivoOnt}/core#" />
<c:set var="rdfs" value="<%= VitroVocabulary.RDFS %>" />
<c:set var="label" value="${rdfs}label" />
<c:set var="infoResourceClassUri" value="${vivoCore}InformationResource" />
@ -97,7 +107,11 @@ SPARQL queries for existing values. --%>
?newPub core:informationResourceInAuthorship ?authorshipUri .
</v:jsonset>
<%-- <v:jsonset var="infoResourceClassUriJson">${infoResourceClassUri}</v:jsonset> --%>
<%-- Must be all one line for JavaScript. --%>
<c:set var="sparqlForAcFilter">
PREFIX core: <${vivoCore}> SELECT ?pubUri WHERE {<${subjectUri}> core:authorInAuthorship ?authorshipUri .?authorshipUri core:linkedInformationResource ?pubUri .}
</c:set>
<c:set var="publicationsClassGroupUri" value="${vivoOnt}#vitroClassGrouppublications" />
<v:jsonset var="publicationsClassGroupUriJson">${publicationsClassGroupUri}</v:jsonset>
@ -181,10 +195,6 @@ SPARQL queries for existing values. --%>
String objectUri = (String) request.getAttribute("objectUri");
editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing
String subjectUri = vreq.getParameter("subjectUri");
String predicateUri = vreq.getParameter("predicateUri");
String subjectName = ((Individual) request.getAttribute("subject")).getName();
List<String> customJs = new ArrayList<String>(Arrays.asList(JavaScript.JQUERY_UI.path(),
JavaScript.UTILS.path(),
JavaScript.CUSTOM_FORM_UTILS.path(),
@ -202,15 +212,21 @@ SPARQL queries for existing values. --%>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<c:url var="acUrl" value="/autocomplete?stem=true" />
<c:url var="sparqlQueryUrl" value="/admin/sparqlquery" />
<jsp:include page="${preForm}" />
<script>
var customFormData = {
sparqlForAcFilter: '${sparqlForAcFilter}',
sparqlQueryUrl: '${sparqlQueryUrl}',
acUrl: '${acUrl}'
}
//var sparqlForAcFilter = "${sparqlForAcFilter}";
</script>
<h2>Create a new publication entry for <%= subjectName %></h2>
<form id="addPublicationForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<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">

View file

@ -178,7 +178,7 @@ var addAuthorForm = {
url: addAuthorForm.acUrl,
dataType: 'json',
data: request,
complete: function(xhr) {
complete: function(xhr, status) {
// Not sure why, but we need an explicit json parse here. jQuery
// should parse the response text and return a json object.
var results = jQuery.parseJSON(xhr.responseText);

View file

@ -103,8 +103,10 @@ var customForm = {
initAutocomplete: function() {
var acFilter = this.getAcFilter();
this.acCache = {};
this.baseAcUrl = $('.acUrl').attr('id');
this.baseAcUrl = customFormData.acUrl;
this.acSelector.autocomplete({
minLength: 3,
@ -120,11 +122,13 @@ var customForm = {
url: customForm.acUrl,
dataType: 'json',
data: request,
complete: function(xhr) {
complete: function(xhr, status) {
// Not sure why, but we need an explicit json parse here. jQuery
// should parse the response text and return a json object.
var results = jQuery.parseJSON(xhr.responseText);
customForm.acCache[request.term] = results;
response(results);
}
@ -138,6 +142,22 @@ var customForm = {
},
getAcFilter: function() {
// RY This gets put on the page for now. May want to put into a js file instead.
var url = $('.sparqlQueryUrl').attr('id');
$.ajax({
url: customFormData.sparqlQueryUrl,
data: {
resultFormat: 'RS_JSON',
query: customFormData.sparqlForAcFilter
},
success: function(data, status, xhr) {
console.log(data);
}
})
},
// Reset some autocomplete values after type is changed
resetAutocomplete: function(typeVal) {
// Append the type parameter to the base autocomplete url