diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp
index 078aebc9..64d0e4b2 100644
--- a/productMods/edit/forms/addAuthorsToInformationResource.jsp
+++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp
@@ -63,7 +63,10 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor
vreq.setAttribute("flagUri",flagUri);
vreq.setAttribute("stringDatatypeUriJson", MiscWebUtils.escape(XSD.xstring.toString()));
- vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(XSD.xint.toString()));
+
+ String intDatatypeUri = XSD.xint.toString();
+ vreq.setAttribute("intDatatypeUri", intDatatypeUri);
+ vreq.setAttribute("intDatatypeUriJson", MiscWebUtils.escape(intDatatypeUri));
%>
@@ -293,12 +296,17 @@ SPARQL queries for existing values. --%>
<%
-
-
-
+
int rank = 0;
for ( Individual authorship : authorships ) {
- rank = Integer.valueOf(authorship.getDataValue(rankUri));
+ int rank1 = Integer.valueOf(authorship.getDataValue(rankUri));
+ String rankValue = authorship.getDataValue(rankUri); // full value, including xsd type if present
+ if (rankValue == null) {
+ rankValue = "";
+ rank = 0;
+ } else {
+ rank = Integer.valueOf(rankValue); // just the integer value
+ }
Individual author = authorship.getRelatedIndividual(linkedAuthorProperty);
if ( author != null ) {
request.setAttribute("author", author);
@@ -306,27 +314,31 @@ SPARQL queries for existing values. --%>
//request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8"));
request.setAttribute("authorUri", author.getURI());
request.setAttribute("authorshipUri", authorship.getURI());
-
+ request.setAttribute("rank", rank);
%>
-
-
- ${author.name}
- Remove
- <%-- Undo --%>
+
+ <%-- --%>
+
+
+ <%-- 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. --%>
+ ${author.name}
+ Remove
+ <%-- Undo --%>
<%
- }
-
+ }
}
// A new author will be ranked last when added.
// This wouldn't handle gaps in the ranking: vreq.setAttribute("rank", authorships.size()+1);
- vreq.setAttribute("rank", rank + 1);
+ vreq.setAttribute("newRank", rank + 1);
+ vreq.setAttribute("rankPred", rankUri);
%>
@@ -356,8 +368,11 @@ SPARQL queries for existing values. --%>
-
+
+
+
" />
+ " />
diff --git a/productMods/edit/forms/css/addAuthorsToInformationResource.css b/productMods/edit/forms/css/addAuthorsToInformationResource.css
index 92ed2b03..ddeba3c2 100644
--- a/productMods/edit/forms/css/addAuthorsToInformationResource.css
+++ b/productMods/edit/forms/css/addAuthorsToInformationResource.css
@@ -7,18 +7,15 @@
#authors li {
list-style: none;
margin-bottom: .75em;
+ padding-left: 1em;
+ background: url("../images/sortable_icon.png") no-repeat left center;
}
-#authors a.existingAuthor {
+#authors a.authorLink {
display: inline-block;
width: 15em;
}
-/* These are only here for JavaScript to pick up. Don't display!! */
-#authors span.existingAuthorUri {
- display: none;
-}
-
#showAddForm span.or {
display: none;
}
@@ -85,10 +82,15 @@ form a:hover.cancel,
margin-top: 3em;
}
+
+
+/* Disabling undo links for the present. Add back later. */
+/*
a.undo,
#selectedAuthor {
display: none;
}
+*/
/* Hide elements not used in non-JS version of form */
/* rjy7 Currently not supporting non-JS version of this form. */
diff --git a/productMods/edit/forms/images/sortable_icon.png b/productMods/edit/forms/images/sortable_icon.png
new file mode 100644
index 00000000..8cae70f7
Binary files /dev/null and b/productMods/edit/forms/images/sortable_icon.png differ
diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js
index ea293938..7de829ba 100644
--- a/productMods/edit/forms/js/addAuthorsToInformationResource.js
+++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js
@@ -50,7 +50,9 @@ var addAuthorForm = {
this.bindEventListeners();
- this.setUpAutocomplete();
+ this.initAutocomplete();
+
+ this.initAuthorReordering();
if (this.findValidationErrors()) {
this.initFormAfterInvalidSubmission();
@@ -97,6 +99,7 @@ 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)) {
@@ -106,17 +109,17 @@ var addAuthorForm = {
url: $(this).attr('href'),
type: 'POST',
data: {
- deletion: $(this).attr('id')
+ deletion: $(this).parents('.authorship').attr('id')
},
dataType: 'json',
context: $(this), // context for callback
complete: function(request, status) {
- var authorListing = $(this).parent();
-// var author = $(this).siblings('span.authorName');
-// var authorLink = author.children('a.existingAuthor');
+ var authorship = $(this).parents('.authorship');
+// var author = $(this).siblings('span.author');
+// var authorLink = author.children('a.authorLink');
// var authorName = authorLink.html();
if (status === 'success') {
- authorListing.fadeOut(400, function() {
+ authorship.fadeOut(400, function() {
$(this).remove();
});
// $(this).hide();
@@ -272,7 +275,58 @@ var addAuthorForm = {
this.personUriField.val('');
},
- setUpAutocomplete: function() {
+ initAuthorReordering: function() {
+ $('#authors').sortable({
+ update: function() {
+ addAuthorForm.resetRankings();
+ }
+ });
+ },
+
+ resetRankings: function() {
+ var rankPred = '<' + $('#rankPred').val() + '>',
+ additions = '',
+ retractions = '',
+ rankTypeSuffix = '^^<' + $('#rankType').val() + '>',
+ uri,
+ newRank,
+ oldRank;
+ $('li.authorship').each(function(index) {
+ // This value does double duty, for removal and reordering
+ uri = $(this).children('.remove').attr('id');
+ oldRank = $(this).children('.rank').attr('id'); // already contains the rankSuffix, if present
+ newRank = index + 1;
+ additions += uri + ' ' + rankPred + ' ' + '"' + newRank + '"' + rankTypeSuffix + ' .';
+ retractions += uri + ' ' + rankPred + ' ' + '"' + oldRank + ' .';
+ });
+ console.log(additions);
+ console.log(retractions);
+ $.ajax({
+ url: $('#reorderUrl').val(),
+ data: {
+ additions: additions,
+ retractions: retractions
+ },
+ dataType: 'json',
+ type: 'POST',
+ success: function(xhr, status, error) {
+ // reset rank in the span
+ // can just do from values we computed, if easier than getting data back from server
+ //
+ },
+ error: function(data, status, request) {
+ addAuthorForm.restorePreviousRankings();
+ alert('Reordering of author ranks failed.');
+ }
+ });
+ },
+
+ restorePreviousRankings: function() {
+ // restore existing rankings after reordering failure
+ // use span.rank id attr value to determine
+ },
+
+ initAutocomplete: function() {
var cache = {};
var url = $('#acUrl').val();