diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp index 56859aad..fdcf176c 100644 --- a/productMods/edit/forms/addAuthorsToInformationResource.jsp +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -31,6 +31,7 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator" %> @@ -299,14 +300,21 @@ SPARQL queries for existing values. --%> int rank = 0; for ( Individual authorship : authorships ) { - rank = Integer.valueOf(authorship.getDataValue(rankPredicateUri)); + String rankDatatypeUri = ""; + DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(rankPredicateUri); + if (rankStmt != null) { + rank = Integer.valueOf(rankStmt.getData()); + rankDatatypeUri = rankStmt.getDatatypeURI(); + } + Individual author = authorship.getRelatedIndividual(linkedAuthorProperty); if ( author != null ) { - request.setAttribute("author", author); + request.setAttribute("authorName", author.getName()); // 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()); + request.setAttribute("rankValue", rank + "_" + rankDatatypeUri); request.setAttribute("rank", rank); %> @@ -317,10 +325,10 @@ SPARQL queries for existing values. --%> <%-- --%>
  • - + <%-- ${rankDatatypeUri}--%> <%-- 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} + ${authorName} Remove <%-- Undo --%>
  • @@ -361,9 +369,9 @@ SPARQL queries for existing values. --%> - - - + + + " /> " /> diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index dfe844ee..7721d3cc 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -276,50 +276,77 @@ var addAuthorForm = { initAuthorReordering: function() { $('#authors').sortable({ update: function() { - addAuthorForm.resetRankings(); + addAuthorForm.reorderAuthorships(); } }); }, - resetRankings: function() { + reorderAuthorships: function() { + var rankPred = '<' + $('#rankPred').val() + '>', - additions = '', - retractions = '', - rankTypeSuffix = '^^<' + $('#rankType').val() + '>', - uri, - newRank, - oldRank; + rankTypeSuffix = $('#rankXsdType').val(), + additions = '', + retractions = ''; + $('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 + ' .'; + var uri = '<' + $(this).attr('id') + '>', + newRank = index + 1, + newRankVal, + oldRank, + oldRankType, + oldRankVal, + rankVals; + + rankVals = $(this).children('.rank').attr('id').split('_'); // e.g., 1_http://www.w3.org/2001/XMLSchema#int + oldRank = rankVals[0]; + oldRankType = rankVals[1]; + oldRankVal = addAuthorForm.makeRankDataPropVal(oldRank, oldRankType); + + newRankVal = addAuthorForm.makeRankDataPropVal(newRank, rankTypeSuffix); + + additions += uri + ' ' + rankPred + ' ' + newRankVal + ' .'; + retractions += uri + ' ' + rankPred + ' ' + oldRankVal + ' .'; }); - console.log(additions); - console.log(retractions); + + // console.log("additions: " + additions); + // console.log("retractions: " + retractions); + $.ajax({ url: $('#reorderUrl').val(), data: { additions: additions, retractions: retractions }, + additions: additions, + retractions: retractions, + processData: 'false', 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 - // + success: function(data, status, request) { + addAuthorForm.resetRankVals(this.additions); + console.log(this.additions) }, - error: function(data, status, request) { - addAuthorForm.restorePreviousRankings(); + error: function(request, status, error) { + addAuthorForm.restorePreviousOrder(); alert('Reordering of author ranks failed.'); } }); }, - restorePreviousRankings: function() { + makeRankDataPropVal: function(rank, xsdType) { + var rankVal = '"' + rank + '"'; + if (xsdType) { + rankVal += '^^<' + xsdType + '>' + } + return rankVal; + }, + + resetRankVals: function() { + + }, + + restorePreviousOrder: function() { // restore existing rankings after reordering failure // use span.rank id attr value to determine },