ActionBar: Verwendung im »SimpleSystemSetting«-Controller
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 27 Feb 2017 16:03:46 +0000 (17:03 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 28 Feb 2017 09:44:03 +0000 (10:44 +0100)
SL/Controller/SimpleSystemSetting.pm
templates/webpages/simple_system_setting/form.html
templates/webpages/simple_system_setting/list.html

index 5fb9751..5fb79aa 100644 (file)
@@ -250,6 +250,7 @@ my @default_list_attributes = (
 sub action_list {
   my ($self) = @_;
 
+  $self->setup_list_action_bar;
   $self->render('simple_system_setting/list', title => $self->config->{titles}->{list});
 }
 
@@ -377,6 +378,7 @@ sub render_form {
 
   my $sub_form_template = SL::System::Process->exe_dir . '/templates/webpages/simple_system_setting/_' . $self->type . '_form.html';
 
+  $self->setup_render_form_action_bar;
   $self->render(
     'simple_system_setting/form',
     %params,
@@ -409,6 +411,57 @@ sub setup_language {
   $self->{dateformats}   = [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ];
 }
 
+#
+# action bar
+#
+
+sub setup_list_action_bar {
+  my ($self, %params) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      link => [
+        t8('Add'),
+        link => $self->url_for(action => 'new', type => $self->type),
+      ],
+    );
+  }
+}
+
+sub setup_render_form_action_bar {
+  my ($self) = @_;
+
+  my $is_new         = !$self->object->id;
+  my $can_be_deleted = !$is_new
+                    && (!$self->object->can("orphaned")       || $self->object->orphaned)
+                    && (!$self->object->can("can_be_deleted") || $self->object->can_be_deleted);
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Save'),
+        submit    => [ '#form', { action => 'SimpleSystemSetting/' . ($is_new ? 'create' : 'update') } ],
+        checks    => [ 'kivi.validate_form' ],
+        accesskey => 'enter',
+      ],
+
+      action => [
+        t8('Delete'),
+        submit   => [ '#form', { action => 'SimpleSystemSetting/delete' } ],
+        confirm  => t8('Do you really want to delete this object?'),
+        disabled => $is_new          ? t8('This object has not been saved yet.')
+                  : !$can_be_deleted ? t8('The object is in use and cannot be deleted.')
+                  :                    undef,
+      ],
+
+      link => [
+        t8('Abort'),
+        link => $self->list_url,
+      ],
+    );
+  }
+}
+
 1;
 
 __END__
index 26ca5b4..b30680e 100644 (file)
 
  [%- SET sub_file = "simple_system_setting/_" _ sub_form_template _ "_form.html";
      INCLUDE $sub_file %]
-
- <p>
-  [% L.hidden_tag("action", "SimpleSystemSetting/dispatch") %]
-  [% L.submit_tag("action_" _  (SELF.object.id ? "update" : "create"), LxERP.t8("Save"), onclick="return kivi.validate_form('#form');") %]
-  [%- IF SELF.object.id && (!SELF.object.can("orphaned") || SELF.object.orphaned) && (!SELF.object.can("can_be_deleted") || SELF.object.can_be_deleted) -%]
-    [% L.submit_tag("action_delete", LxERP.t8("Delete"), confirm=LxERP.t8("Do you really want to delete this object?")) %]
-  [%- END %]
-  <a href="[% SELF.list_url %]">[%- LxERP.t8("Cancel") %]</a>
- </p>
 </form>
index 398124c..0f89642 100644 (file)
  </tbody>
 </table>
 
-<hr height="3">
-
-<p>
- <a href="[% SELF.url_for(action="new", type=SELF.type) %]">[%- "Add" | $T8 %]</a>
-</p>
-
 [% IF SELF.supports_reordering %]
 [% L.sortable_element("#object_list tbody", url=SELF.url_for(action="reorder", type=SELF.type), with="object_id") %]
 [% END %]