NIHVIVO-646 JS bug fixes and refinements
This commit is contained in:
parent
745e98e0fb
commit
63c49c180d
3 changed files with 72 additions and 31 deletions
|
@ -293,14 +293,20 @@ SPARQL queries for existing values. --%>
|
||||||
// ulClass = "class='processedSubmission'";
|
// ulClass = "class='processedSubmission'";
|
||||||
//}
|
//}
|
||||||
//System.out.println(vreq.getAttribute("entToReturnTo"));
|
//System.out.println(vreq.getAttribute("entToReturnTo"));
|
||||||
|
String ulClass = "";
|
||||||
|
if (authorships.size() > 1) {
|
||||||
|
// This class triggers application of dd styles. Don't wait for js to add
|
||||||
|
// the ui-sortable class, because then the page flashes as the styles are updated.
|
||||||
|
ulClass = "class='dd'";
|
||||||
|
}
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<ul id="authorships">
|
<ul id="authorships" <%= ulClass %>>
|
||||||
<%
|
<%
|
||||||
|
|
||||||
int rank = 0;
|
int rank = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
request.setAttribute("authorshipCount", authorships.size());
|
|
||||||
for ( Individual authorship : authorships ) {
|
for ( Individual authorship : authorships ) {
|
||||||
String rankDatatypeUri = "";
|
String rankDatatypeUri = "";
|
||||||
DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(rankPredicateUri);
|
DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(rankPredicateUri);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
margin-bottom: .75em;
|
margin-bottom: .75em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#authorships.dd li,
|
||||||
#authorships.ui-sortable li {
|
#authorships.ui-sortable li {
|
||||||
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;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
var addAuthorForm = {
|
var addAuthorForm = {
|
||||||
|
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
|
|
||||||
this.mixIn();
|
this.mixIn();
|
||||||
this.initObjects();
|
this.initObjects();
|
||||||
this.initPage();
|
this.initPage();
|
||||||
|
@ -111,20 +110,32 @@ var addAuthorForm = {
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
context: $(this), // context for callback
|
context: $(this), // context for callback
|
||||||
complete: function(request, status) {
|
complete: function(request, status) {
|
||||||
var authorship = $(this).parents('.authorship');
|
var authorship = $(this).parents('.authorship'),
|
||||||
// var author = $(this).siblings('span.author');
|
nextAuthorships = authorship.next(),
|
||||||
// var authorLink = author.children('a.authorLink');
|
rank;
|
||||||
// var authorName = authorLink.html();
|
// author = $(this).siblings('span.author'),
|
||||||
|
// authorLink = author.children('a.authorLink'),
|
||||||
|
// authorName = authorLink.html();
|
||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
// Reset the position value of each succeeding authorship
|
|
||||||
authorship.next().each(function() {
|
if (nextAuthorships.length) {
|
||||||
var pos = parseInt($(this).children('.position').attr('id'));
|
// Reset the position value of each succeeding authorship
|
||||||
$(this).children('.position').attr('id', pos-1);
|
nextAuthorships.each(function() {
|
||||||
});
|
//var pos = parseInt($(this).children('.position').attr('id'));
|
||||||
|
//$(this).children('.position').attr('id', pos-1);
|
||||||
|
var pos = addAuthorForm.getPosition(this);
|
||||||
|
addAuthorForm.setPosition(this, pos-1);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Removed author was last in rank: reset the rank hidden form field
|
||||||
|
rank = addAuthorForm.getRank(authorship);
|
||||||
|
$('input#rank').val(rank);
|
||||||
|
}
|
||||||
|
|
||||||
authorship.fadeOut(400, function() {
|
authorship.fadeOut(400, function() {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
// If there's just one author remaining, remove the drag and drop title message.
|
// If there's just one author remaining, disable drag-drop
|
||||||
if ($('.authorship').length == 1) {
|
if ($('.authorship').length == 1) {
|
||||||
addAuthorForm.disableAuthorDD();
|
addAuthorForm.disableAuthorDD();
|
||||||
}
|
}
|
||||||
|
@ -152,12 +163,13 @@ var addAuthorForm = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Disable DD and cues if only one author remaining
|
// Disable DD and associated cues if only one author remains
|
||||||
disableAuthorDD: function() {
|
disableAuthorDD: function() {
|
||||||
var author = $('.authorship');
|
var authorship = $('.authorship');
|
||||||
$('#authorships').sortable({ disable: true} );
|
$('#authorships').sortable({ disable: true} );
|
||||||
author.css('background', 'none');
|
authorship.css('background', 'none');
|
||||||
author.css('padding-left', '0');
|
authorship.css('padding-left', '0');
|
||||||
|
authorship.children('.author').attr('title', '');
|
||||||
},
|
},
|
||||||
|
|
||||||
onLastNameChange: function() {
|
onLastNameChange: function() {
|
||||||
|
@ -300,9 +312,7 @@ var addAuthorForm = {
|
||||||
}
|
}
|
||||||
|
|
||||||
authorships.each(function() {
|
authorships.each(function() {
|
||||||
// Make sure all browsers support title attribute on elements other than link and image.
|
$(this).children('.author').attr('title', 'Drag and drop to reorder authors');
|
||||||
// If not, move title to the author link.
|
|
||||||
$(this).attr('title', 'Drag and drop to reorder authors');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
authorshipList.sortable({
|
authorshipList.sortable({
|
||||||
|
@ -316,7 +326,7 @@ var addAuthorForm = {
|
||||||
$('li.authorship').each(function(index) {
|
$('li.authorship').each(function(index) {
|
||||||
var uri = $(this).attr('id'),
|
var uri = $(this).attr('id'),
|
||||||
subjectUri = '<' + uri + '>',
|
subjectUri = '<' + uri + '>',
|
||||||
oldRankVal = $(this).children('.rank').attr('id'),
|
oldRankVal = addAuthorForm.getRankVal(this),
|
||||||
newRank = index + 1,
|
newRank = index + 1,
|
||||||
newRankForN3,
|
newRankForN3,
|
||||||
oldRank,
|
oldRank,
|
||||||
|
@ -338,7 +348,7 @@ var addAuthorForm = {
|
||||||
// of the Ajax request.
|
// of the Ajax request.
|
||||||
authorship = {
|
authorship = {
|
||||||
uri: uri,
|
uri: uri,
|
||||||
newRank: newRank + '_' + rankXsdType
|
rankVal: newRank + '_' + rankXsdType
|
||||||
};
|
};
|
||||||
authorships.push(authorship);
|
authorships.push(authorship);
|
||||||
|
|
||||||
|
@ -362,22 +372,24 @@ var addAuthorForm = {
|
||||||
$.each(authorships, function(index, obj) {
|
$.each(authorships, function(index, obj) {
|
||||||
// find the element with this uri as id
|
// find the element with this uri as id
|
||||||
var el = $('li[id=' + obj.uri + ']'),
|
var el = $('li[id=' + obj.uri + ']'),
|
||||||
rank = obj.newRank,
|
// because all ranks have been reordered without gaps,
|
||||||
pos = rank.split('_')[0];
|
// we can get the position from the rank
|
||||||
// set the new rank for this element
|
pos = obj.rankVal.split('_')[0];
|
||||||
el.children('.rank').attr('id', rank);
|
// set the new rank and position for this element
|
||||||
el.children('.position').attr('id', pos);
|
addAuthorForm.setRankVal(el, obj.rankVal);
|
||||||
|
addAuthorForm.setPosition(el, pos);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(request, status, error) {
|
error: function(request, status, error) {
|
||||||
// Put the moved item back to its original position.
|
// Put the moved item back to its original position.
|
||||||
// Seems we need to do this by hand. Can't see any way to do it with jQuery UI. ??
|
// Seems we need to do this by hand. Can't see any way to do it with jQuery UI. ??
|
||||||
var pos = ui.item.children('.position').attr('id'),
|
var pos = addAuthorForm.getPosition(ui.item),
|
||||||
nextpos = parseInt(pos) + 1,
|
//ui.item.children('.position').attr('id'),
|
||||||
|
nextpos = pos + 1,
|
||||||
authorships = $('#authorships'),
|
authorships = $('#authorships'),
|
||||||
next = authorships.find('.position[id=' + nextpos + ']').parent();
|
next = authorships.find('.position[id=' + nextpos + ']').parent();
|
||||||
|
|
||||||
if (next.length > 0) {
|
if (next.length) {
|
||||||
ui.item.insertBefore(next);
|
ui.item.insertBefore(next);
|
||||||
} else {
|
} else {
|
||||||
ui.item.appendTo(authorships);
|
ui.item.appendTo(authorships);
|
||||||
|
@ -390,6 +402,28 @@ var addAuthorForm = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getPosition: function(authorship) {
|
||||||
|
return parseInt($(authorship).children('.position').attr('id'));
|
||||||
|
},
|
||||||
|
|
||||||
|
setPosition: function(authorship, pos) {
|
||||||
|
$(authorship).children('.position').attr('id', pos);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get the authorship rank value, which includes xsd type
|
||||||
|
getRankVal: function(authorship) {
|
||||||
|
return $(authorship).children('.rank').attr('id');
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get the integer value from the authorship rank value
|
||||||
|
getRank: function(authorship) {
|
||||||
|
return this.getRankVal(authorship).split('_')[0];
|
||||||
|
},
|
||||||
|
|
||||||
|
setRankVal: function(authorship, rank) {
|
||||||
|
$(authorship).children('.rank').attr('id', rank);
|
||||||
|
},
|
||||||
|
|
||||||
makeRankDataPropVal: function(rank, xsdType) {
|
makeRankDataPropVal: function(rank, xsdType) {
|
||||||
var rankVal = '"' + rank + '"';
|
var rankVal = '"' + rank + '"';
|
||||||
if (xsdType) {
|
if (xsdType) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue