From: Galen Charlton <[EMAIL PROTECTED]>
A button to delete (non-mandatory) subfields and fields
is added to the bib and authority MARC editors. This button,
which displays as a hypen or minus sign after the plus sign
to clone a field, acts as follows:
[1] When deleting a whole MARC field, if at least
one other repeat of that field exists, deletes
the field from the editor page. If the field
to be deleted is the last instance of that tag,
the contents of the field are cleared, not removed.
This allows one to delete all 650 tags, then
add a new one without having to reload the
record in the editor.
[2] When deleting a subfield, if at least one other
repeat of that subfield and its tag occurs
*anywhere else in the record, not necessarily in the same tag*,
deletes the subfield.
Otherwise, if the subfield is the last occurrence
of that tag/subfield combination, clears the input
form instead.
Documentation note: new screenshots for MARC editor, plus
description of the '-' button.
Credit to MJ Ray for introducing the '-' button
and the UnCloneField JavaScript function.
Signed-off-by: Andrew Moore <[EMAIL PROTECTED]>
---
authorities/authorities.pl | 2 +
cataloguing/addbiblio.pl | 2 +
koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css | 7 ++-
.../prog/en/modules/authorities/authorities.tmpl | 94 ++++++++++++++++---
.../prog/en/modules/cataloguing/addbiblio.tmpl | 95 ++++++++++++++++---
5 files changed, 170 insertions(+), 30 deletions(-)
diff --git a/authorities/authorities.pl b/authorities/authorities.pl
index cd2a280..26da895 100755
--- a/authorities/authorities.pl
+++ b/authorities/authorities.pl
@@ -426,6 +426,7 @@ sub build_tabs ($$$$$) {
index => $index_tag,
tag_lib => $tagslib->{$tag}->{lib},
repeatable => $tagslib->{$tag}->{repeatable},
+ mandatory => $tagslib->{$tag}->{mandatory},
subfield_loop => [EMAIL PROTECTED],
fixedfield => ($tag < 10)?(1):(0),
random => CreateKey,
@@ -462,6 +463,7 @@ sub build_tabs ($$$$$) {
index => $index_tag,
tag_lib => $tagslib->{$tag}->{lib},
repeatable => $tagslib->{$tag}->{repeatable},
+ mandatory => $tagslib->{$tag}->{mandatory},
indicator1 => $indicator1,
indicator2 => $indicator2,
subfield_loop => [EMAIL PROTECTED],
diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index b27b6fa..7713113 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -657,6 +657,7 @@ sub build_tabs ($$$$$) {
index => $index_tag,
tag_lib => $tagslib->{$tag}->{lib},
repeatable => $tagslib->{$tag}->{repeatable},
+ mandatory => $tagslib->{$tag}->{mandatory},
subfield_loop => [EMAIL PROTECTED],
fixedfield => $tag < 10?1:0,
random => CreateKey,
@@ -702,6 +703,7 @@ sub build_tabs ($$$$$) {
index => $index_tag,
tag_lib => $tagslib->{$tag}->{lib},
repeatable => $tagslib->{$tag}->{repeatable},
+ mandatory => $tagslib->{$tag}->{mandatory},
indicator1 => $indicator1,
indicator2 => $indicator2,
subfield_loop => [EMAIL PROTECTED],
diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css
b/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css
index 9d8f946..a102467 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css
+++ b/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css
@@ -6,7 +6,12 @@
float : left;
}
-a.buttonPlus {
+.buttonPlus {
+ font-weight : bold;
+ text-decoration : none;
+}
+
+.buttonMinus {
font-weight : bold;
text-decoration : none;
}
diff --git
a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tmpl
b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tmpl
index d6b13a9..c8cf89b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tmpl
@@ -6,8 +6,25 @@
<script type="text/javascript">
//<![CDATA[
+ var fields_in_use = {};
$(document).ready(function() {
$('#authoritytabs > ul').tabs();
+ $('.tag').each(function() {
+ var field_id = this.getAttribute('id').substring(0, 7);
+ if (field_id in fields_in_use) {
+ fields_in_use[field_id]++;
+ } else {
+ fields_in_use[field_id] = 1;
+ }
+ });
+ $('.subfield_line').each(function() {
+ var field_id = this.getAttribute('id').substring(0, 12);
+ if (field_id in fields_in_use) {
+ fields_in_use[field_id]++;
+ } else {
+ fields_in_use[field_id] = 1;
+ }
+ });
$("#f").submit(function(){
return $(this).Check();
});
@@ -90,6 +107,7 @@ function ExpandField(index) {
*/
function CloneField(index) {
var original = document.getElementById(index); //original <div>
+ fields_in_use[index.substr(0, 7)]++;
var clone = original.cloneNode(true);
var new_key = CreateKey();
var new_id = original.getAttribute('id')+new_key;
@@ -149,14 +167,15 @@ function CloneField(index) {
imgs[0].setAttribute('onclick',"upSubfield(\'"+divs[i].getAttribute('id')+"\');");
<!-- /TMPL_UNLESS -->
- // setting its '+' button
- var CloneButtonPlus=0;
+ // setting its '+' and '-' buttons
try {
- CloneButtonPlus = divs[i].getElementsByTagName('span')[0];
- if(CloneButtonPlus.getAttribute('class') == 'buttonPlus'){
- CloneButtonPlus.setAttribute('onclick',"CloneSubfield('" +
divs[i].getAttribute('id') + "')");
- } else {
- CloneButtonPlus = 0;
+ 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') + "')");
+ }
}
}
catch(e){
@@ -222,8 +241,14 @@ function CloneField(index) {
var CloneButtonPlus;
try {
- CloneButtonPlus = divs[i].getElementsByTagName('span')[1];
// 0 is the title
- CloneButtonPlus.setAttribute('onclick',"CloneField('" +
divs[i].parentNode.getAttribute('id') + "')");
+ var anchors = divs[i].getElementsByTagName('span');
+ for (var j = 0; j < anchors.length; j++) {
+ if (anchors[j].getAttribute('class') == 'buttonPlus') {
+ anchors[j].setAttribute('onclick',"CloneField('" +
new_id + "')");
+ } else if (anchors[j].getAttribute('class') ==
'buttonMinus') {
+ anchors[j].setAttribute('onclick',"UnCloneField('"
+ new_id + "')");
+ }
+ }
}
catch(e){
// do nothig CloneButtonPlus doesn't exist.
@@ -249,6 +274,7 @@ function CloneField(index) {
function CloneSubfield(index){
var original = document.getElementById(index); //original <div>
+ fields_in_use[index.substr(0, 12)]++;
var clone = original.cloneNode(true);
var new_key = CreateKey();
var new_id = original.getAttribute('id')+new_key;
@@ -289,16 +315,16 @@ function CloneSubfield(index){
// setting a new if for the parent div
clone.setAttribute('id',new_id);
- var CloneButtonPlus;
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'){
- CloneButtonPlus = spans[i];
- CloneButtonPlus.setAttribute('onclick',"CloneSubfield('" +
new_id + "')");
- var buttonUp = clone.getElementsByTagName('img')[0];
- buttonUp.setAttribute('onclick',"upSubfield('" + new_id +
"')");
+ spans[i].setAttribute('onclick',"CloneSubfield('" + new_id
+ "')");
+ } else if (spans[i].getAttribute('class') == 'buttonMinus') {
+ spans[i].setAttribute('onclick',"UnCloneField('" + new_id
+ "')");
}
}
}
@@ -310,6 +336,40 @@ function CloneSubfield(index){
original.parentNode.insertBefore(clone,original.nextSibling);
}
+ /**
+ * This function removes or clears unwanted subfields
+ */
+function UnCloneField(index) {
+ var original = document.getElementById(index);
+ var field_id;
+ if (index.match("tag")) {
+ field_id = index.substr(0, 7);
+ } else {
+ field_id = index.substr(0, 12);
+ }
+ if (1 == fields_in_use[field_id]) {
+ // clear inputs, but don't delete
+ $(":input.input_marceditor", original).each(function(){
+ // thanks to
http://www.learningjquery.com/2007/08/clearing-form-data for
+ // hint about clearing selects correctly
+ var type = this.type;
+ var tag = this.tagName.toLowerCase();
+ if (type == 'text' || type == 'password' || tag == 'textarea') {
+ this.value = "";
+ } else if (type == 'checkbox' || type == 'radio') {
+ this.checked = false;
+ } else if (tag == 'select') {
+ this.selectedIndex = -1;
+ }
+ });
+ $(":input.indicator", original).val("");
+ } else {
+ original.parentNode.removeChild(original);
+ fields_in_use[field_id]--;
+ }
+}
+
+
/**
* This function create a random number
*/
@@ -531,6 +591,9 @@ function searchauthority() {
<!-- TMPL_IF name="repeatable" -->
<span class="buttonPlus" onclick="CloneField('tag_<!--
TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random"
-->')">+</span>
<!-- /TMPL_IF -->
+ <!-- TMPL_UNLESS NAME="mandatory" -->
+ <span class="buttonMinus" onclick="UnCloneField('tag_<!--
TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random"
-->')">−</span>
+ <!-- /TMPL_UNLESS -->
</div>
@@ -575,6 +638,9 @@ function searchauthority() {
<!-- TMPL_IF NAME="repeatable" -->
<span class="buttonPlus"
onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR
NAME='subfield' -->')">+</span>
<!-- /TMPL_IF -->
+ <!-- TMPL_UNLESS NAME="mandatory" -->
+ <span class="buttonMinus"
onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR
NAME='subfield' --><!-- TMPL_VAR name="random" -->')">−</span>
+ <!-- /TMPL_UNLESS -->
</div>
<!-- End of the line -->
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tmpl
b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tmpl
index b5647d8..f5fa3a5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tmpl
@@ -5,10 +5,27 @@
<script type="text/javascript">
//<![CDATA[
+ var fields_in_use = {};
$(document).ready(function() {
$('#addbibliotabs > ul').tabs().bind('show.ui-tabs',
function(e, ui) {
$("#"+ui.panel.id+" input:eq(0)").focus();
});
+ $('.tag').each(function() {
+ var field_id = this.getAttribute('id').substring(0, 7);
+ if (field_id in fields_in_use) {
+ fields_in_use[field_id]++;
+ } else {
+ fields_in_use[field_id] = 1;
+ }
+ });
+ $('.subfield_line').each(function() {
+ var field_id = this.getAttribute('id').substring(0, 12);
+ if (field_id in fields_in_use) {
+ fields_in_use[field_id]++;
+ } else {
+ fields_in_use[field_id] = 1;
+ }
+ });
});
$('#header_search > ul').tabs().bind('show.ui-tabs', function(e, ui) {
$('#header_search > div:not(.ui-tabs-hide)').find('input').eq(0).focus(); });
@@ -145,10 +162,11 @@ function ExpandField(index) {
}
/**
- * To clone a field or a subfield by clickink on '+' button
+ * To clone a field or a subfield by clicking on '+' button
*/
function CloneField(index) {
var original = document.getElementById(index); //original <div>
+ fields_in_use[index.substr(0, 7)]++;
var clone = original.cloneNode(true);
var new_key = CreateKey();
var new_id = original.getAttribute('id')+new_key;
@@ -208,14 +226,15 @@ function CloneField(index) {
imgs[0].setAttribute('onclick',"upSubfield(\'"+divs[i].getAttribute('id')+"\');");
<!-- /TMPL_UNLESS -->
- // setting its '+' button
- var CloneButtonPlus=0;
+ // setting its '+' and '-' buttons
try {
- CloneButtonPlus = divs[i].getElementsByTagName('span')[0];
- if(CloneButtonPlus.getAttribute('class') == 'buttonPlus'){
- CloneButtonPlus.setAttribute('onclick',"CloneSubfield('" +
divs[i].getAttribute('id') + "')");
- } else {
- CloneButtonPlus = 0;
+ 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') + "')");
+ }
}
}
catch(e){
@@ -280,8 +299,14 @@ function CloneField(index) {
var CloneButtonPlus;
try {
- CloneButtonPlus = divs[i].getElementsByTagName('span')[1];
// 0 is the title
- CloneButtonPlus.setAttribute('onclick',"CloneField('" +
divs[i].parentNode.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',"CloneField('" +
new_id + "')");
+ } else if (anchors[j].getAttribute('class') ==
'buttonMinus') {
+ anchors[j].setAttribute('onclick',"UnCloneField('"
+ new_id + "')");
+ }
+ }
}
catch(e){
// do nothig CloneButtonPlus doesn't exist.
@@ -306,6 +331,7 @@ function CloneField(index) {
function CloneSubfield(index){
var original = document.getElementById(index); //original <div>
+ fields_in_use[index.substr(0, 12)]++;
var clone = original.cloneNode(true);
var new_key = CreateKey();
var new_id = original.getAttribute('id')+new_key;
@@ -346,16 +372,16 @@ function CloneSubfield(index){
// setting a new if for the parent div
clone.setAttribute('id',new_id);
- var CloneButtonPlus;
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'){
- CloneButtonPlus = spans[i];
- CloneButtonPlus.setAttribute('onclick',"CloneSubfield('" +
new_id + "')");
- var buttonUp = clone.getElementsByTagName('img')[0];
- buttonUp.setAttribute('onclick',"upSubfield('" + new_id +
"')");
+ spans[i].setAttribute('onclick',"CloneSubfield('" + new_id
+ "')");
+ } else if (spans[i].getAttribute('class') == 'buttonMinus') {
+ spans[i].setAttribute('onclick',"UnCloneField('" + new_id
+ "')");
}
}
}
@@ -367,6 +393,39 @@ function CloneSubfield(index){
original.parentNode.insertBefore(clone,original.nextSibling);
}
+ /**
+ * This function removes or clears unwanted subfields
+ */
+function UnCloneField(index) {
+ var original = document.getElementById(index);
+ var field_id;
+ if (index.match("tag")) {
+ field_id = index.substr(0, 7);
+ } else {
+ field_id = index.substr(0, 12);
+ }
+ if (1 == fields_in_use[field_id]) {
+ // clear inputs, but don't delete
+ $(":input.input_marceditor", original).each(function(){
+ // thanks to
http://www.learningjquery.com/2007/08/clearing-form-data for
+ // hint about clearing selects correctly
+ var type = this.type;
+ var tag = this.tagName.toLowerCase();
+ if (type == 'text' || type == 'password' || tag == 'textarea') {
+ this.value = "";
+ } else if (type == 'checkbox' || type == 'radio') {
+ this.checked = false;
+ } else if (tag == 'select') {
+ this.selectedIndex = -1;
+ }
+ });
+ $(":input.indicator", original).val("");
+ } else {
+ original.parentNode.removeChild(original);
+ fields_in_use[field_id]--;
+ }
+}
+
/**
* This function create a random number
*/
@@ -572,6 +631,9 @@ function unHideSubfield(index,labelindex) { // FIXME :: is
it used ?
<!-- TMPL_IF name="repeatable" -->
<a href="#" class="buttonPlus" onclick="CloneField('tag_<!--
TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random"
-->'); return false;" title="Repeat this Tag">+</a>
<!-- /TMPL_IF -->
+ <!-- TMPL_UNLESS name="mandatory" -->
+ <a href="#" class="buttonMinus"
onclick="UnCloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR
NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Delete
this Tag">−</a>
+ <!-- /TMPL_UNLESS -->
</div>
@@ -608,6 +670,9 @@ function unHideSubfield(index,labelindex) { // FIXME :: is
it used ?
<!-- TMPL_IF NAME="repeatable" -->
<span class="buttonPlus"
onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR
NAME='subfield' --><!-- TMPL_VAR name="random" -->')">+</span>
<!-- /TMPL_IF -->
+ <!-- TMPL_UNLESS NAME="mandatory" -->
+ <span class="buttonMinus"
onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR
NAME='subfield' --><!-- TMPL_VAR name="random" -->')">−</span>
+ <!-- /TMPL_UNLESS -->
</div>
<!-- End of the line -->
--
1.5.6
_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches