From ede7b517793615180a39db8a5cb81d9870530fd3 Mon Sep 17 00:00:00 2001 From: ryounes Date: Tue, 12 Jul 2011 19:01:16 +0000 Subject: [PATCH] NIHVIVO-707 Tweaks to addAuthors and manageWebpages Javascript --- .../js/addAuthorsToInformationResource.js | 24 ++++++++++++------- .../forms/js/manageWebpagesForIndividual.js | 24 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index 1f063e96..64b12471 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -528,10 +528,17 @@ var addAuthorForm = { removeAuthorship: function(link) { // RY Upgrade this to a modal window - var message = 'Are you sure you want to remove this author?'; + var removeLast = false, + message = 'Are you sure you want to remove this author?'; + if (!confirm(message)) { return false; } + + if ($(link)[0] === $('.remove:last')[0]) { + removeLast = true; + } + $.ajax({ url: $(link).attr('href'), type: 'POST', @@ -566,15 +573,16 @@ var addAuthorForm = { // Actions that depend on the author having been removed from the DOM: numAuthors = $('.authorship').length; // retrieve the length after removing authorship from the DOM - if (numAuthors > 0) { - // Reorder to remove any gaps + + // If removed item not last, reorder to remove any gaps + if (numAuthors > 0 && ! removeLast) { addAuthorForm.reorderAuthors(); - - // If fewer than two authors remaining, disable drag-drop - if (numAuthors < 2) { - addAuthorForm.disableAuthorDD(); - } } + + // If fewer than two authors remaining, disable drag-drop + if (numAuthors < 2) { + addAuthorForm.disableAuthorDD(); + } }); // $(this).hide(); diff --git a/productMods/edit/forms/js/manageWebpagesForIndividual.js b/productMods/edit/forms/js/manageWebpagesForIndividual.js index 07e251c4..6c9479ab 100644 --- a/productMods/edit/forms/js/manageWebpagesForIndividual.js +++ b/productMods/edit/forms/js/manageWebpagesForIndividual.js @@ -151,10 +151,17 @@ var manageWebpages = { removeWebpage: function(link) { // RY Upgrade this to a modal window - var message = 'Are you sure you want to remove this web page?'; + var removeLast = false, + message = 'Are you sure you want to remove this web page?'; + if (!confirm(message)) { return false; } + + if ($(link)[0] === $('.remove:last')[0]) { + removeLast = true; + } + $.ajax({ url: $(link).attr('href'), type: 'POST', @@ -178,15 +185,16 @@ var manageWebpages = { // Actions that depend on the webpage having been removed from the DOM: numWebpages = $('.webpage').length; // retrieve the new length after removing webpage from the DOM - if (numWebpages > 0) { - // Reorder to remove any gaps + + // If removed item not last, reorder to remove any gaps + if (numWebpages > 0 && ! removeLast) { manageWebpages.reorder(); - - // If fewer than two webpages remaining, disable drag-drop - if (numWebpages < 2) { - manageWebpages.disableDD(); - } } + + // If fewer than two webpages remaining, disable drag-drop + if (numWebpages < 2) { + manageWebpages.disableDD(); + } }); } else {