NIHVIVO-744 After removing an author, clear only matching autocomplete cache keys rather than entire cache.
NIHVIVO-741 Complete refactoring of authorship removal using javascript data rather than DOM elements and attributes.
This commit is contained in:
parent
a173e5a711
commit
d6e70ad48d
2 changed files with 23 additions and 11 deletions
|
@ -341,7 +341,7 @@ SPARQL queries for existing values. --%>
|
||||||
|
|
||||||
request.setAttribute("author", authorship.getRelatedIndividual(vivoCore + "linkedAuthor"));
|
request.setAttribute("author", authorship.getRelatedIndividual(vivoCore + "linkedAuthor"));
|
||||||
%>
|
%>
|
||||||
<li class="authorship" id="${authorshipUri}">
|
<li class="authorship">
|
||||||
<%-- span.author will be used in the next phase, when we display a message that the author has been
|
<%-- span.author will be used in the next phase, when we display a message that the author has been
|
||||||
removed. That text will replace the a.authorName, which will be removed. --%>
|
removed. That text will replace the a.authorName, which will be removed. --%>
|
||||||
<span class="author">
|
<span class="author">
|
||||||
|
|
|
@ -189,11 +189,11 @@ var addAuthorForm = {
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
source: function(request, response) {
|
source: function(request, response) {
|
||||||
if (request.term in addAuthorForm.acCache) {
|
if (request.term in addAuthorForm.acCache) {
|
||||||
// console.log('found term in cache');
|
console.log('found term in cache');
|
||||||
response(addAuthorForm.acCache[request.term]);
|
response(addAuthorForm.acCache[request.term]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log('not getting term from cache');
|
console.log('not getting term from cache');
|
||||||
|
|
||||||
// If the url query params are too long, we could do a post
|
// If the url query params are too long, we could do a post
|
||||||
// here instead of a get. Add the exclude uris to the data
|
// here instead of a get. Add the exclude uris to the data
|
||||||
|
@ -257,6 +257,18 @@ var addAuthorForm = {
|
||||||
return filteredResults;
|
return filteredResults;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// After removing an authorship, selectively clear matching autocomplete
|
||||||
|
// cache entries, else the associated author will not be included in
|
||||||
|
// subsequent autocomplete suggestions.
|
||||||
|
clearAcCacheEntries: function(name) {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
$.each(this.acCache, function(key, value) {
|
||||||
|
if (name.indexOf(key) == 0) {
|
||||||
|
delete addAuthorForm.acCache[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
// Action taken after selecting an author from the autocomplete list
|
// Action taken after selecting an author from the autocomplete list
|
||||||
showSelectedAuthor: function(ui) {
|
showSelectedAuthor: function(ui) {
|
||||||
|
|
||||||
|
@ -581,7 +593,8 @@ var addAuthorForm = {
|
||||||
url: $(link).attr('href'),
|
url: $(link).attr('href'),
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
deletion: $(link).parents('.authorship').attr('id')
|
//deletion: $(link).parents('.authorship').attr('id')
|
||||||
|
deletion: $(link).parents('.authorship').data('authorshipUri')
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
context: link, // context for callback
|
context: link, // context for callback
|
||||||
|
@ -592,15 +605,14 @@ var addAuthorForm = {
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
|
|
||||||
authorship = $(this).parents('.authorship');
|
authorship = $(this).parents('.authorship');
|
||||||
authorUri = $(authorship).data('authorUri');
|
|
||||||
|
|
||||||
// In future, do this selectively by only clearing terms that match the
|
// Clear autocomplete cache entries matching this author's name, else
|
||||||
// deleted author's name
|
// autocomplete will be retrieved from the cache, which excludes the removed author.
|
||||||
addAuthorForm.acCache = {};
|
addAuthorForm.clearAcCacheEntries(authorship.data('authorName'));
|
||||||
|
|
||||||
// Remove this author from the acFilter so it can be returned in autocomplete
|
// Remove this author from the acFilter so it is included in autocomplete
|
||||||
// results again.
|
// results again.
|
||||||
addAuthorForm.removeAuthorFromAcFilter(authorUri);
|
addAuthorForm.removeAuthorFromAcFilter(authorship.data('authorUri'));
|
||||||
|
|
||||||
authorship.fadeOut(400, function() {
|
authorship.fadeOut(400, function() {
|
||||||
var numAuthors;
|
var numAuthors;
|
||||||
|
@ -611,7 +623,7 @@ var addAuthorForm = {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
|
|
||||||
// Actions that depend on the author having been removed from the DOM:
|
// Actions that depend on the author having been removed from the DOM:
|
||||||
numAuthors = $('.authorship').length;
|
numAuthors = $('.authorship').length; // retrieve the length after removing authorship from the DOM
|
||||||
if (numAuthors > 0) {
|
if (numAuthors > 0) {
|
||||||
// Reorder to remove any gaps
|
// Reorder to remove any gaps
|
||||||
addAuthorForm.reorderAuthors();
|
addAuthorForm.reorderAuthors();
|
||||||
|
|
Loading…
Add table
Reference in a new issue