commit a3afc944f025a130a55d440b045eceadb0630466
Author: Moritz Bunkus <m.bunkus@linet.de>
Date:   Tue Mar 21 14:57:36 2017 +0100

    ActionBar: Verwendung bei »System« → »Einheiten bearbeiten«

diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl
index b3ca071c0..2aeba0372 100644
--- a/bin/mozilla/am.pl
+++ b/bin/mozilla/am.pl
@@ -39,6 +39,7 @@ use SL::Auth::PasswordPolicy;
 use SL::AM;
 use SL::CA;
 use SL::Form;
+use SL::Helper::Flash;
 use SL::User;
 use SL::USTVA;
 use SL::Iconv;
@@ -795,6 +796,29 @@ sub doclose {
   $main::lxdebug->leave_sub();
 }
 
+sub add_unit {
+  $::auth->assert('config');
+
+  # my $units = AM->retrieve_units(\%::myconfig, $::form, "resolved_");
+  # # AM->units_in_use(\%::myconfig, $::form, $units);
+
+  # $units->{$_}->{BASE_UNIT_DDBOX} = AM->unit_select_data($units, $units->{$_}->{base_unit}, 1) for keys %{$units};
+
+  my @languages = @{ SL::DB::Manager::Language->get_all_sorted };
+
+  my $units = AM->retrieve_units(\%::myconfig, $::form);
+  my $ddbox = AM->unit_select_data($units, undef, 1);
+
+  setup_am_add_unit_action_bar();
+
+  $::form->{title} = $::locale->text("Add unit");
+  $::form->header();
+  print($::form->parse_html_template("am/add_unit", {
+    NEW_BASE_UNIT_DDBOX => $ddbox,
+    LANGUAGES           => \@languages,
+  }));
+}
+
 sub edit_units {
   $main::lxdebug->enter_sub();
 
@@ -831,7 +855,9 @@ sub edit_units {
   $units = AM->retrieve_units(\%myconfig, $form);
   my $ddbox = AM->unit_select_data($units, undef, 1);
 
-  $form->{"title"} = $locale->text("Add and edit units");
+  setup_am_edit_units_action_bar();
+
+  $form->{"title"} = $locale->text("Edit units");
   $form->header();
   print($form->parse_html_template("am/edit_units",
                                    { "UNITS"               => \@unit_list,
@@ -842,7 +868,7 @@ sub edit_units {
   $main::lxdebug->leave_sub();
 }
 
-sub add_unit {
+sub create_unit {
   $main::lxdebug->enter_sub();
 
   my $form     = $main::form;
@@ -877,9 +903,9 @@ sub add_unit {
 
   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
-  $form->{"saved_message"} = $locale->text("The unit has been saved.");
+  flash_later('info', $locale->text("The unit has been added."));
 
-  edit_units();
+  print $form->redirect_header('am.pl?action=edit_units');
 
   $main::lxdebug->leave_sub();
 }
@@ -983,9 +1009,9 @@ sub save_unit {
 
   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
-  $form->{"saved_message"} = $locale->text("The units have been saved.");
+  flash_later('info', $locale->text("The units have been saved."));
 
-  edit_units();
+  print $form->redirect_header('am.pl?action=edit_units');
 
   $main::lxdebug->leave_sub();
 }
@@ -1463,3 +1489,45 @@ sub setup_am_edit_tax_action_bar {
     );
   }
 }
+
+sub setup_am_add_unit_action_bar {
+  my %params = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Save'),
+        submit    => [ '#form', { action => "create_unit" } ],
+        accesskey => 'enter',
+      ],
+
+      'separator',
+
+      link => [
+        t8('Back'),
+        link => 'am.pl?action=edit_units',
+      ],
+    );
+  }
+}
+
+sub setup_am_edit_units_action_bar {
+  my %params = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Save'),
+        submit    => [ '#form', { action => "save_unit" } ],
+        accesskey => 'enter',
+      ],
+
+      'separator',
+
+      link => [
+        t8('Add'),
+        link => 'am.pl?action=add_unit',
+      ],
+    );
+  }
+}
diff --git a/locale/de/all b/locale/de/all
index 41496079c..066901fa1 100755
--- a/locale/de/all
+++ b/locale/de/all
@@ -190,7 +190,6 @@ $self->{texts} = {
   'Add Vendor Invoice'          => 'Einkaufsrechnung erfassen',
   'Add Warehouse'               => 'Lager erfassen',
   'Add acceptance status'       => 'Abnahmestatus hinzufügen',
-  'Add and edit units'          => 'Einheiten erfassen und bearbeiten',
   'Add bank account'            => 'Bankkonto erfassen',
   'Add booking group'           => 'Buchungsgruppe erfassen',
   'Add business'                => 'Kunden-/Lieferantentyp hinzufügen',
@@ -3128,7 +3127,7 @@ $self->{texts} = {
   'The transfer has been canceled by the user.' => 'Der Vorgang wurde durch den Benutzer abgebrochen.',
   'The transport cost article \'#1\' is missing. Do you want to continue anyway?' => 'Der Transportkostenartikel »#1« fehlt. Wollen Sie trotzdem fortfahren?',
   'The type is missing.'        => 'Der Typ fehlt.',
-  'The unit has been saved.'    => 'Die Einheit wurde gespeichert.',
+  'The unit has been added.'    => 'Die Einheit wurde erfasst.',
   'The unit in row %d has been deleted in the meantime.' => 'Die Einheit in Zeile %d ist in der Zwischentzeit gel&ouml;scht worden.',
   'The unit in row %d has been used in the meantime and cannot be changed anymore.' => 'Die Einheit in Zeile %d wurde in der Zwischenzeit benutzt und kann nicht mehr ge&auml;ndert werden.',
   'The unit is missing.'        => 'Die Einheit fehlt.',
diff --git a/templates/webpages/am/_units_header_info.html b/templates/webpages/am/_units_header_info.html
new file mode 100644
index 000000000..a54a782b0
--- /dev/null
+++ b/templates/webpages/am/_units_header_info.html
@@ -0,0 +1,7 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE T8 -%]
+<p>
+ [% LxERP.t8('All units have either no or exactly one base unit of which they are multiples.') %]
+ [% LxERP.t8('If you select a base unit then you also have to enter a factor.') %]
+ [% LxERP.t8('You have to define a unit as a multiple of a smaller unit.') %]
+ [% LxERP.t8('Therefore the definition of "kg" with the base unit "g" and a factor of 1000 is valid while defining "g" with a base unit of "kg" and a factor of "0.001" is not.') %]
+</p>
diff --git a/templates/webpages/am/add_unit.html b/templates/webpages/am/add_unit.html
new file mode 100644
index 000000000..573121cb5
--- /dev/null
+++ b/templates/webpages/am/add_unit.html
@@ -0,0 +1,39 @@
+[%- USE HTML -%][%- USE T8 -%]
+<h1>[% 'Add unit' | $T8 %]</h1>
+
+[% PROCESS "am/_units_header_info.html" %]
+
+<hr>
+
+<form method="post" action="[% HTML.escape(script) %]" id="form">
+
+ <input type="hidden" name="type" value="unit">
+
+ <table>
+  <tr>
+   <th align="right">[% 'Unit' | $T8 %]</th>
+   <td><input name="new_name" size="20" maxlength="20"></td>
+  </tr>
+  <tr>
+   <th align="right">[% 'Base unit' | $T8 %]</th>
+   <td>
+    <select name="new_base_unit">
+     [% FOREACH row = NEW_BASE_UNIT_DDBOX %]<option [% row.selected %]>[% row.name %]</option>[% END %]
+    </select>
+   </td>
+  </tr>
+  <tr>
+   <th align="right">[% 'Factor' | $T8 %]</th>
+   <td><input name="new_factor"></td>
+  </tr>
+
+  [% FOREACH language = LANGUAGES %]
+   <tr>
+    <th align="right">[% language.description %]</th>
+    <td><input name="new_localized_[% language.id %]" size="20" maxlength="20"></td>
+    <th align="right">[% 'Plural' | $T8 %]</th>
+    <td><input name="new_localized_plural_[% language.id %]" size="20" maxlength="20"></td>
+   </tr>
+  [% END %]
+ </table>
+</form>
diff --git a/templates/webpages/am/edit_units.html b/templates/webpages/am/edit_units.html
index 1879d56b9..210ec0c0a 100644
--- a/templates/webpages/am/edit_units.html
+++ b/templates/webpages/am/edit_units.html
@@ -2,72 +2,27 @@
 [% USE HTML %]
 <h1>[% title %]</h1>
 
- [% IF saved_message %]
-  <p>[% saved_message %]</p>
+[% PROCESS "common/flash.html" %]
 
-  <hr>
- [% END %]
+[% PROCESS "am/_units_header_info.html" %]
 
- <form method="post" action="[% HTML.escape(script) %]">
+<hr>
 
- <input type="hidden" name="type" value="unit">
-
- <p>
-  [% LxERP.t8('All units have either no or exactly one base unit of which they are multiples.') %]
-  [% LxERP.t8('If you select a base unit then you also have to enter a factor.') %]
-  [% LxERP.t8('You have to define a unit as a multiple of a smaller unit.') %]
-  [% LxERP.t8('Therefore the definition of "kg" with the base unit "g" and a factor of 1000 is valid while defining "g" with a base unit of "kg" and a factor of "0.001" is not.') %]
- </p>
+<p>
+ [% 'Units that have already been used (e.g. for parts and services or in invoices or warehouse transactions) cannot be changed.' | $T8 %]
+</p>
 
- <hr>
+<p>
+ [% 'Units marked for deletion will be deleted upon saving.' | $T8 %]
+</p>
 
- <h2>[% 'Add unit' | $T8 %]</h2>
+<p>
+ [% 'You can declare different translations for singular and plural for each unit (e.g. &quot;day&quot; and &quot;days).' | $T8 %]
+</p>
 
- <table>
-  <tr>
-   <th align="right">[% 'Unit' | $T8 %]</th>
-   <td><input name="new_name" size="20" maxlength="20"></td>
-  </tr>
-  <tr>
-   <th align="right">[% 'Base unit' | $T8 %]</th>
-   <td>
-    <select name="new_base_unit">
-     [% FOREACH row = NEW_BASE_UNIT_DDBOX %]<option [% row.selected %]>[% row.name %]</option>[% END %]
-    </select>
-   </td>
-  </tr>
-  <tr>
-   <th align="right">[% 'Factor' | $T8 %]</th>
-   <td><input name="new_factor"></td>
-  </tr>
-
-  [% FOREACH language = LANGUAGES %]
-   <tr>
-    <th align="right">[% language.description %]</th>
-    <td><input name="new_localized_[% language.id %]" size="20" maxlength="20"></td>
-    <th align="right">[% 'Plural' | $T8 %]</th>
-    <td><input name="new_localized_plural_[% language.id %]" size="20" maxlength="20"></td>
-   </tr>
-  [% END %]
- </table>
+<form method="post" action="[% HTML.escape(script) %]" id="form">
 
- <input type="submit" class="submit" name="action" value="[% 'Add' | $T8 %]">
-
- <hr>
-
- <h2>[% 'Edit units' | $T8 %]</h2>
-
- <p>
-  [% 'Units that have already been used (e.g. for parts and services or in invoices or warehouse transactions) cannot be changed.' | $T8 %]
- </p>
-
- <p>
-  [% 'Units marked for deletion will be deleted upon saving.' | $T8 %]
- </p>
-
- <p>
-  [% 'You can declare different translations for singular and plural for each unit (e.g. &quot;day&quot; and &quot;days).' | $T8 %]
- </p>
+ <input type="hidden" name="type" value="unit">
 
  <table id="unit_list">
   <thead>
@@ -127,9 +82,6 @@
 
  <input type="hidden" name="rowcount" value="[% UNITS.size %]">
 
- <input type="submit" class="submit" name="action" value="[% 'Save' | $T8 %]">
-
  </form>
 
  [% L.sortable_element('#unit_list tbody', url => 'controller.pl?action=Unit/reorder', with => 'unit_id') %]
-
