NIHVIVO-646 Drag-and-drop author reordering
This commit is contained in:
parent
9ba79a0685
commit
f9d62691f5
2 changed files with 64 additions and 29 deletions
|
@ -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.Individual" %>
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %>
|
<%@ 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.dao.VitroVocabulary" %>
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator" %>
|
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator" %>
|
||||||
|
@ -299,14 +300,21 @@ SPARQL queries for existing values. --%>
|
||||||
|
|
||||||
int rank = 0;
|
int rank = 0;
|
||||||
for ( Individual authorship : authorships ) {
|
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);
|
Individual author = authorship.getRelatedIndividual(linkedAuthorProperty);
|
||||||
if ( author != null ) {
|
if ( author != null ) {
|
||||||
request.setAttribute("author", author);
|
request.setAttribute("authorName", author.getName());
|
||||||
// Doesn't seem to need urlencoding to add as id attribute value
|
// Doesn't seem to need urlencoding to add as id attribute value
|
||||||
//request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8"));
|
//request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8"));
|
||||||
request.setAttribute("authorUri", author.getURI());
|
request.setAttribute("authorUri", author.getURI());
|
||||||
request.setAttribute("authorshipUri", authorship.getURI());
|
request.setAttribute("authorshipUri", authorship.getURI());
|
||||||
|
request.setAttribute("rankValue", rank + "_" + rankDatatypeUri);
|
||||||
request.setAttribute("rank", rank);
|
request.setAttribute("rank", rank);
|
||||||
|
|
||||||
%>
|
%>
|
||||||
|
@ -317,10 +325,10 @@ SPARQL queries for existing values. --%>
|
||||||
|
|
||||||
<%-- <c:url var="undoHref" value="/edit/addAuthorToInformationResource" /> --%>
|
<%-- <c:url var="undoHref" value="/edit/addAuthorToInformationResource" /> --%>
|
||||||
<li class="authorship" id="${authorshipUri}">
|
<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
|
<%-- 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. --%>
|
||||||
<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="${deleteAuthorshipHref}" class="remove">Remove</a>
|
||||||
<%-- <a href="${undoHref}" class="undo">Undo</a> --%></span>
|
<%-- <a href="${undoHref}" class="undo">Undo</a> --%></span>
|
||||||
</li>
|
</li>
|
||||||
|
@ -361,9 +369,9 @@ SPARQL queries for existing values. --%>
|
||||||
<input type="hidden" id="personUri" name="personUri" value="" /> <!-- Field value populated by JavaScript -->
|
<input type="hidden" id="personUri" name="personUri" value="" /> <!-- Field value populated by JavaScript -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="rankPred" value="${rankPred}" />
|
<input type="hidden" name="rankPred" id="rankPred" value="${rankPred}" />
|
||||||
<input type="hidden" name="rankXsdType" value="${intDatatypeUri}" />
|
<input type="hidden" name="rankXsdType" id="rankXsdType" value="${intDatatypeUri}" />
|
||||||
<input type="hidden" name="rank" value="${newRank}" />
|
<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="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" />" />
|
<input type="hidden" name="reorderUrl" id="reorderUrl" value="<c:url value="/edit/primitiveRdfEdit" />" />
|
||||||
|
|
||||||
|
|
|
@ -276,50 +276,77 @@ var addAuthorForm = {
|
||||||
initAuthorReordering: function() {
|
initAuthorReordering: function() {
|
||||||
$('#authors').sortable({
|
$('#authors').sortable({
|
||||||
update: function() {
|
update: function() {
|
||||||
addAuthorForm.resetRankings();
|
addAuthorForm.reorderAuthorships();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
resetRankings: function() {
|
reorderAuthorships: function() {
|
||||||
|
|
||||||
var rankPred = '<' + $('#rankPred').val() + '>',
|
var rankPred = '<' + $('#rankPred').val() + '>',
|
||||||
additions = '',
|
rankTypeSuffix = $('#rankXsdType').val(),
|
||||||
retractions = '',
|
additions = '',
|
||||||
rankTypeSuffix = '^^<' + $('#rankType').val() + '>',
|
retractions = '';
|
||||||
uri,
|
|
||||||
newRank,
|
|
||||||
oldRank;
|
|
||||||
$('li.authorship').each(function(index) {
|
$('li.authorship').each(function(index) {
|
||||||
// This value does double duty, for removal and reordering
|
// This value does double duty, for removal and reordering
|
||||||
uri = $(this).children('.remove').attr('id');
|
var uri = '<' + $(this).attr('id') + '>',
|
||||||
oldRank = $(this).children('.rank').attr('id'); // already contains the rankSuffix, if present
|
newRank = index + 1,
|
||||||
newRank = index + 1;
|
newRankVal,
|
||||||
additions += uri + ' ' + rankPred + ' ' + '"' + newRank + '"' + rankTypeSuffix + ' .';
|
oldRank,
|
||||||
retractions += uri + ' ' + rankPred + ' ' + '"' + 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({
|
$.ajax({
|
||||||
url: $('#reorderUrl').val(),
|
url: $('#reorderUrl').val(),
|
||||||
data: {
|
data: {
|
||||||
additions: additions,
|
additions: additions,
|
||||||
retractions: retractions
|
retractions: retractions
|
||||||
},
|
},
|
||||||
|
additions: additions,
|
||||||
|
retractions: retractions,
|
||||||
|
processData: 'false',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
success: function(xhr, status, error) {
|
success: function(data, status, request) {
|
||||||
// reset rank in the span
|
addAuthorForm.resetRankVals(this.additions);
|
||||||
// can just do from values we computed, if easier than getting data back from server
|
console.log(this.additions)
|
||||||
//
|
|
||||||
},
|
},
|
||||||
error: function(data, status, request) {
|
error: function(request, status, error) {
|
||||||
addAuthorForm.restorePreviousRankings();
|
addAuthorForm.restorePreviousOrder();
|
||||||
alert('Reordering of author ranks failed.');
|
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
|
// restore existing rankings after reordering failure
|
||||||
// use span.rank id attr value to determine
|
// use span.rank id attr value to determine
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue