NIHVIVO-646 update authorship ranks on page after successful drag-and-drop reordering

This commit is contained in:
rjy7 2010-07-01 19:31:29 +00:00
parent f9d62691f5
commit 8b96e68e71
3 changed files with 52 additions and 33 deletions

View file

@ -295,7 +295,7 @@ SPARQL queries for existing values. --%>
//System.out.println(vreq.getAttribute("entToReturnTo"));
%>
<ul id="authors">
<ul id="authorships">
<%
int rank = 0;

View file

@ -1,17 +1,17 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
#authors {
#authorships {
margin-left: 0;
}
#authors li {
#authorships li {
list-style: none;
margin-bottom: .75em;
padding-left: 1em;
background: url("../images/sortable_icon.png") no-repeat left center;
}
#authors a.authorLink {
#authorships a.authorLink {
display: inline-block;
width: 15em;
}
@ -29,22 +29,22 @@ form h3 {
}
form a:link.cancel, form a:visited.cancel,
#authors a:link.remove, #authors a:visited.remove,
#authors a:link.undo, #authors a:visited.undo,
#authorships a:link.remove, #authorships a:visited.remove,
#authorships a:link.undo, #authorships a:visited.undo,
#showAddForm a:link.cancel, #showAddForm a:visited.cancel {
color: #f70;
border-color: #f70;
}
form a:hover.cancel,
#authors a:hover.remove,
#authors a:hover.undo,
#authorships a:hover.remove,
#authorships a:hover.undo,
#showAddForm a:hover.cancel {
color: #fff;
background: #f70;
}
#authors a.undo {
#authorships a.undo {
margin-left: 1em;
}

View file

@ -274,7 +274,7 @@ var addAuthorForm = {
},
initAuthorReordering: function() {
$('#authors').sortable({
$('#authorships').sortable({
update: function() {
addAuthorForm.reorderAuthorships();
}
@ -283,32 +283,45 @@ var addAuthorForm = {
reorderAuthorships: function() {
var rankPred = '<' + $('#rankPred').val() + '>',
rankTypeSuffix = $('#rankXsdType').val(),
var predicateUri = '<' + $('#rankPred').val() + '>',
rankXsdType = $('#rankXsdType').val(),
additions = '',
retractions = '';
retractions = '',
authorships = [];
$('li.authorship').each(function(index) {
// This value does double duty, for removal and reordering
var uri = '<' + $(this).attr('id') + '>',
newRank = index + 1,
newRankVal,
var uri = $(this).attr('id'),
subjectUri = '<' + uri + '>',
oldRankVal = $(this).children('.rank').attr('id'),
newRank = index + 1,
newRankForN3,
oldRank,
oldRankType,
oldRankVal,
oldRankForN3,
rankVals;
rankVals = $(this).children('.rank').attr('id').split('_'); // e.g., 1_http://www.w3.org/2001/XMLSchema#int
rankVals = oldRankVal.split('_'); // e.g., 1_http://www.w3.org/2001/XMLSchema#int
oldRank = rankVals[0];
oldRankType = rankVals[1];
oldRankVal = addAuthorForm.makeRankDataPropVal(oldRank, oldRankType);
oldRankForN3 = addAuthorForm.makeRankDataPropVal(oldRank, oldRankType);
newRankVal = addAuthorForm.makeRankDataPropVal(newRank, rankTypeSuffix);
newRankForN3 = addAuthorForm.makeRankDataPropVal(newRank, rankXsdType);
additions += subjectUri + ' ' + predicateUri + ' ' + newRankForN3 + ' .';
retractions += subjectUri + ' ' + predicateUri + ' ' + oldRankForN3 + ' .';
// This object will be used to modify the page after success or failure of the
// Ajax request.
authorship = {
uri: uri,
oldRank: oldRank,
newRank: newRank + '_' + rankXsdType
};
authorships.push(authorship);
additions += uri + ' ' + rankPred + ' ' + newRankVal + ' .';
retractions += uri + ' ' + rankPred + ' ' + oldRankVal + ' .';
});
// console.log(authorships)
// console.log("additions: " + additions);
// console.log("retractions: " + retractions);
@ -318,17 +331,15 @@ var addAuthorForm = {
additions: additions,
retractions: retractions
},
additions: additions,
retractions: retractions,
authorships: authorships,
processData: 'false',
dataType: 'json',
type: 'POST',
success: function(data, status, request) {
addAuthorForm.resetRankVals(this.additions);
console.log(this.additions)
addAuthorForm.updateRanks(this.authorships);
},
error: function(request, status, error) {
addAuthorForm.restorePreviousOrder();
addAuthorForm.resetOrder(this.authorships);
alert('Reordering of author ranks failed.');
}
});
@ -342,11 +353,19 @@ var addAuthorForm = {
return rankVal;
},
resetRankVals: function() {
// After drag-and-drop reorder, update the rank vals stored with the authorships;
// otherwise, additional reorderings will issue incorrect retractions in the request.
updateRanks: function(authorships) {
$.each(authorships, function(index, obj) {
// find the element with this uri as id
var el = $('li[id=' + obj.uri + ']');
// set the new rank for this element
el.children('.rank').attr('id', obj.newRank);
});
},
restorePreviousOrder: function() {
// After drag-and-drop failure, reset to original order
resetOrder: function(authorships) {
// restore existing rankings after reordering failure
// use span.rank id attr value to determine
},
@ -398,7 +417,7 @@ var addAuthorForm = {
getExistingAuthorUris: function() {
var existingAuthors = $('#authors li');
var existingAuthors = $('#authorships li');
return existingAuthors.map(function() {
return $(this).attr('id');
});