X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/6b5e657a5cef0fe78cc00d27940e4b6a65bd30b0..0cb6e3af8457c1b10c356a1749269b16c5cd3328:/SL/Controller/CustomVariableConfig.pm diff --git a/SL/Controller/CustomVariableConfig.pm b/SL/Controller/CustomVariableConfig.pm index 33c3dec40..a56740b8f 100644 --- a/SL/Controller/CustomVariableConfig.pm +++ b/SL/Controller/CustomVariableConfig.pm @@ -7,8 +7,10 @@ use parent qw(SL::Controller::Base); use List::Util qw(first); use SL::DB::CustomVariableConfig; +use SL::DB::CustomVariableValidity; use SL::Helper::Flash; use SL::Locale::String; +use Data::Dumper; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(config module module_description flags) ], @@ -61,12 +63,9 @@ sub show_form { $self->flags({ map { split m/=/, $_, 2 } - split m/;/, ($self->config->flags || '') + split m/:/, ($self->config->flags || '') }); - $::lxdebug->dump(0, "cflags", $self->config->flags); - $::lxdebug->dump(0, "flags", $self->flags); - $self->render('custom_variable_config/form', %params); } @@ -105,7 +104,7 @@ sub action_reorder { SL::DB::CustomVariableConfig->reorder_list(@{ $::form->{cvarcfg_id} || [] }); - $self->render(\'', { type => 'json' }); + $self->render(\'', { type => 'json' }); # ' make emacs happy } # @@ -181,10 +180,33 @@ sub create_or_update { return; } + my $dbh = $self->config->db; + $dbh->begin_work; + $self->config->save; + $self->_set_cvar_validity() if $is_new; + + $dbh->commit; flash_later('info', $is_new ? t8('The custom variable has been created.') : t8('The custom variable has been saved.')); $self->redirect_to(action => 'list', module => $self->module); } +sub _set_cvar_validity { + my ($self) = @_; + + my $flags = { + map { split m/=/, $_, 2 } + split m/:/, ($self->config->flags || '') + }; + + # nothing to do to set valid + return if !$flags->{defaults_to_invalid}; + + my $all_parts = SL::DB::Manager::Part->get_all(where => [ or => [ obsolete => 0, obsolete => undef ] ]); + foreach my $part (@{ $all_parts }) { + SL::DB::CustomVariableValidity->new(config_id => $self->config->id, trans_id => $part->id)->save; + } +} + 1;