NIHVIVO-646 Work on autocomplete in add authors to publication form

This commit is contained in:
rjy7 2010-06-21 16:07:22 +00:00
parent 03a2f1cfe9
commit 65af54c74e
2 changed files with 49 additions and 13 deletions

View file

@ -307,7 +307,7 @@ SPARQL queries for existing values. --%>
<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" 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" />" />
<!-- Field values populated by JavaScript --> <!-- Field values populated by JavaScript -->
<input type="hidden" id="label" name="label" value="" /> <input type="hidden" id="label" name="label" value="" />
<input type="hidden" id="personUri" name="personUri" value="" /> <input type="hidden" id="personUri" name="personUri" value="" />

View file

@ -47,8 +47,8 @@ var addAuthorForm = {
initForm: function() { initForm: function() {
//this.firstNameWrapper.hide(); this.firstNameWrapper.hide();
//this.middleNameWrapper.hide(); this.middleNameWrapper.hide();
this.showFormButton.click(function() { this.showFormButton.click(function() {
addAuthorForm.showFormDiv.hide(); addAuthorForm.showFormDiv.hide();
@ -66,18 +66,36 @@ var addAuthorForm = {
return false; return false;
}); });
// this.setUpAutocomplete(); this.setUpAutocomplete();
}, },
// setUpAutocomplete: function() { setUpAutocomplete: function() {
//
// var names = ["Adams", "Bell", "Smith", "Smile", "Smelt", "Younes", "Young"]; var cache = {};
// $('#lastName').autocomplete({ var url = $('#acUrl').val();
// source: names $('#lastName').autocomplete({
// }); minLength: 2,
// source: function(request, response) {
// }, if (request.term in cache) {
response(cache[request.term]);
return;
}
$.ajax({
url: url,
dataType: "json",
data: request,
success: function(data) {
cache[request.term] = data;
response(data);
}
// on select: fill in person uri
});
}
});
},
insertLabel: function() { insertLabel: function() {
var firstName, var firstName,
@ -114,4 +132,22 @@ var addAuthorForm = {
$(document).ready(function() { $(document).ready(function() {
addAuthorForm.onLoad(); addAuthorForm.onLoad();
}); });
/* "value" : uri
* label: gets displayed in form field = rdfs:label
*
* on select: put the uri into the person uri form field
*/
/*[ { "id": "Somateria mollissima", "label": "Common Eider", "value": "Common Eider" },
{ "id": "Crex crex", "label": "Corncrake", "value": "Corncrake" },
{ "id": "Grus grus", "label": "Common Crane", "value": "Common Crane" },
{ "id": "Charadrius hiaticula", "label": "Common Ringed Plover", "value": "Common Ringed Plover" },
{ "id": "Gallinago gallinago", "label": "Common Snipe", "value": "Common Snipe" },
{ "id": "Tringa totanus", "label": "Common Redshank", "value": "Common Redshank" },
{ "id": "Sterna hirundo", "label": "Common Tern", "value": "Common Tern" },
{ "id": "Alcedo atthis", "label": "Common Kingfisher", "value": "Common Kingfisher" },
{ "id": "Corvus corax", "label": "Common Raven", "value": "Common Raven" },
{ "id": "Emberiza calandra", "label": "Corn Bunting", "value": "Corn Bunting" },
{ "id": "Phalacrocorax carbo", "label": "Great Cormorant", "value": "Great Cormorant" },
{ "id": "Tadorna tadorna", "label": "Common Shelduck", "value": "Common Shelduck" } ]*/