NIHVIVO-646 update authorship ranks on page after successful drag-and-drop reordering
This commit is contained in:
parent
f9d62691f5
commit
8b96e68e71
3 changed files with 52 additions and 33 deletions
|
@ -295,7 +295,7 @@ SPARQL queries for existing values. --%>
|
||||||
//System.out.println(vreq.getAttribute("entToReturnTo"));
|
//System.out.println(vreq.getAttribute("entToReturnTo"));
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<ul id="authors">
|
<ul id="authorships">
|
||||||
<%
|
<%
|
||||||
|
|
||||||
int rank = 0;
|
int rank = 0;
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
#authors {
|
#authorships {
|
||||||
margin-left: 0;
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#authors li {
|
#authorships li {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin-bottom: .75em;
|
margin-bottom: .75em;
|
||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
background: url("../images/sortable_icon.png") no-repeat left center;
|
background: url("../images/sortable_icon.png") no-repeat left center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#authors a.authorLink {
|
#authorships a.authorLink {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 15em;
|
width: 15em;
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,22 @@ form h3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
form a:link.cancel, form a:visited.cancel,
|
form a:link.cancel, form a:visited.cancel,
|
||||||
#authors a:link.remove, #authors a:visited.remove,
|
#authorships a:link.remove, #authorships a:visited.remove,
|
||||||
#authors a:link.undo, #authors a:visited.undo,
|
#authorships a:link.undo, #authorships a:visited.undo,
|
||||||
#showAddForm a:link.cancel, #showAddForm a:visited.cancel {
|
#showAddForm a:link.cancel, #showAddForm a:visited.cancel {
|
||||||
color: #f70;
|
color: #f70;
|
||||||
border-color: #f70;
|
border-color: #f70;
|
||||||
}
|
}
|
||||||
|
|
||||||
form a:hover.cancel,
|
form a:hover.cancel,
|
||||||
#authors a:hover.remove,
|
#authorships a:hover.remove,
|
||||||
#authors a:hover.undo,
|
#authorships a:hover.undo,
|
||||||
#showAddForm a:hover.cancel {
|
#showAddForm a:hover.cancel {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: #f70;
|
background: #f70;
|
||||||
}
|
}
|
||||||
|
|
||||||
#authors a.undo {
|
#authorships a.undo {
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,7 @@ var addAuthorForm = {
|
||||||
},
|
},
|
||||||
|
|
||||||
initAuthorReordering: function() {
|
initAuthorReordering: function() {
|
||||||
$('#authors').sortable({
|
$('#authorships').sortable({
|
||||||
update: function() {
|
update: function() {
|
||||||
addAuthorForm.reorderAuthorships();
|
addAuthorForm.reorderAuthorships();
|
||||||
}
|
}
|
||||||
|
@ -283,32 +283,45 @@ var addAuthorForm = {
|
||||||
|
|
||||||
reorderAuthorships: function() {
|
reorderAuthorships: function() {
|
||||||
|
|
||||||
var rankPred = '<' + $('#rankPred').val() + '>',
|
var predicateUri = '<' + $('#rankPred').val() + '>',
|
||||||
rankTypeSuffix = $('#rankXsdType').val(),
|
rankXsdType = $('#rankXsdType').val(),
|
||||||
additions = '',
|
additions = '',
|
||||||
retractions = '';
|
retractions = '',
|
||||||
|
authorships = [];
|
||||||
|
|
||||||
$('li.authorship').each(function(index) {
|
$('li.authorship').each(function(index) {
|
||||||
// This value does double duty, for removal and reordering
|
var uri = $(this).attr('id'),
|
||||||
var uri = '<' + $(this).attr('id') + '>',
|
subjectUri = '<' + uri + '>',
|
||||||
newRank = index + 1,
|
oldRankVal = $(this).children('.rank').attr('id'),
|
||||||
newRankVal,
|
newRank = index + 1,
|
||||||
|
newRankForN3,
|
||||||
oldRank,
|
oldRank,
|
||||||
oldRankType,
|
oldRankType,
|
||||||
oldRankVal,
|
oldRankForN3,
|
||||||
rankVals;
|
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];
|
oldRank = rankVals[0];
|
||||||
oldRankType = rankVals[1];
|
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("additions: " + additions);
|
||||||
// console.log("retractions: " + retractions);
|
// console.log("retractions: " + retractions);
|
||||||
|
|
||||||
|
@ -318,17 +331,15 @@ var addAuthorForm = {
|
||||||
additions: additions,
|
additions: additions,
|
||||||
retractions: retractions
|
retractions: retractions
|
||||||
},
|
},
|
||||||
additions: additions,
|
authorships: authorships,
|
||||||
retractions: retractions,
|
|
||||||
processData: 'false',
|
processData: 'false',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
success: function(data, status, request) {
|
success: function(data, status, request) {
|
||||||
addAuthorForm.resetRankVals(this.additions);
|
addAuthorForm.updateRanks(this.authorships);
|
||||||
console.log(this.additions)
|
|
||||||
},
|
},
|
||||||
error: function(request, status, error) {
|
error: function(request, status, error) {
|
||||||
addAuthorForm.restorePreviousOrder();
|
addAuthorForm.resetOrder(this.authorships);
|
||||||
alert('Reordering of author ranks failed.');
|
alert('Reordering of author ranks failed.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -342,11 +353,19 @@ var addAuthorForm = {
|
||||||
return rankVal;
|
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
|
// restore existing rankings after reordering failure
|
||||||
// use span.rank id attr value to determine
|
// use span.rank id attr value to determine
|
||||||
},
|
},
|
||||||
|
@ -398,7 +417,7 @@ var addAuthorForm = {
|
||||||
|
|
||||||
getExistingAuthorUris: function() {
|
getExistingAuthorUris: function() {
|
||||||
|
|
||||||
var existingAuthors = $('#authors li');
|
var existingAuthors = $('#authorships li');
|
||||||
return existingAuthors.map(function() {
|
return existingAuthors.map(function() {
|
||||||
return $(this).attr('id');
|
return $(this).attr('id');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue