NIHVIVO-646 Drag-and-drop author reordering

This commit is contained in:
rjy7 2010-07-01 18:27:07 +00:00
parent 9ba79a0685
commit f9d62691f5
2 changed files with 64 additions and 29 deletions

View file

@ -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. --%>
<%-- <c:url var="undoHref" value="/edit/addAuthorToInformationResource" /> --%>
<li class="authorship" id="${authorshipUri}">
<span class="rank" id="${rank}" />
<span class="rank" id="${rankValue}" /> <%-- ${rankDatatypeUri}</span>--%>
<%-- 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. --%>
<span class="author"><a href="${authorHref}" id="${authorUri}" class="authorLink">${author.name}</a>
<span class="author"><a href="${authorHref}" id="${authorUri}" class="authorLink">${authorName}</a>
<a href="${deleteAuthorshipHref}" class="remove">Remove</a>
<%-- <a href="${undoHref}" class="undo">Undo</a> --%></span>
</li>
@ -361,9 +369,9 @@ SPARQL queries for existing values. --%>
<input type="hidden" id="personUri" name="personUri" value="" /> <!-- Field value populated by JavaScript -->
</div>
<input type="hidden" name="rankPred" value="${rankPred}" />
<input type="hidden" name="rankXsdType" value="${intDatatypeUri}" />
<input type="hidden" name="rank" value="${newRank}" />
<input type="hidden" name="rankPred" id="rankPred" value="${rankPred}" />
<input type="hidden" name="rankXsdType" id="rankXsdType" value="${intDatatypeUri}" />
<input type="hidden" name="rank" id="rank" value="${newRank}" />
<input type="hidden" name="acUrl" id="acUrl" value="<c:url value="/autocomplete?type=${foaf}Person&stem=false" />" />
<input type="hidden" name="reorderUrl" id="reorderUrl" value="<c:url value="/edit/primitiveRdfEdit" />" />

View file

@ -276,50 +276,77 @@ var addAuthorForm = {
initAuthorReordering: function() {
$('#authors').sortable({
update: function() {
addAuthorForm.resetRankings();
addAuthorForm.reorderAuthorships();
}
});
},
resetRankings: function() {
reorderAuthorships: function() {
var rankPred = '<' + $('#rankPred').val() + '>',
rankTypeSuffix = $('#rankXsdType').val(),
additions = '',
retractions = '',
rankTypeSuffix = '^^<' + $('#rankType').val() + '>',
uri,
newRank,
oldRank;
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
},