From 37a85a5e97e3299b45cbcaa083f672eb71675dd6 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Tue, 29 Jun 2010 16:15:51 +0000 Subject: [PATCH] NIHVIVO-646 Autocomplete, remove author functionality --- .../forms/addAuthorsToInformationResource.jsp | 12 +++-- .../css/addAuthorsToInformationResource.css | 10 +++- .../js/addAuthorsToInformationResource.js | 53 ++++++++++++++++--- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp index ccfe4ea3..957fe675 100644 --- a/productMods/edit/forms/addAuthorsToInformationResource.jsp +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -291,13 +291,17 @@ SPARQL queries for existing values. --%> // Doesn't seem to need urlencoding to add as id attribute value //request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8")); request.setAttribute("authorUri", author.getURI()); + request.setAttribute("authorshipUri", authorship.getURI()); %> - -
  • - ${author.name} - Remove + + + +
  • + ${author.name} + Remove + Undo
  • <% diff --git a/productMods/edit/forms/css/addAuthorsToInformationResource.css b/productMods/edit/forms/css/addAuthorsToInformationResource.css index 5adcb2b5..b4376268 100644 --- a/productMods/edit/forms/css/addAuthorsToInformationResource.css +++ b/productMods/edit/forms/css/addAuthorsToInformationResource.css @@ -9,6 +9,7 @@ margin-bottom: .75em; } + #authors a.existingAuthor { display: inline-block; width: 15em; @@ -22,6 +23,7 @@ /* Hide elements not used in non-JS version of form */ #showAddForm, a.remove, +a.undo, #selectedAuthor { display: none; } @@ -39,7 +41,8 @@ form h3 { } form a:link.cancel, form a:visited.cancel, -#authors a:link.remove, #authors a:visited.remove, +#authors a:link.remove, #authors a:visited.remove, +#authors a:link.undo, #authors a:visited.undo, #showAddForm a:link.cancel, #showAddForm a:visited.cancel { color: #f70; border-color: #f70; @@ -47,11 +50,16 @@ form a:link.cancel, form a:visited.cancel, form a:hover.cancel, #authors a:hover.remove, +#authors a:hover.undo, #showAddForm a:hover.cancel { color: #fff; background: #f70; } +#authors a.undo { + margin-left: 1em; +} + #content form p.inline { clear: left; margin-bottom: 0; diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index a88b8ab2..bf95429b 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -21,7 +21,8 @@ var addAuthorForm = { this.form = $('#addAuthorForm'); this.showFormButtonWrapper = $('#showAddForm'); this.showFormButton = $('#showAddFormButton'); - this.removeLinks = $('a.remove'); + this.removeAuthorshipLinks = $('a.remove'); + this.undoLinks = $('a.undo'); this.submit = this.form.find(':submit'); this.cancel = this.form.find('.cancel'); this.labelField = $('#label'); @@ -42,7 +43,9 @@ var addAuthorForm = { // Show elements hidden by CSS for the non-JavaScript-enabled version. // NB The non-JavaScript version of this form is currently not functional. - this.removeLinks.show(); + this.removeAuthorshipLinks.show(); + + this.undoLinks.hide(); this.bindEventListeners(); @@ -82,7 +85,8 @@ var addAuthorForm = { addAuthorForm.hideFieldsForNewPerson(); }); - // Prevent form submission when hitting enter in last name field + // When hitting enter in last name field, if not an autocomplete + // selection, show first and middle name fields. this.lastNameField.keydown(function(event) { if (event.keyCode === 13) { console.log('in keydown') @@ -90,15 +94,46 @@ var addAuthorForm = { return false; } }); + + this.removeAuthorshipLinks.click(function() { + $.ajax({ + url: $(this).attr('href'), + type: 'POST', + data: { + deletion: $(this).attr('id') + }, + dataType: 'json', + context: $(this), // context for callback + complete: function(request, status) { + var author = $(this).siblings('span.authorName'); + var authorLink = author.children('a.existingAuthor'); + var authorName = authorLink.html(); + if (status === 'success') { + $(this).hide(); + $(this).siblings('.undo').show(); + author.html(authorName + ' has been removed'); + author.css('width', 'auto'); + author.effect("highlight", {}, 3000); + } else { + alert('Error processing request'); + } + } + }); + return false; + }); + + this.undoLinks.click(function() { + $.ajax({ + url: $(this).attr('href') + }); + return false; + }); + }, onLastNameChange: function() { this.showFieldsForNewPerson(); this.firstNameField.focus(); - // This is persisting and showing old results in some cases unless we - // explicitly wipe it out. - $('ul.ui-autocomplete li').remove(); - $('ul.ui-autocomplete').hide(); }, showFieldsForNewPerson: function() { @@ -193,6 +228,8 @@ var addAuthorForm = { addAuthorForm.initFormView(); return false; }); + + return false; }, hideSelectedAuthor: function() { @@ -248,7 +285,7 @@ var addAuthorForm = { getExistingAuthorUris: function() { - var existingAuthors = $('#authors .existingAuthor'); + var existingAuthors = $('#authors li'); return existingAuthors.map(function() { return $(this).attr('id'); });