From 04eadcd5bcaf24ea660a29e031efa9431c9650a1 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Date: Fri, 2 May 2014 18:38:20 -0300 Subject: [PATCH] Bug 11638 - Remove HTML from addbiblio.pl This patch extracts variables with HTML from addbiblio.pl and an instance of CGI::scrolling_list As it changes how MARC editor show input fields, I prefer not add patches for other cases mentioned on Comment #1 To test: 1. Verify there are no regressions on MARC editor Add/Edit records, modify values About the error message on error when deleting biblio, it must be localized but the script is not trying to use a template file, only prints a basic html and aborts. Perhaps a way of handling errors more gracefully is needed, but again it need to be solved on it's own bug. --- cataloguing/addbiblio.pl | 168 +++++++++----------- .../prog/en/modules/cataloguing/addbiblio.tt | 28 +++- 2 files changed, 105 insertions(+), 91 deletions(-) diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 118bfc2..5b06706 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -239,18 +239,15 @@ sub build_authorized_values_list { } } $authorised_values_sth->finish; - return CGI::scrolling_list( - -name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, - -values => \@authorised_values, - -default => $value, - -labels => \%authorised_lib, - -override => 1, - -size => 1, - -multiple => 0, - -tabindex => 1, - -id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, - -class => "input_marceditor", - ); + return { + type => 'select', + id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + default => $value, + values => \@authorised_values, + labels => \%authorised_lib, + }; + } =head2 CreateKey @@ -366,37 +363,33 @@ sub create_input { defined($tagslib->{$tag}->{'a'}->{authtypecode}) and $tagslib->{$tag}->{'a'}->{authtypecode} ne '') { - $subfield_data{marc_value} = - "<input type=\"text\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - value=\"$value\" - class=\"input_marceditor readonly\" - tabindex=\"1\" - size=\"5\" - maxlength=\"".$subfield_data{maxlength}."\" - readonly=\"readonly\" - \/>"; + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 5, + maxlength => $subfield_data{maxlength}, + readonly => 1, + }; # it's a thesaurus / authority field } elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { # when authorities auto-creation is allowed, do not set readonly my $is_readonly = !C4::Context->preference("BiblioAddsAuthorities"); - $subfield_data{marc_value} = - "<input type=\"text\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - value=\"$value\" - class=\"input_marceditor readonly\" - tabindex=\"1\" - size=\"67\" - maxlength=\"".$subfield_data{maxlength}."\"". - ($is_readonly ? "readonly=\"readonly\"" : ""). - "\/> - <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot tag_editor\" - onclick=\"openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'".$tagslib->{$tag}->{$subfield}->{authtypecode}."','biblio'); return false;\" tabindex=\"1\" title=\"Tag editor\">Tag editor</a></span> - "; + + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + readonly => ($is_readonly) ? 1 : 0, + authtype => $tagslib->{$tag}->{$subfield}->{authtypecode}, + }; + # it's a plugin field } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) { @@ -413,46 +406,44 @@ sub create_input { my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop ); my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop ); - $subfield_data{marc_value} = - "<input tabindex=\"1\" - type=\"text\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - value=\"$value\" - class=\"input_marceditor\" - onfocus=\"Focus$function_name($index_tag)\" - size=\"67\" - maxlength=\"".$subfield_data{maxlength}."\" - onblur=\"Blur$function_name($index_tag); \" \/> - <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot tag_editor\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" tabindex=\"1\" title=\"Tag editor\">Tag editor</a></span> - $javascript"; + $subfield_data{marc_value} = { + type => 'text_complex', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + function_name => $function_name, + index_tag => $index_tag, + javascript => $javascript, + }; + } else { warn "Plugin Failed: $plugin"; # supply default input form - $subfield_data{marc_value} = - "<input type=\"text\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - value=\"$value\" - tabindex=\"1\" - size=\"67\" - maxlength=\"".$subfield_data{maxlength}."\" - class=\"input_marceditor\" - \/> - "; + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + readonly => 0, + }; + } # it's an hidden field } elsif ( $tag eq '' ) { - $subfield_data{marc_value} = - "<input tabindex=\"1\" - type=\"hidden\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - size=\"67\" - maxlength=\"".$subfield_data{maxlength}."\" - value=\"$value\" \/> - "; + $subfield_data{marc_value} = { + type => 'hidden', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + }; + } else { # it's a standard field @@ -466,28 +457,25 @@ sub create_input { && C4::Context->preference("marcflavour") eq "MARC21" ) ) { - $subfield_data{marc_value} = - "<textarea cols=\"70\" - rows=\"4\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - class=\"input_marceditor\" - tabindex=\"1\" - >$value</textarea> - "; + $subfield_data{marc_value} = { + type => 'textarea', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + }; + } else { - $subfield_data{marc_value} = - "<input type=\"text\" - id=\"".$subfield_data{id}."\" - name=\"".$subfield_data{id}."\" - value=\"$value\" - tabindex=\"1\" - size=\"67\" - maxlength=\"".$subfield_data{maxlength}."\" - class=\"input_marceditor\" - \/> - "; + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + readonly => 0, + }; + } } $subfield_data{'index_subfield'} = $index_subfield; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index f446d6e..73537f8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -610,7 +610,33 @@ function Changefwk(FwkList) { </label> [% END %] - [% subfield_loo.marc_value %] + [% SET val = subfield_loo.marc_value %] + [% IF ( val.type == 'text' ) %] + [% IF ( val.readonly == 1 ) %] + <input type="text" id="[%- val.id -%]" name="[%- val.name -%]" value="[%- val.value -%]" class="input_marceditor readonly" tabindex="1" size="[%- val.size -%]" maxlength="[%- val.maxlength -%]" readonly="readonly" /> + [% ELSE %] + <input type="text" id="[%- val.id -%]" name="[%- val.name -%]" value="[%- val.value -%]" class="input_marceditor" tabindex="1" size="[%- val.size -%]" maxlength="[%- val.maxlength -%]" /> + [% END %] + [% IF ( val.authtype ) %] + <span class="subfield_controls"><a href="#" class="buttonDot tag_editor" onclick="openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'[%- val.authtype -%]','biblio'); return false;" tabindex="1" title="Tag editor">Tag editor</a></span> + [% END %] + [% ELSIF ( val.type == 'text_complex' ) %] + <input type="text" id="[%- val.id -%]" name="[%- val.name -%]" value="[%- val.value -%]" class="input_marceditor" tabindex="1" size="[%- val.size -%]" maxlength="[%- val.maxlength -%]" onfocus="Focus[%- val.function_name -%]([%- val.index_tag -%])" onblur="Blur[%- val.function_name -%]([%- val.index_tag -%])" /><span class="subfield_controls"><a href="#" class="buttonDot tag_editor" onclick="Clic[%- val.function_name -%]('[%- val.id -%]'); return false;" tabindex="1" title="Tag editor">Tag editor</a></span>[% val.javascript %] + [% ELSIF ( val.type == 'hidden' ) %] + <input tabindex="1" type="hidden" id="[%- val.id -%]" name="[%- val.name -%]" size="[%- val.size -%]" maxlength="[%- val.maxlength -%]" value="[%- val.value -%]" /> + [% ELSIF ( val.type == 'textarea' ) %] + <textarea cols="70" rows="4" id="[%- val.id -%]" name="[%- val.name -%]" class="input_marceditor" tabindex="1">[%- val.value -%]</textarea> + [% ELSIF ( val.type == 'select' ) %] + <select name="[%- val.name -%]" tabindex="1" size="1" class="input_marceditor" id="[%- val.id -%]"> + [% FOREACH aval IN val.values %] + [% IF aval == val.default %] + <option value="[%- aval -%]" selected="selected">[%- val.labels.$aval -%]</option> + [% ELSE %] + <option value="[%- aval -%]">[%- val.labels.$aval -%]</option> + [% END %] + [% END %] + </select> + [% END %] <span class="subfield_controls"> [% IF ( subfield_loo.repeatable ) %] -- 1.7.9.5