NIHVIVO-725 Autocomplete filters out existing publications for this author
This commit is contained in:
parent
faaf087406
commit
6a43e5399e
2 changed files with 58 additions and 26 deletions
|
@ -109,7 +109,7 @@ SPARQL queries for existing values. --%>
|
||||||
|
|
||||||
<%-- Must be all one line for JavaScript. --%>
|
<%-- Must be all one line for JavaScript. --%>
|
||||||
<c:set var="sparqlForAcFilter">
|
<c:set var="sparqlForAcFilter">
|
||||||
PREFIX core: <${vivoCore}> SELECT ?pubUri WHERE {<${subjectUri}> core:authorInAuthorship ?authorshipUri .?authorshipUri core:linkedInformationResource ?pubUri .}
|
PREFIX core: <${vivoCore}> SELECT ?individual WHERE {<${subjectUri}> core:authorInAuthorship ?authorshipUri .?authorshipUri core:linkedInformationResource ?individual .}
|
||||||
</c:set>
|
</c:set>
|
||||||
|
|
||||||
<c:set var="publicationsClassGroupUri" value="${vivoOnt}#vitroClassGrouppublications" />
|
<c:set var="publicationsClassGroupUri" value="${vivoOnt}#vitroClassGrouppublications" />
|
||||||
|
@ -214,15 +214,9 @@ PREFIX core: <${vivoCore}> SELECT ?pubUri WHERE {<${subjectUri}> core:authorInAu
|
||||||
|
|
||||||
<c:url var="acUrl" value="/autocomplete?stem=true" />
|
<c:url var="acUrl" value="/autocomplete?stem=true" />
|
||||||
<c:url var="sparqlQueryUrl" value="/admin/sparqlquery" />
|
<c:url var="sparqlQueryUrl" value="/admin/sparqlquery" />
|
||||||
|
|
||||||
<jsp:include page="${preForm}" />
|
<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>
|
<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"/>" >
|
||||||
|
@ -244,4 +238,11 @@ var customFormData = {
|
||||||
<p id="requiredLegend" class="requiredHint">* required fields</p>
|
<p id="requiredLegend" class="requiredHint">* required fields</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var customFormData = {
|
||||||
|
sparqlForAcFilter: '${sparqlForAcFilter}',
|
||||||
|
sparqlQueryUrl: '${sparqlQueryUrl}',
|
||||||
|
acUrl: '${acUrl}'
|
||||||
|
};
|
||||||
|
</script>
|
||||||
<jsp:include page="${postForm}"/>
|
<jsp:include page="${postForm}"/>
|
|
@ -25,8 +25,11 @@ var customForm = {
|
||||||
this.requiredLegend = $('#requiredLegend');
|
this.requiredLegend = $('#requiredLegend');
|
||||||
this.typeSelector = this.form.find('#typeSelector');
|
this.typeSelector = this.form.find('#typeSelector');
|
||||||
|
|
||||||
//if there isn't a two stage setup, don't do two stage behavior
|
if (!this.typeSelector) {
|
||||||
this.twoStageForm = ( this.typeSelector.length > 1 );
|
this.formSteps = 1;
|
||||||
|
} else {
|
||||||
|
this.formSteps = 2;
|
||||||
|
}
|
||||||
|
|
||||||
// This is the label element for the field with name 'label'
|
// This is the label element for the field with name 'label'
|
||||||
this.labelFieldLabel = $('label[for=' + $('#label').attr('id') + ']');
|
this.labelFieldLabel = $('label[for=' + $('#label').attr('id') + ']');
|
||||||
|
@ -41,6 +44,8 @@ var customForm = {
|
||||||
this.acSelector = this.form.find('.acSelector');
|
this.acSelector = this.form.find('.acSelector');
|
||||||
this.acSelection = this.form.find('.acSelection');
|
this.acSelection = this.form.find('.acSelection');
|
||||||
|
|
||||||
|
$.extend(this, customFormData);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set up the form on page load
|
// Set up the form on page load
|
||||||
|
@ -50,7 +55,7 @@ var customForm = {
|
||||||
|
|
||||||
this.initAutocomplete();
|
this.initAutocomplete();
|
||||||
|
|
||||||
if (this.findValidationErrors() || ! this.twoStageForm) {
|
if (this.findValidationErrors() || this.formSteps == 1) {
|
||||||
this.initFormFullView();
|
this.initFormFullView();
|
||||||
} else {
|
} else {
|
||||||
this.initFormTypeView();
|
this.initFormTypeView();
|
||||||
|
@ -65,8 +70,8 @@ var customForm = {
|
||||||
this.requiredLegend.hide();
|
this.requiredLegend.hide();
|
||||||
this.or.hide();
|
this.or.hide();
|
||||||
|
|
||||||
if( twoStageForm ){
|
if( this.formSteps > 1 ){
|
||||||
this.cancel.unbind('click');
|
this.cancel.unbind('click');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -78,7 +83,7 @@ var customForm = {
|
||||||
this.button.show();
|
this.button.show();
|
||||||
this.button.val('Create Publication');
|
this.button.val('Create Publication');
|
||||||
|
|
||||||
if( twoStageForm ){
|
if( this.formSteps > 1 ){
|
||||||
this.cancel.unbind('click');
|
this.cancel.unbind('click');
|
||||||
this.cancel.click(function() {
|
this.cancel.click(function() {
|
||||||
customForm.clearFormData(); // clear any input and validation errors
|
customForm.clearFormData(); // clear any input and validation errors
|
||||||
|
@ -109,8 +114,7 @@ var customForm = {
|
||||||
|
|
||||||
initAutocomplete: function() {
|
initAutocomplete: function() {
|
||||||
|
|
||||||
var acFilter = this.getAcFilter();
|
this.getAcFilter();
|
||||||
|
|
||||||
this.acCache = {};
|
this.acCache = {};
|
||||||
this.baseAcUrl = customFormData.acUrl;
|
this.baseAcUrl = customFormData.acUrl;
|
||||||
|
|
||||||
|
@ -131,11 +135,10 @@ var customForm = {
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
// Not sure why, but we need an explicit json parse here. jQuery
|
// Not sure why, but we need an explicit json parse here. jQuery
|
||||||
// should parse the response text and return a json object.
|
// should parse the response text and return a json object.
|
||||||
var results = jQuery.parseJSON(xhr.responseText);
|
var results = $.parseJSON(xhr.responseText),
|
||||||
|
filteredResults = customForm.filterAcResults(results);
|
||||||
customForm.acCache[request.term] = results;
|
customForm.acCache[request.term] = filteredResults;
|
||||||
|
response(filteredResults);
|
||||||
response(results);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -150,7 +153,8 @@ var customForm = {
|
||||||
|
|
||||||
getAcFilter: function() {
|
getAcFilter: function() {
|
||||||
// RY This gets put on the page for now. May want to put into a js file instead.
|
// RY This gets put on the page for now. May want to put into a js file instead.
|
||||||
var url = $('.sparqlQueryUrl').attr('id');
|
var url = $('.sparqlQueryUrl').attr('id'),
|
||||||
|
filter;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: customFormData.sparqlQueryUrl,
|
url: customFormData.sparqlQueryUrl,
|
||||||
|
@ -159,9 +163,36 @@ var customForm = {
|
||||||
query: customFormData.sparqlForAcFilter
|
query: customFormData.sparqlForAcFilter
|
||||||
},
|
},
|
||||||
success: function(data, status, xhr) {
|
success: function(data, status, xhr) {
|
||||||
console.log(data);
|
// Not sure why, but we need an explicit json parse here. jQuery
|
||||||
|
// should parse the response text and return a json object.
|
||||||
|
customForm.setAcFilter($.parseJSON(data));
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setAcFilter: function(data) {
|
||||||
|
var filter = [];
|
||||||
|
$.each(data.results.bindings, function() {
|
||||||
|
filter.push(this.individual.value);
|
||||||
|
});
|
||||||
|
this.acFilter = filter;
|
||||||
|
},
|
||||||
|
|
||||||
|
filterAcResults: function(results) {
|
||||||
|
var filteredResults = [];
|
||||||
|
if (!this.acFilter.length) {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
$.each(results, function() {
|
||||||
|
if (! $.inArray(this.uri, this.acFilter)) {
|
||||||
|
filteredResults.push(this);
|
||||||
|
}
|
||||||
|
// Debugging
|
||||||
|
// else {
|
||||||
|
// console.log("filtering out " + this.label);
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
return filteredResults;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Reset some autocomplete values after type is changed
|
// Reset some autocomplete values after type is changed
|
||||||
|
@ -188,7 +219,7 @@ var customForm = {
|
||||||
|
|
||||||
this.button.val('Add Publication');
|
this.button.val('Add Publication');
|
||||||
|
|
||||||
if( this.twoStageForm){
|
if( this.formSteps > 1){
|
||||||
this.cancel.unbind('click');
|
this.cancel.unbind('click');
|
||||||
this.cancel.click(function() {
|
this.cancel.click(function() {
|
||||||
// TODO Check out cancel action for authors form. Need to undo/empty some of the stuff above.
|
// TODO Check out cancel action for authors form. Need to undo/empty some of the stuff above.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue