NIHVIVO-741 Refactor addAuthorForm javascript to use data attached to objects rather than DOM elements and spans to store authorship data.

This commit is contained in:
rjy7 2010-08-16 19:48:06 +00:00
parent 3f4f00b1e2
commit 227bdb81d4

View file

@ -225,7 +225,6 @@ var addAuthorForm = {
}, },
setAcFilter: function() { setAcFilter: function() {
//var existingAuthors = $('#authorships .authorName');
this.acFilter = []; this.acFilter = [];
$('.authorship').each(function() { $('.authorship').each(function() {
@ -372,31 +371,32 @@ var addAuthorForm = {
$.each(authorships, function(index, obj) { $.each(authorships, function(index, obj) {
// find the authorship with this uri // find the authorship with this uri
var authorship = addAuthorForm.findAuthorship('authorshipUri', obj.uri), var authorship = addAuthorForm.findAuthorship('authorshipUri', obj.uri),
//var el = $('li[id=' + obj.uri + ']'),
// because all ranks have been reordered without gaps, // because all ranks have been reordered without gaps,
// we can get the position from the rank // we can get the position from the rank
rank = addAuthorForm.getRankIntValFromRankVal(obj.rankVal); pos = addAuthorForm.getRankIntValFromRankVal(obj.rankVal);
// set the new rank and position for this element // set the new rank and position for this element
addAuthorForm.setRank(authorship, obj.rankVal); addAuthorForm.setRank(authorship, obj.rankVal);
addAuthorForm.setPosition(authorship, rank); addAuthorForm.setPosition(authorship, pos);
maxRank = rank; maxRank = pos;
// console.log(authorship.data('authorshipUri') + ' is at rank ' + authorship.data('rankVal')); // console.log(authorship.data('authorshipUri') + ' is at rank ' + authorship.data('rankVal'));
}); });
// Set the form rank field value. // Set the form rank field value.
$('#rank').val(maxRank + 1); $('#rank').val(maxRank + 1);
// console.log("value of rank field = " + $('#rank').val());
}, },
error: function(request, status, error) { error: function(request, status, error) {
// This is performed only after drag-and-drop. // ui is undefined on page load and after an authorship removal.
if (ui) { if (ui) {
// 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 = addAuthorForm.getPosition(ui.item), var pos = addAuthorForm.getPosition(ui.item),
nextpos = pos + 1, authorships = $('#authorships'), nextpos = pos + 1,
authorships = $('#authorships'),
next = addAuthorForm.findAuthorship('position', nextpos); next = addAuthorForm.findAuthorship('position', nextpos);
//authorships.find('.position[id=' + nextpos + ']').parent(); //authorships.find('.position[id=' + nextpos + ']').parent();
if (next.length) { if (next) {
ui.item.insertBefore(next); ui.item.insertBefore(next);
} }
else { else {
@ -439,7 +439,7 @@ var addAuthorForm = {
// Get the authorship numeric rank // Get the authorship numeric rank
getRankIntVal: function(authorship) { getRankIntVal: function(authorship) {
var rankVal = getRankStrVal(authorship); var rankVal = this.getRankStrVal(authorship);
return this.getRankIntValFromRankVal(rankVal); return this.getRankIntValFromRankVal(rankVal);
}, },
@ -621,8 +621,6 @@ var addAuthorForm = {
numAuthors = $('.authorship').length; numAuthors = $('.authorship').length;
if (numAuthors > 0) { if (numAuthors > 0) {
// Reorder to remove any gaps // Reorder to remove any gaps
// RY if we do this based on js objects rather than rank stored in the DOM,
// this wouldn't depend on removing the author from the DOM.
addAuthorForm.reorderAuthors(); addAuthorForm.reorderAuthors();
// If less than two authors remaining, disable drag-drop // If less than two authors remaining, disable drag-drop