From 8bdc7f83acaf471ac9e14c7c0a74e3a4d9a575ee Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Thu, 18 Oct 2007 05:08:17 -0500 Subject: [PATCH] bug Fixing bugs.koha.org 1479 Porting userinterface improvements from biblios to items. I have to port that also into serialsadditems. Maybe there could be a way to have only one place for MARCinput management. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- cataloguing/additem.pl | 235 ++++++++++++++---- .../prog/en/modules/cataloguing/additem.tmpl | 81 +++++- 2 files changed, 263 insertions(+), 53 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 929b07f167..97acca3560 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -25,6 +25,7 @@ use C4::Output; use C4::Biblio; use C4::Context; use C4::Koha; # XXX subfield_is_koha_internal_p +use Date::Calc qw(Today); use MARC::File::XML; @@ -241,16 +242,35 @@ foreach my $tag (sort keys %{$tagslib}) { next if subfield_is_koha_internal_p($subfield); next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); my %subfield_data; + + my $index_subfield= int(rand(1000000)); + if($subfield eq '@'){ + $subfield_data{id} = "tag_".$tag."_subfield_0_".$index_subfield; + } else { + $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield; + } $subfield_data{tag}=$tag; $subfield_data{subfield}=$subfield; + $subfield_data{random}=int(rand(1000000)); # $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; $subfield_data{marc_lib}="{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}.""; $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; - $subfield_data{hidden}= "display:none" if $tagslib->{$tag}->{$subfield}->{hidden}; my ($x,$value); ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord); $value =~ s/"/"/g; + unless ($value) { + $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; + + # get today date & replace YYYY, MM, DD if provided in the default value + my ( $year, $month, $day ) = Today(); + $month = sprintf( "%02d", $month ); + $day = sprintf( "%02d", $day ); + $value =~ s/YYYY/$year/g; + $value =~ s/MM/$month/g; + $value =~ s/DD/$day/g; + } + $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne ''); #testing branch value if IndependantBranches. my $test = (C4::Context->preference("IndependantBranches")) && ($tag eq $branchtagfield) && ($subfield eq $branchtagsubfield) && @@ -268,66 +288,179 @@ foreach my $tag (sort keys %{$tagslib}) { $value=~s/^\s+|\s+$//g; } } - if ($tagslib->{$tag}->{$subfield}->{authorised_value}) { + if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { my @authorised_values; my %authorised_lib; + my $dbh=C4::Context->dbh; + # builds list, depending on authorised value... + #---- branch - if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { - if ((C4::Context->preference("IndependantBranches")) && (C4::Context->userenv->{flags} != 1)){ - my $sth=$dbh->prepare("select branchcode,branchname from branches where branchcode = ? order by branchname"); - $sth->execute(C4::Context->userenv->{branch}); - push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - while (my ($branchcode,$branchname) = $sth->fetchrow_array) { + if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { + my $sth = + $dbh->prepare( + "select branchcode,branchname from branches order by branchname"); + $sth->execute; + push @authorised_values, "" + unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + + while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) { push @authorised_values, $branchcode; - $authorised_lib{$branchcode}=$branchname; + $authorised_lib{$branchcode} = $branchname; } - } else { - my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname"); + + #----- itemtypes + } + elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { + my $sth = + $dbh->prepare( + "select itemtype,description from itemtypes order by description"); $sth->execute; - push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - while (my ($branchcode,$branchname) = $sth->fetchrow_array) { - push @authorised_values, $branchcode; - $authorised_lib{$branchcode}=$branchname; + push @authorised_values, "" + unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + + my $itemtype; + + while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) { + push @authorised_values, $itemtype; + $authorised_lib{$itemtype} = $description; } - } - #----- itemtypes - } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") { - my $sth=$dbh->prepare("select itemtype,description from itemtypes order by description"); - $sth->execute; - push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - while (my ($itemtype,$description) = $sth->fetchrow_array) { - push @authorised_values, $itemtype; - $authorised_lib{$itemtype}=$description; - } - #---- "true" authorised value - } else { - $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value}); - push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - while (my ($authvalue,$lib) = $authorised_values_sth->fetchrow_array) { - push @authorised_values, $authvalue; - $authorised_lib{$authvalue}=$lib; + $value = $itemtype unless ($value); + + #---- "true" authorised value + } + else { + $authorised_values_sth->execute( + $tagslib->{$tag}->{$subfield}->{authorised_value} ); + + push @authorised_values, "" + unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + + while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { + push @authorised_values, $value; + $authorised_lib{$value} = $lib; } } - $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value', - -values=> \@authorised_values, - -default=>"$value", - -labels => \%authorised_lib, - -size=>1, - -tabindex=>'', - -multiple=>0, - ); - } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) { - $subfield_data{marc_value}=" {$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">..."; - #" - } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) { - my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'}; - require $plugin; - my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,0); - my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0); - $subfield_data{marc_value}=" ... $javascript"; - } else { - $subfield_data{marc_value}=""; + $subfield_data{marc_value} =CGI::scrolling_list( + -name => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, + -values => \@authorised_values, + -default => $value, + -labels => \%authorised_lib, + -override => 1, + -size => 1, + -multiple => 0, + -tabindex => 1, + -id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, + -class => "input_marceditor", + ); + # it's a thesaurus / authority field + } + elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { + $subfield_data{marc_value} = + " + {$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">... + "; + # it's a plugin field + } + elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) { + + # opening plugin. Just check wether we are on a developper computer on a production one + # (the cgidir differs) + my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder"; + unless ( opendir( DIR, "$cgidir" ) ) { + $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder"; + } + my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'}; + do $plugin || die "Plugin Failed: ".$plugin; + 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 ); +# my ( $function_name, $javascript,$extended_param ); + + $subfield_data{marc_value} = + " + ... + $javascript"; + # it's an hidden field + } + elsif ( $tag eq '' ) { + $subfield_data{marc_value} = + " + "; + } + elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { + $subfield_data{marc_value} = + ""; + + # it's a standard field + } + else { + if ( + length($value) > 100 + or + ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300 + and $tag < 400 && $subfield eq 'a' ) + or ( $tag >= 500 + and $tag < 600 + && C4::Context->preference("marcflavour") eq "MARC21" ) + ) + { + $subfield_data{marc_value} = + " + "; + } + else { + $subfield_data{marc_value} = + " + "; + } } # $subfield_data{marc_value}=""; push(@loop_data, \%subfield_data); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl index 4f0409d296..8dceafdbbd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl @@ -51,6 +51,78 @@ function confirm_deletion(biblionumber,itemnumber) { window.location = "additem.pl?op=delitem&biblionumber="+biblionumber+"&itemnumber="+itemnumber; } } + +function CloneSubfield(index){ + var original = document.getElementById(index); //original
+ var clone = original.cloneNode(true); + var new_key = CreateKey(); + var new_id = original.getAttribute('id')+new_key; + + // set the attribute for the new 'div' subfields + var inputs = clone.getElementsByTagName('input'); + var selects = clone.getElementsByTagName('select'); + var textareas = clone.getElementsByTagName('textarea'); + + // input + var id_input = ""; + for(var i=0,len=inputs.length; i + // when cloning a subfield, reset its label too. + var label = clone.getElementsByTagName('label')[0]; + label.setAttribute('for',id_input); + + + // setting a new if for the parent div + clone.setAttribute('id',new_id); + + var CloneButtonPlus; + try { + 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 + "')"); + } + } + } + } + catch(e){ + // do nothig if ButtonPlus & CloneButtonPlus don't exist. + } + // insert this line on the page + original.parentNode.insertBefore(clone,original.nextSibling); +} + +/** + * This function create a random number + */ +function CreateKey(){ + return parseInt(Math.random() * 100000); +} + + //]]> @@ -99,13 +171,18 @@ function confirm_deletion(biblionumber,itemnumber) {

Edit Item

-

+

"> + " /> " /> " /> -

+ + ')">+ + + +
" /> -- 2.39.5