Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / Controller / CustomVariableConfig.pm
index 456fe71..193523a 100644 (file)
@@ -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
@@ -46,6 +47,7 @@ sub action_list {
 
   my $configs = SL::DB::Manager::CustomVariableConfig->get_all_sorted(where => [ module => $self->module ]);
 
+  $self->setup_list_action_bar;
   $::form->header;
   $self->render('custom_variable_config/list',
                 title   => t8('List of custom variables'),
@@ -70,6 +72,7 @@ sub show_form {
   $params{all_partsgroups} = SL::DB::Manager::PartsGroup->get_all();
 
   $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side);
+  $self->setup_form_action_bar;
   $self->render('custom_variable_config/form', %params);
 }
 
@@ -164,6 +167,7 @@ sub init_modules {
     { module => 'IC',               description => t8('Parts, services and assemblies') },
     { module => 'Projects',         description => t8('Projects')                       },
     { module => 'RequirementSpecs', description => t8('Requirement Specs')              },
+    { module => 'ShipTo',           description => t8('Shipping Address')               },
   )];
 }
 
@@ -196,13 +200,13 @@ sub create_or_update {
     return;
   }
 
-  my $dbh = $self->config->db;
-  $dbh->begin_work;
+  SL::DB->client->with_transaction(sub {
+    my $dbh = SL::DB->client->dbh;
 
-  $self->config->save;
-  $self->_set_cvar_validity() if $is_new;
-
-  $dbh->commit;
+    $self->config->save;
+    $self->_set_cvar_validity() if $is_new;
+    1;
+  }) or do { die SL::DB->client->error };
 
   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);
@@ -225,4 +229,57 @@ sub _set_cvar_validity {
   }
 }
 
+sub setup_list_action_bar {
+  my ($self) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Add'),
+        link => $self->url_for(action => 'new', module => $self->module),
+      ],
+    );
+  }
+}
+
+sub setup_form_action_bar {
+  my ($self) = @_;
+
+  my $is_new = !$self->config->id;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      combobox => [
+        action => [
+          t8('Save'),
+          submit    => [ '#form', { action => 'CustomVariableConfig/' . ($is_new ? 'create' : 'update') } ],
+          checks    => [ 'check_prerequisites' ],
+          accesskey => 'enter',
+        ],
+
+        action => [
+          t8('Save as new'),
+          submit => [ '#form', { action => 'CustomVariableConfig/create'} ],
+          checks => [ 'check_prerequisites' ],
+          not_if => $is_new,
+        ],
+      ], # end of combobox "Save"
+
+      action => [
+        t8('Delete'),
+        submit   => [ '#form', { action => 'CustomVariableConfig/destroy' } ],
+        confirm  => t8('Do you really want to delete this object?'),
+        disabled => $is_new ? t8('This object has not been saved yet.') : undef,
+      ],
+
+      'separator',
+
+      link => [
+        t8('Abort'),
+        link => $self->url_for(action => 'list', module => $self->module),
+      ],
+    );
+  }
+}
+
 1;