From 074a857a5e09bd3d7d4b448ebc15f9b6dd54664c Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Sat, 3 May 2014 00:21:48 -0300 Subject: [PATCH] Bug 12176 - Remove HTML from additem.pl This patch removes HTML code from additem.pl To test: 1. Chech no regressions on Add/Edit/Save items 2. Update translation files for a language, check new string "Tag editor" on staff PO file 3. Check it pass xt/tt_valid.t Rebased Signed-off-by: Chris Cormack Signed-off-by: Jonathan Druart --- cataloguing/additem.pl | 91 +++++++++++++++------- .../prog/en/modules/cataloguing/additem.tt | 27 ++++++- 2 files changed, 87 insertions(+), 31 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index f379108..f465f4f 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -154,9 +154,6 @@ sub generate_subfield_form { my $input = new CGI; $value = $input->param('barcode'); } - my $attributes_no_value = qq(id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$subfield_data{maxlength}" ); - my $attributes_no_value_textarea = qq(id="$subfield_data{id}" name="field_value" class="input_marceditor" rows="5" cols="64" ); - my $attributes = qq($attributes_no_value value="$value" ); if ( $subfieldlib->{authorised_value} ) { my @authorised_values; @@ -213,29 +210,35 @@ sub generate_subfield_form { } if ($subfieldlib->{'hidden'}) { - $subfield_data{marc_value} = qq( $authorised_lib{$value}); + $subfield_data{marc_value} = { + type => 'hidden', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + avalue => $authorised_lib{$value}, + }; } else { - $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list - -name => "field_value", - -values => \@authorised_values, - -default => $value, - -labels => \%authorised_lib, - -override => 1, - -size => 1, - -multiple => 0, - -id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield, - -class => "input_marceditor", - ); + $subfield_data{marc_value} = { + type => 'select', + id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield, + name => "field_value", + values => \@authorised_values, + labels => \%authorised_lib, + default => $value, + }; } } # it's a thesaurus / authority field elsif ( $subfieldlib->{authtypecode} ) { - $subfield_data{marc_value} = " - {authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">... - "; + $subfield_data{marc_value} = { + type => 'text1', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + authtypecode => $subfieldlib->{authtypecode}, + }; } # it's a plugin field elsif ( $subfieldlib->{value_builder} ) { @@ -247,22 +250,41 @@ 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[ - ... - $javascript]; + $subfield_data{marc_value} = { + type => 'text2', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + function => $function_name, + data_random => $subfield_data{random}, + change => $change, + javascript => $javascript, + }; } else { warn "Plugin Failed: $plugin"; - $subfield_data{marc_value} = ""; # supply default input form + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + }; # supply default input form } } elsif ( $tag eq '' ) { # it's an hidden field - $subfield_data{marc_value} = qq(); + $subfield_data{marc_value} = { + type => 'hidden', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + }; } elsif ( $subfieldlib->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ? - $subfield_data{marc_value} = qq(); + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + }; } elsif ( length($value) > 100 or (C4::Context->preference("marcflavour") eq "UNIMARC" and @@ -271,10 +293,19 @@ sub generate_subfield_form { 500 <= $tag && $tag < 600 ) ) { # oversize field (textarea) - $subfield_data{marc_value} = "\n"; + $subfield_data{marc_value} = { + type => 'textarea', + id => $subfield_data{id}, + value => $value, + }; } else { # it's a standard field - $subfield_data{marc_value} = ""; + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + maxlength => $subfield_data{max_length}, + value => $value, + }; } return \%subfield_data; 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 85a4486..1111f14 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -212,7 +212,32 @@ $(document).ready(function() { [% ELSE %] [% END %] - [% ite.marc_value %] + + [% SET mv = ite.marc_value %] + [% IF ( mv.type == 'hidden' ) %] + [% mv.avalue %] + [% ELSIF ( mv.type == 'select' ) %] + + [% ELSIF ( mv.type == 'text1' ) %] + + ... + [% ELSIF ( mv.type == 'text2' ) %] + + ...[% mv.javascript %] + [% ELSIF ( mv.type == 'text' ) %] + + [% ELSIF ( mv.type == 'textarea' ) %] + + [% END %] + -- 2.0.0.rc2