From e0900c89f30e6a0ebe9c9152cabbe4410e5b3c31 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 10 Nov 2021 14:41:57 +0100 Subject: [PATCH] Benutzerdef. Var. als HTML-Feld: allgemeine Infrastruktur --- SL/CVar.pm | 10 ++++++---- SL/Controller/CustomVariableConfig.pm | 3 ++- SL/DB/CustomVariable.pm | 6 +++--- SL/DB/CustomVariableConfig.pm | 1 + templates/webpages/amcvar/render_inputs.html | 3 +++ templates/webpages/amcvar/render_inputs_block.html | 4 ++++ templates/webpages/common/render_cvar_input.html | 2 ++ 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/SL/CVar.pm b/SL/CVar.pm index a905edee7..637f129c8 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -10,6 +10,7 @@ use Data::Dumper; use SL::DBUtils; use SL::MoreCommon qw(listify); +use SL::Presenter::Text; use SL::Util qw(trim); use SL::DB; @@ -46,7 +47,7 @@ SQL } elsif ($config->{type} eq 'number') { $config->{precision} = $1 if ($config->{options} =~ m/precision=(\d+)/i); - } elsif ($config->{type} eq 'textfield') { + } elsif ($config->{type} =~ m{^(?:html|text)field$}) { $config->{width} = 30; $config->{height} = 5; $config->{width} = $1 if ($config->{options} =~ m/width=(\d+)/i); @@ -112,7 +113,7 @@ sub get_custom_variables { my $custom_variables = $self->get_configs(module => $params{module}); foreach my $cvar (@{ $custom_variables }) { - if ($cvar->{type} eq 'textfield') { + if ($cvar->{type} =~ m{^(?:html|text)field}) { $cvar->{width} = 30; $cvar->{height} = 5; @@ -271,7 +272,7 @@ sub _save_custom_variables { my $value = $params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}"}; - if (($config->{type} eq 'text') || ($config->{type} eq 'textfield') || ($config->{type} eq 'select')) { + if (any { $config->{type} eq $_ } qw(text textfield htmlfield select)) { push @values, undef, undef, $value, undef; } elsif (($config->{type} eq 'date') || ($config->{type} eq 'timestamp')) { @@ -375,7 +376,7 @@ sub build_filter_query { my (@sub_values, @sub_where, $not); - if (($config->{type} eq 'text') || ($config->{type} eq 'textfield')) { + if (any { $config->{type} eq $_ } qw(text textfield htmlfield)) { next unless ($params{filter}->{$name}); push @sub_where, qq|cvar.text_value ILIKE ?|; @@ -525,6 +526,7 @@ sub add_custom_variables_to_report { : $cfg->{type} eq 'vendor' ? (SL::DB::Manager::Vendor->find_by(id => 1*$ref->{number_value}) || SL::DB::Vendor->new)->name : $cfg->{type} eq 'part' ? (SL::DB::Manager::Part->find_by(id => 1*$ref->{number_value}) || SL::DB::Part->new)->partnumber : $cfg->{type} eq 'bool' ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No')) + : $cfg->{type} eq 'htmlfield' ? SL::Presenter::Text::stripped_html($ref->{text_value}) : $ref->{text_value}; } } diff --git a/SL/Controller/CustomVariableConfig.pm b/SL/Controller/CustomVariableConfig.pm index 0b124e9fb..193523a85 100644 --- a/SL/Controller/CustomVariableConfig.pm +++ b/SL/Controller/CustomVariableConfig.pm @@ -25,6 +25,7 @@ __PACKAGE__->run_before('load_config', only => [ qw(edit update destroy) ]); our %translations = ( text => t8('Free-form text'), textfield => t8('Text field'), + htmlfield => t8('HTML field'), number => t8('Number'), date => t8('Date'), timestamp => t8('Timestamp'), @@ -35,7 +36,7 @@ our %translations = ( part => t8('Part'), ); -our @types = qw(text textfield number date bool select customer vendor part); # timestamp +our @types = qw(text textfield htmlfield number date bool select customer vendor part); # timestamp # # actions diff --git a/SL/DB/CustomVariable.pm b/SL/DB/CustomVariable.pm index cb6c83158..eeae39aaf 100644 --- a/SL/DB/CustomVariable.pm +++ b/SL/DB/CustomVariable.pm @@ -52,7 +52,7 @@ sub parse_value { return $self->timestamp_value(!defined($unparsed) ? undef : ref($unparsed) eq 'DateTime' ? $unparsed->clone : DateTime->from_kivitendo($unparsed)); } - # text, textfield, select + # text, textfield, htmlfield and select $self->text_value($unparsed); } @@ -92,7 +92,7 @@ sub value { return $self->timestamp_value ? $self->timestamp_value->clone->truncate(to => 'day') : undef; } - goto &text_value; # text, textfield and select + goto &text_value; # text, textfield, htmlfield and select } sub value_as_text { @@ -116,7 +116,7 @@ sub value_as_text { return $object ? $object->displayable_name : ''; } - goto &text_value; # text, textfield and select + goto &text_value; # text, textfield, htmlfield and select } sub is_valid { diff --git a/SL/DB/CustomVariableConfig.pm b/SL/DB/CustomVariableConfig.pm index f8bf7a168..c9f07219b 100644 --- a/SL/DB/CustomVariableConfig.pm +++ b/SL/DB/CustomVariableConfig.pm @@ -117,6 +117,7 @@ sub value_col { customer => 'number_value', vendor => 'number_value', part => 'number_value', + htmlfield => 'text_value', text => 'text_value', textfield => 'text_value', select => 'text_value' diff --git a/templates/webpages/amcvar/render_inputs.html b/templates/webpages/amcvar/render_inputs.html index 880106a99..e269b8e18 100644 --- a/templates/webpages/amcvar/render_inputs.html +++ b/templates/webpages/amcvar/render_inputs.html @@ -19,6 +19,9 @@ [%- ELSIF var.type == 'textfield' %] +[%- ELSIF var.type == 'htmlfield' %] + + [%- ELSIF var.type == 'date' %] [% L.date_tag(var_name, var.value) %] diff --git a/templates/webpages/amcvar/render_inputs_block.html b/templates/webpages/amcvar/render_inputs_block.html index 73731625a..984c589b0 100644 --- a/templates/webpages/amcvar/render_inputs_block.html +++ b/templates/webpages/amcvar/render_inputs_block.html @@ -27,6 +27,10 @@ [% render_cvar_tag_options.import(cols=cvar.var.width, rows=cvar.var.height); L.textarea_tag(cvar_tag_name, cvar.value, render_cvar_tag_options) %] +[%- ELSIF cvar.var.type == 'htmlfield' %] +[% render_cvar_tag_options.import(cols=cvar.var.width, rows=cvar.var.height, class="texteditor"); + L.textarea_tag(cvar_tag_name, L.restricted_html(cvar.value), render_cvar_tag_options) %] + [%- ELSIF cvar.var.type == 'date' %] [%- L.date_tag(cvar_tag_name, cvar.value, render_cvar_tag_options) %] diff --git a/templates/webpages/common/render_cvar_input.html b/templates/webpages/common/render_cvar_input.html index d40037178..36445d630 100644 --- a/templates/webpages/common/render_cvar_input.html +++ b/templates/webpages/common/render_cvar_input.html @@ -16,6 +16,8 @@ [% L.checkbox_tag(var_name, checked = var.value, for_submit = 1) %] [%- ELSIF ( var.config .type == 'textfield' ) %] [% L.textarea_tag(var_name, var.value, cols = var.config.processed_options.WIDTH, rows = var.config.processed_options.HEIGHT) %] +[%- ELSIF ( var.config .type == 'htmlfield' ) %] + [% L.textarea_tag(var_name, L.restricted_html(var.value), cols = var.config.processed_options.WIDTH, rows = var.config.processed_options.HEIGHT, class='texteditor') %] [%- ELSIF ( var.config.type == 'date' ) %] [% L.date_tag(var_name, var.value) %] [%- ELSIF ( var.config.type == 'timestamp' ) %] -- 2.20.1