From 65af54c74e1b9539b921f1abeec6667bac789b49 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 21 Jun 2010 16:07:22 +0000 Subject: [PATCH] NIHVIVO-646 Work on autocomplete in add authors to publication form --- .../forms/addAuthorsToInformationResource.jsp | 2 +- .../js/addAuthorsToInformationResource.js | 60 +++++++++++++++---- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp index 79c6bb01..72690136 100644 --- a/productMods/edit/forms/addAuthorsToInformationResource.jsp +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -307,7 +307,7 @@ SPARQL queries for existing values. --%>

${initialHint}

- + " /> diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index 95d2ca4b..e04dc42b 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -47,8 +47,8 @@ var addAuthorForm = { initForm: function() { - //this.firstNameWrapper.hide(); - //this.middleNameWrapper.hide(); + this.firstNameWrapper.hide(); + this.middleNameWrapper.hide(); this.showFormButton.click(function() { addAuthorForm.showFormDiv.hide(); @@ -66,18 +66,36 @@ var addAuthorForm = { return false; }); -// this.setUpAutocomplete(); + this.setUpAutocomplete(); }, -// setUpAutocomplete: function() { -// -// var names = ["Adams", "Bell", "Smith", "Smile", "Smelt", "Younes", "Young"]; -// $('#lastName').autocomplete({ -// source: names -// }); -// -// }, + setUpAutocomplete: function() { + + var cache = {}; + var url = $('#acUrl').val(); + $('#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() { var firstName, @@ -114,4 +132,22 @@ var addAuthorForm = { $(document).ready(function() { addAuthorForm.onLoad(); -}); \ No newline at end of file +}); + +/* "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" } ]*/ \ No newline at end of file