X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FCVar.pm;h=4d9b6a700b846e9a1192c5296a4b47529f88aec1;hb=87d99e7285f69f6f51596162ad8d7b744c48d517;hp=703bbfe3a7b95952177c1e9f8301cb0caf145d98;hpb=561744fd3b3dcd8cf0280e3b6dc2a81889610b29;p=kivitendo-erp.git diff --git a/SL/CVar.pm b/SL/CVar.pm index 703bbfe3a..4d9b6a700 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -1,5 +1,7 @@ package CVar; +use strict; + use List::Util qw(first); use Data::Dumper; @@ -242,6 +244,8 @@ sub get_custom_variables { : $act_var->{text_value}; $cvar->{valid} = $act_var->{valid}; } else { + $cvar->{valid} = 1; + if ($cvar->{type} eq 'date') { if ($cvar->{default_value} eq 'NOW') { $cvar->{value} = $cvar->{current_date}; @@ -334,9 +338,11 @@ sub save_custom_variables { do_statement($form, $sth, $query, @values); - $self->save_custom_variables_validity(trans_id => $params{trans_id}, config_id => $config->{id}, - validity => ($params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid"} ? 1 : 0) - ); + unless ($params{always_valid}) { + $self->save_custom_variables_validity(trans_id => $params{trans_id}, config_id => $config->{id}, + validity => ($params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid"} ? 1 : 0) + ); + }; } $sth->finish(); @@ -347,7 +353,7 @@ sub save_custom_variables { } sub render_inputs { - $main::lxdebug->enter_sub(); + $main::lxdebug->enter_sub(2); my $self = shift; my %params = @_; @@ -360,14 +366,15 @@ sub render_inputs { my %options = ( name_prefix => "$params{name_prefix}", name_postfix => "$params{name_postfix}", hide_non_editable => $params{hide_non_editable}, + show_disabled_message => $params{show_disabled_message}, ); foreach my $var (@{ $params{variables} }) { - $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { 'var' => $var, %options }); - $var->{VALID_BOX} = "{valid} ? ' checked' : '']}>"; + $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { var => $var, %options }); + $var->{VALID_BOX} = $form->parse_html_template('amcvar/render_checkboxes', { var => $var, %options }); } - $main::lxdebug->leave_sub(); + $main::lxdebug->leave_sub(2); } sub render_search_options { @@ -381,6 +388,8 @@ sub render_search_options { my $myconfig = \%main::myconfig; my $form = $main::form; + $params{hidden_cvar_filters} = $myconfig->{hide_cvar_search_options}; + $params{include_prefix} = 'l_' unless defined($params{include_prefix}); $params{include_value} ||= '1'; @@ -527,7 +536,8 @@ sub add_custom_variables_to_report { # allow sub_module to be a coderef or a fixed value if (ref $params{sub_module} ne 'CODE') { - $params{sub_module} = sub { "$params{sub_module}" }; + my $sub_module = "$params{sub_module}"; + $params{sub_module} = sub { $sub_module }; } my %cfg_map = map { $_->{id} => $_ } @{ $configs }; @@ -596,18 +606,6 @@ sub get_field_format_list { return ($date_fields, $number_fields); } -=head2 VALIDITY - -Suppose the following scenario: - -You have a lot of parts in your database, and a set of properties cofigured. Now not every part has every of these properties, some combinations will just make no sense. In order to clean up your inputs a bit, you want to mark certain combinations as invalid, blocking them from modification and possibly display. - -Validity is assumed. If you modify validity, you actually save B. -iNvalidity is saved as a function of config_id, and the trans_id - -In the naive way, disable an attribute for a specific id (simple) - -=cut sub save_custom_variables_validity { $main::lxdebug->enter_sub(); @@ -651,7 +649,7 @@ sub save_custom_variables_validity { } sub get_custom_variables_validity { - $main::lxdebug->enter_sub(); + $main::lxdebug->enter_sub(2); my $self = shift; my %params = @_; @@ -667,9 +665,42 @@ sub get_custom_variables_validity { my ($invalid) = selectfirst_array_query($form, $dbh, $query, conv_i($params{config_id}), conv_i($params{trans_id})); - $main::lxdebug->leave_sub(); + $main::lxdebug->leave_sub(2); return !$invalid; } 1; + +__END__ + +=head1 NAME + +SL::CVar.pm - Custom Variables module + +=head1 SYNOPSIS + + # dealing with configs + + my $all_configs = CVar->get_configs() + my $config = CVar->get_config(id => '1234') + + CVar->save_config($config); + CVar->delete->config($config) + + # dealing with custom vars + + CVar->get_custom_variables(module => 'ic') + +=head2 VALIDITY + +Suppose the following scenario: + +You have a lot of parts in your database, and a set of properties cofigured. Now not every part has every of these properties, some combinations will just make no sense. In order to clean up your inputs a bit, you want to mark certain combinations as invalid, blocking them from modification and possibly display. + +Validity is assumed. If you modify validity, you actually save B. +Invalidity is saved as a function of config_id, and the trans_id + +In the naive way, disable an attribute for a specific id (simple) + +=cut