From a96e27d23fa7a54749e9eb4515f81f311805546d Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Fri, 13 Jul 2012 15:26:34 +0200 Subject: [PATCH 1/3] Bug 7455: Authority subfields are cloned in the wrong field --- cataloguing/additem.pl | 6 +- koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css | 10 +- koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js | 463 +++++++++++++++ .../prog/en/modules/authorities/authorities.tt | 618 +++++--------------- .../authorities/blinddetail-biblio-search.tt | 2 +- .../prog/en/modules/cataloguing/addbiblio.tt | 599 +++++-------------- .../prog/en/modules/cataloguing/additem.tt | 77 +-- .../prog/en/modules/serials/serials-edit.tt | 82 +-- .../prog/en/modules/tools/batchMod-edit.tt | 5 +- tools/batchMod.pl | 6 +- 10 files changed, 774 insertions(+), 1094 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 7b7dbac..79a717c 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -247,7 +247,7 @@ sub generate_subfield_form { my $change = index($javascript, 'function Change') > -1 ? "return Change$function_name($subfield_data{random}, '$subfield_data{id}');" : 'return 1;'; - $subfield_data{marc_value} = qq[ @@ -255,7 +255,7 @@ sub generate_subfield_form { $javascript]; } else { warn "Plugin Failed: $plugin"; - $subfield_data{marc_value} = ""; # supply default input form + $subfield_data{marc_value} = ""; # supply default input form } } elsif ( $tag eq '' ) { # it's an hidden field @@ -274,7 +274,7 @@ sub generate_subfield_form { $subfield_data{marc_value} = "\n"; } else { # it's a standard field - $subfield_data{marc_value} = ""; + $subfield_data{marc_value} = ""; } return \%subfield_data; diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css b/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css index d2489b3..d35a471 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/addbiblio.css @@ -50,8 +50,10 @@ div.tag { } div.subfield_line { - padding-bottom : .3em; - clear: both; + padding-bottom: .3em; + float: left; + clear: left; + width: 100%; } div.subfield_line label { @@ -63,6 +65,10 @@ div.subfield_line label { clear:left; } +.subfieldcode img { + cursor: pointer; +} + .tag_title { font-size : 90%; padding : .2em 0; diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js new file mode 100644 index 0000000..29ab1eb --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js @@ -0,0 +1,463 @@ +/* + * Unified file for catalogue edition + */ + +/* Functions developed for addbiblio.tt and authorities.tt */ + +// returns the fieldcode based upon tag div id +function getFieldCode(tagDivId){ + // format : tag__... + return tagDivId.substr(3+1,3); +} + +//returns the field and subfieldcode based upon subfield div id +function getFieldAndSubfieldCode(subfieldDivId){ + // format : subfield... + return subfieldDivId.substr(8,3+1); +} + +//returns the subfieldcode based upon subfieldid writing +function getSubfieldCode(tagsubfieldid){ + // 3 : tag +3 : tagnumber +4 : number of _ +8 subfield -1 begins at 0 + return tagsubfieldid.substr(3+3+4+8-1,1); +} + +// Take the base of tagsubfield information (removing the subfieldcodes and subfieldindexes) +// returns the filter +function getTagInputnameFilter(tagsubfieldid){ + var tagsubfield=tagsubfieldid.substr(0,tagsubfieldid.lastIndexOf("_")); + var tagcode=tagsubfield.substr(tagsubfield.lastIndexOf("_")); + tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_")); + tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_")); + tagsubfield=tagsubfield+"_."+tagcode; + return tagsubfield; +} + +function openAuth(tagsubfieldid,authtype) { + // let's take the base of tagsubfield information (removing the indexes and the codes + var element=document.getElementById(tagsubfieldid); + var tagsubfield=getTagInputnameFilter(tagsubfieldid); + var elementsubfcode=getSubfieldCode(element.name); + var mainmainstring=element.value; + var mainstring=""; + var inputs = element.parentNode.parentNode.getElementsByTagName("input"); + + for (var myindex =0; myindex + var divs = original.getElementsByTagName('div'); + for(var i=0,divslen = divs.length ; i show all subfields + divs[i].style.display = 'block'; + } else if (divs[i].style.display == 'none') { + // show + divs[i].style.display = 'block'; + } else { + // hide + divs[i].style.display = 'none'; + } + } + } +} +/** + * To clone a field + * @param hideMarc '0' for false, '1' for true + * @param advancedMARCEditor '0' for false, '1' for true + */ +function CloneField(index, hideMarc, advancedMARCEditor) { + var original = document.getElementById(index); //original
+ var clone = original.cloneNode(true); + var new_key = CreateKey(); + var new_id = original.getAttribute('id')+new_key; + + clone.setAttribute('id',new_id); // setting a new id for the parent div + + var divs = clone.getElementsByTagName('div'); + + if(hideMarc == '0') { + // No indicator if hide_marc + // setting a new name for the new indicator + for(var i=0; i < 2; i++) { + var indicator = clone.getElementsByTagName('input')[i]; + indicator.setAttribute('name',indicator.getAttribute('name')+new_key); + } + } + + // settings all subfields + for(var i=0,divslen = divs.length ; i + var clone = original.cloneNode(true); + var new_key = CreateKey(); + + // set the attribute for the new 'div' subfields + var inputs = clone.getElementsByTagName('input'); + var selects = clone.getElementsByTagName('select'); + var textareas = clone.getElementsByTagName('textarea'); + var linkid; + + // input + var id_input = ""; + for(var i=0,len=inputs.length; i 1) { + canUnclone = true; + } + } else { + // unclone a subfield, check if there will remain one subfield + var subfieldCode = getFieldAndSubfieldCode(index); + // subfield divs with id begining with original field and subfield field code + var cloneSubfields = $('.subfield_line[id^="subfield'+subfieldCode+'"]'); + if (cloneSubfields.length > 1) { + canUnclone = true; + } + } + if (canUnclone) { + // remove clone + original.parentNode.removeChild(original); + } else { + // 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(""); + } +} + +/** + * This function create a random number + */ +function CreateKey(){ + return parseInt(Math.random() * 100000); +} + +/** + * This function allows to move a subfield up by clickink on the 'up' button . + */ +function upSubfield(index) { + try{ + var line = document.getElementById(index); // get the line where the user has clicked. + } catch(e) { + return; // this line doesn't exist... + } + var tag = line.parentNode; // get the dad of this line. (should be "
") + + // getting all subfields for this tag + var subfields = tag.getElementsByTagName('div'); + var subfieldsLength = subfields.length; + + if(subfieldsLength<=1) return; // nothing to do if there is just one subfield. + + // among all subfields + for(var i=0;i + * @param original subfield div to clone + */ +function CloneItemSubfield(original){ + var clone = original.cloneNode(true); + var new_key = CreateKey(); + + // set the attribute for the new 'div' subfields + var inputs = clone.getElementsByTagName('input'); + var selects = clone.getElementsByTagName('select'); + var textareas = clone.getElementsByTagName('textarea'); + + // input (except hidden type) + var id_input = ""; + for(var i=0,len=inputs.length; iKoha › Authorities › [% IF ( authid ) %]Modify authority #[% authid %] ([% authtypetext %])[% ELSE %]Adding authority ([% authtypetext %])[% END %] [% INCLUDE 'doc-head-close.inc' %] + + @@ -657,6 +267,7 @@ function unHideSubfield(index,labelindex) { // FIXME :: is it used ? //]]> [% INCLUDE 'header.inc' %] +
@@ -802,83 +413,129 @@ function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
- + [% FOREACH BIG_LOO IN BIG_LOOP %] - -[% IF ( BIG_LOO.number ) %] -
-[% ELSE %]
-[% END %] - [% FOREACH innerloo IN BIG_LOO.innerloop %] - [% IF ( innerloo.tag ) %] -
+ [% IF ( innerloo.tag ) %] +
- [% UNLESS hide_marc %] - [% IF advancedMARCEditor %] - [% innerloo.tag %] - [% ELSE %] - [% innerloo.tag %] - [% IF marcflavour != 'NORMARC' %] ?[% END %] - - [% END %] + [% UNLESS hide_marc %] + [% IF advancedMARCEditor %] + [% innerloo.tag %] + [% ELSE %] + [% innerloo.tag %] + [% IF marcflavour != 'NORMARC' %] ?[% END %] + + [% END %] [% IF ( innerloo.fixedfield ) %] - - + + [% ELSE %] - - + + [% END %] - - [% ELSE %] + [% ELSE %] [% IF ( innerloo.fixedfield ) %] - - + + [% ELSE %] - - + + [% END %] - [% END %] + [% END %] [% UNLESS advancedMARCEditor %] - [% innerloo.tag_lib %] + [% innerloo.tag_lib %] [% END %] - [% IF ( innerloo.repeatable ) %] - Repeat this Tag - [% END %] - Delete this Tag - - + + [% IF ( innerloo.repeatable ) %] + + Repeat this Tag + + [% END %] + + Delete this Tag + + +
- + [% FOREACH subfield_loo IN innerloo.subfield_loop %] -
+
[% UNLESS advancedMARCEditor %] [% IF ( subfield_loo.fixedfield ) %]
- [% END %] -
- [% END %] - [% END %] +
-[% END %] -
+ [% END %] + [% END %] +
+[% END %] + +
+ @@ -914,6 +578,7 @@ function unHideSubfield(index,labelindex) { // FIXME :: is it used ? +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 05750b2..2c33df8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -1,6 +1,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Cataloging › [% title |html %] [% IF ( author ) %] by [% author %][% END %] (Record #[% biblionumber %]) › Items [% INCLUDE 'doc-head-close.inc' %] + + @@ -163,7 +164,9 @@ $(document).ready(function(){ [% IF ( ite.repeatable ) %] - + + + Clone + [% END %]
diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 3ba93a8..8391209 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -393,14 +393,14 @@ foreach my $tag (sort keys %{$tagslib}) { my $temp; my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data ); my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data ); - $subfield_data{marc_value} = qq[ ... $javascript]; } else { warn "Plugin Failed: $plugin"; - $subfield_data{marc_value} = ""; # supply default input form + $subfield_data{marc_value} = ""; # supply default input form } } elsif ( $tag eq '' ) { # it's an hidden field @@ -419,7 +419,7 @@ foreach my $tag (sort keys %{$tagslib}) { $subfield_data{marc_value} = "\n"; } else { # it's a standard field - $subfield_data{marc_value} = ""; + $subfield_data{marc_value} = ""; } # $subfield_data{marc_value}=""; push (@loop_data, \%subfield_data); -- 1.7.9.5