Bug 4867 - cannot clone subfields in marc editor, other clone/unclone weirdness

When the clone/unclone plus/minus were replaced with images the <span> tags were inadvertantly deleted
causing the js to loose its ability to identify the clone/unclone links and properly udpate the indexes.
The resulting incorrect indexes caused various weirdnesses to result when one attempted to clone/unclone
subfields.

This patch simply adds classes to the two links and updates the js to identify the links based on class.

Thanks to owen for his help in chasing this down.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
This commit is contained in:
Chris Nighswonger 2010-09-14 11:02:42 -04:00 committed by Galen Charlton
parent dfaa0e9d35
commit d8f16da180
1 changed files with 16 additions and 16 deletions

View File

@ -324,12 +324,12 @@ function CloneField(index) {
// setting its '+' and '-' buttons
try {
var spans = divs[i].getElementsByTagName('span');
for (var j = 0; j < spans.length; j++) {
if(spans[j].getAttribute('class') == 'buttonPlus'){
spans[j].setAttribute('onclick',"CloneSubfield('" + divs[i].getAttribute('id') + "')");
} else if (spans[j].getAttribute('class') == 'buttonMinus') {
spans[j].setAttribute('onclick',"UnCloneField('" + divs[i].getAttribute('id') + "')");
var anchors = divs[i].getElementsByTagName('a');
for (var j = 0; j < anchors.length; j++) {
if(anchors[j].getAttribute('class') == 'buttonPlus'){
anchors[j].setAttribute('onclick',"CloneSubfield('" + divs[i].getAttribute('id') + "')");
} else if (anchors[j].getAttribute('class') == 'buttonMinus') {
anchors[j].setAttribute('onclick',"UnCloneField('" + divs[i].getAttribute('id') + "')");
}
}
}
@ -479,19 +479,19 @@ function CloneSubfield(index){
label.setAttribute('for',id_input);
<!-- /TMPL_UNLESS -->
// setting a new if for the parent div
// setting a new id for the parent div
clone.setAttribute('id',new_id);
try {
var buttonUp = clone.getElementsByTagName('img')[0];
buttonUp.setAttribute('onclick',"upSubfield('" + new_id + "')");
var spans = clone.getElementsByTagName('span');
if(spans.length){
for(var i = 0 ,lenspans = spans.length ; i < lenspans ; i++){
if(spans[i].getAttribute('class') == 'buttonPlus'){
spans[i].setAttribute('onclick',"CloneSubfield('" + new_id + "')");
} else if (spans[i].getAttribute('class') == 'buttonMinus') {
spans[i].setAttribute('onclick',"UnCloneField('" + new_id + "')");
var anchors = clone.getElementsByTagName('a');
if(anchors.length){
for(var i = 0 ,lenanchors = anchors.length ; i < lenanchors ; i++){
if(anchors[i].getAttribute('class') == 'buttonPlus'){
anchors[i].setAttribute('onclick',"CloneSubfield('" + new_id + "')");
} else if (anchors[i].getAttribute('class') == 'buttonMinus') {
anchors[i].setAttribute('onclick',"UnCloneField('" + new_id + "')");
}
}
}
@ -810,8 +810,8 @@ function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
<!-- TMPL_VAR NAME="marc_value" -->
<!-- TMPL_IF NAME="repeatable" -->
<span class="subfield_controls"><a href="#" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/clone-subfield.png" alt="Clone" title="Clone this subfield" /></a>
<a href="#" onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/delete-subfield.png" alt="Delete" title="Delete this subfield" /></a></span>
<span class="subfield_controls"><a href="#" class="buttonPlus" tabindex="1" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/clone-subfield.png" alt="Clone" title="Clone this subfield" /></a>
<a href="#" class="buttonMinus" tabindex="1" onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/delete-subfield.png" alt="Delete" title="Delete this subfield" /></a></span>
<!-- /TMPL_IF -->