From 745e98e0fbc46d981cabea9baa8364963a4cbe1b Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 2 Jul 2010 16:09:26 +0000 Subject: [PATCH] NIHVIVO-646 Disable author drag-drop if only 1 author (on page load or after removing an author) --- .../forms/addAuthorsToInformationResource.jsp | 6 ++-- .../css/addAuthorsToInformationResource.css | 7 ++-- .../js/addAuthorsToInformationResource.js | 34 ++++++++++++++++--- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp index 6b027cc9..102126e7 100644 --- a/productMods/edit/forms/addAuthorsToInformationResource.jsp +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -300,6 +300,7 @@ SPARQL queries for existing values. --%> int rank = 0; int index = 0; + request.setAttribute("authorshipCount", authorships.size()); for ( Individual authorship : authorships ) { String rankDatatypeUri = ""; DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(rankPredicateUri); @@ -329,13 +330,12 @@ SPARQL queries for existing values. --%> - - <%-- --%> +
  • <%-- This span will be used in the next phase, when we display a message that the author has been - removed. That text will replace the a.authorLink. --%> + removed. That text will replace the a.authorLink, which will be removed. --%> ${authorName} Remove <%-- Undo --%> diff --git a/productMods/edit/forms/css/addAuthorsToInformationResource.css b/productMods/edit/forms/css/addAuthorsToInformationResource.css index 7cc51616..b211950b 100644 --- a/productMods/edit/forms/css/addAuthorsToInformationResource.css +++ b/productMods/edit/forms/css/addAuthorsToInformationResource.css @@ -7,8 +7,11 @@ #authorships li { list-style: none; margin-bottom: .75em; +} + +#authorships.ui-sortable li { padding-left: 1em; - background: url("../images/sortable_icon.png") no-repeat left center; + background: url("../images/sortable_icon.png") no-repeat left center; } #authorships a.authorLink { @@ -95,8 +98,6 @@ form a:hover.cancel, margin-top: 3em; } - - /* Disabling undo links for the present. Add back later. */ /* a.undo, diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index f95e5c93..eb310bcf 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -97,7 +97,6 @@ var addAuthorForm = { }); this.removeAuthorshipLinks.click(function() { - console.log($(this).parents('.authorship')); // RY Upgrade this to a modal window var message = "Are you sure you want to remove this author?"; if (!confirm(message)) { @@ -122,17 +121,22 @@ var addAuthorForm = { var pos = parseInt($(this).children('.position').attr('id')); $(this).children('.position').attr('id', pos-1); }); + authorship.fadeOut(400, function() { $(this).remove(); + // If there's just one author remaining, remove the drag and drop title message. + if ($('.authorship').length == 1) { + addAuthorForm.disableAuthorDD(); + } }); - + // $(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'); + alert('Error processing request: author not removed'); } } }); @@ -148,6 +152,14 @@ var addAuthorForm = { }, + // Disable DD and cues if only one author remaining + disableAuthorDD: function() { + var author = $('.authorship'); + $('#authorships').sortable({ disable: true} ); + author.css('background', 'none'); + author.css('padding-left', '0'); + }, + onLastNameChange: function() { this.showFieldsForNewPerson(); this.firstNameField.focus(); @@ -279,7 +291,21 @@ var addAuthorForm = { }, initAuthorReordering: function() { - $('#authorships').sortable({ + + var authorshipList = $('#authorships'), + authorships = authorshipList.children(); + + if (authorships.length < 2) { + return; + } + + authorships.each(function() { + // Make sure all browsers support title attribute on elements other than link and image. + // If not, move title to the author link. + $(this).attr('title', 'Drag and drop to reorder authors'); + }); + + authorshipList.sortable({ stop: function(event, ui) { var predicateUri = '<' + $('.rankPred').attr('id') + '>', rankXsdType = $('.rankXsdType').attr('id'),