NIHVIVO-646 After removing an author, reset autocomplete url to modify excluded uris so that uri of author just removed is no longer excluded.

This commit is contained in:
rjy7 2010-07-04 01:12:59 +00:00
parent a2c2e41447
commit dccd622b5b

View file

@ -139,6 +139,9 @@ var addAuthorForm = {
if ($('.authorship').length == 1) { if ($('.authorship').length == 1) {
addAuthorForm.disableAuthorDD(); addAuthorForm.disableAuthorDD();
} }
// Reset the excluded uris in the autocomplete url so that the
// author just removed is no longer excluded.
$('#lastName').autocomplete('option', 'source', addAuthorForm.getAcUrl());
}); });
// $(this).hide(); // $(this).hide();
@ -434,22 +437,17 @@ var addAuthorForm = {
initAutocomplete: function() { initAutocomplete: function() {
var cache = {}; //var cache = {};
var url = $('.acUrl').attr('id'); // RY change to this.cache = {}
var existingAuthorUris = addAuthorForm.getExistingAuthorUris(); // then we'll have access to it when removing an author
jQuery.each(existingAuthorUris, function(index, element) {
url += '&excludeUri=' + element;
});
$('#lastName').autocomplete({ $('#lastName').autocomplete({
minLength: 2, minLength: 2,
source: url, source: addAuthorForm.getAcUrl(),
// RY For now, not using cache because there are complex interactions between filtering and caching. // RY For now, not using cache because there are complex interactions between filtering and caching.
// We want to filter out existingAuthors from autocomplete results, and this seems easiest to do // We want to filter out existingAuthors from autocomplete results, and this seems easiest to do
// server-side. But if an author gets removed, we need to put them back in the results. If results // server-side. But if an author gets removed, we need to put them back in the results. If results
// are cached, the cache needs to be cleared on a remove. Not sure if we have access to it there. // are cached, the cache needs to be cleared on a remove.
// Lots of complexity involved, so for now let's try without the cache.
// source: function(request, response) { // source: function(request, response) {
// if (request.term in cache) { // if (request.term in cache) {
// //console.log("found term in cache"); // //console.log("found term in cache");
@ -477,14 +475,15 @@ var addAuthorForm = {
}, },
getExistingAuthorUris: function() { getAcUrl: function() {
// NB This only gets the id of the first one var url = $('.acUrl').attr('id'),
// return $('#authorships .authorLink').attr('id'); existingAuthors = $('#authorships .authorLink');
var existingAuthors = $('#authorships .authorLink');
return existingAuthors.map(function() { existingAuthors.each(function() {
return $(this).attr('id'); url += '&excludeUri=' + $(this).attr('id');
}); });
return url;
}, },
prepareSubmit: function() { prepareSubmit: function() {