X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Famcvar.pl;h=343350a242de0151da1c0d795c9178cd93cc0418;hb=6f398b352e3b28af6b00852da08193727f803aee;hp=47c821c96a549b4895d36ed41fd208d91b206713;hpb=b2f44e3d98cbbd622b1497c23602eb79e71a3c64;p=kivitendo-erp.git diff --git a/bin/mozilla/amcvar.pl b/bin/mozilla/amcvar.pl index 47c821c96..343350a24 100644 --- a/bin/mozilla/amcvar.pl +++ b/bin/mozilla/amcvar.pl @@ -36,13 +36,17 @@ use SL::CVar; use SL::Form; use Data::Dumper; - -1; +use List::MoreUtils qw(any); require "bin/mozilla/common.pl"; +use strict; + +1; + # end of main +my $locale = $main::locale; our %translations = ('text' => $locale->text('Free-form text'), 'textfield' => $locale->text('Text field'), 'number' => $locale->text('Number'), @@ -50,9 +54,18 @@ our %translations = ('text' => $locale->text('Free-form text'), 'timestamp' => $locale->text('Timestamp'), 'bool' => $locale->text('Yes/No (Checkbox)'), 'select' => $locale->text('Selection'), + 'customer' => $locale->text('Customer'), + 'vendor' => $locale->text('Vendor'), + 'part' => $locale->text('Part'), ); -our @types = qw(text textfield number date bool select); # timestamp +our @types = qw(text textfield number date bool select customer vendor part); # timestamp + +our @modules = ({ module => 'CT', description => $locale->text('Customers and vendors') }, + { module => 'Contacts', description => $locale->text('Contact persons') }, + { module => 'IC', description => $locale->text('Parts, services and assemblies') }, + { module => 'Projects', description => $locale->text('Projects') }, + ); sub add { add_cvar_config(); @@ -62,60 +75,60 @@ sub edit { edit_cvar_config(); } +sub _is_valid_module { + my $module = shift; + + return any { $_->{module} eq $module } @modules; +} + sub list_cvar_configs { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('config'); + my $form = $main::form; + my $locale = $main::locale; - $form->{module} ||= $form->{cvar_module}; + $main::auth->assert('config'); - my @configs = grep { $_->{module} eq $form->{module} } @{ CVar->get_configs() }; + $form->{module} = $form->{module} || $form->{cvar_module} || 'CT'; + $form->{module} = 'CT' unless _is_valid_module($form->{module}); - my $previous_config; + my @configs = @{ CVar->get_configs(module => $form->{module}) }; foreach my $config (@configs) { $config->{type_tr} = $translations{$config->{type}}; - - foreach my $flag (split m/:/, $config->{flags}) { - if ($flag =~ m/(.*?)=(.*)/) { - $config->{"flag_${1}"} = $2; - } else { - $config->{"flag_${flag}"} = 1; - } - } - - if ($previous_config) { - $previous_config->{next_id} = $config->{id}; - $config->{previous_id} = $previous_config->{id}; - } - - $previous_config = $config; } $form->{title} = $locale->text('List of custom variables'); $form->header(); - print $form->parse_html_template('amcvar/list_cvar_configs', { 'CONFIGS' => \@configs }); + print $form->parse_html_template('amcvar/list_cvar_configs', { CONFIGS => \@configs, + MODULES => \@modules }); + +# $main::lxdebug->dump(0, "modules", \@modules); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub add_cvar_config { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('config'); + my $form = $main::form; - $form->{module} ||= $form->{cvar_module}; + $main::auth->assert('config'); + + $form->{module} = $form->{module} || $form->{cvar_module} || 'CT'; $form->{edit} = 0; display_cvar_config_form(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit_cvar_config { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; - $auth->assert('config'); + $main::auth->assert('config'); my $config = CVar->get_config('id' => $form->{id}); @@ -124,13 +137,17 @@ sub edit_cvar_config { $form->{edit} = 1; display_cvar_config_form(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub save { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('config'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); $form->isblank('name', $locale->text('The name is missing.')); $form->isblank('description', $locale->text('The description is missing.')); @@ -155,11 +172,14 @@ sub save { list_cvar_configs(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub delete { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; CVar->delete_config('id' => $form->{id}); @@ -167,13 +187,17 @@ sub delete { list_cvar_configs(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub display_cvar_config_form { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $auth->assert('config'); + $main::auth->assert('config'); my @types = map { { 'type' => $_, 'type_tr' => $translations{$_} } } @types; @@ -184,19 +208,41 @@ sub display_cvar_config_form { $form->{title} = $form->{edit} ? $locale->text("Edit custom variable") : $locale->text("Add custom variable"); $form->header(); - print $form->parse_html_template("amcvar/display_cvar_config_form", { 'TYPES' => \@types }); + print $form->parse_html_template("amcvar/display_cvar_config_form", { TYPES => \@types, + MODULES => \@modules }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub swap_cvar_configs { - $lxdebug->enter_sub(); +sub update { + $main::lxdebug->enter_sub(); - AM->swap_sortkeys(\%myconfig, $form, 'custom_variable_configs'); + my $form = $main::form; - list_cvar_configs(); + $main::auth->assert('config'); + + $form->{included_by_default} = $form->{inclusion} eq 'yes_default_on'; + $form->{includeable} = $form->{inclusion} ne 'no'; + + display_cvar_config_form(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); +} + + +sub dispatcher { + my $form = $main::form; + my $locale = $main::locale; + + foreach my $action (qw(list_cvar_configs add_cvar_config update)) { + if ($form->{"action_${action}"}) { + call_sub($action); + return; + } + } + + $form->error($locale->text('No action defined.')); } 1; +