From a34bdbf789c735db56009ce6c61566ac30792abe Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 27 Feb 2017 17:03:46 +0100 Subject: [PATCH] =?utf8?q?ActionBar:=20Verwendung=20im=20=C2=BBSimpleSyste?= =?utf8?q?mSetting=C2=AB-Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/SimpleSystemSetting.pm | 53 +++++++++++++++++++ .../webpages/simple_system_setting/form.html | 9 ---- .../webpages/simple_system_setting/list.html | 6 --- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/SL/Controller/SimpleSystemSetting.pm b/SL/Controller/SimpleSystemSetting.pm index 5fb975162..5fb79aaab 100644 --- a/SL/Controller/SimpleSystemSetting.pm +++ b/SL/Controller/SimpleSystemSetting.pm @@ -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__ diff --git a/templates/webpages/simple_system_setting/form.html b/templates/webpages/simple_system_setting/form.html index 26ca5b49f..b30680e34 100644 --- a/templates/webpages/simple_system_setting/form.html +++ b/templates/webpages/simple_system_setting/form.html @@ -14,13 +14,4 @@ [%- SET sub_file = "simple_system_setting/_" _ sub_form_template _ "_form.html"; INCLUDE $sub_file %] - -

- [% 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 %] - [%- LxERP.t8("Cancel") %] -

diff --git a/templates/webpages/simple_system_setting/list.html b/templates/webpages/simple_system_setting/list.html index 398124cc9..0f896421e 100644 --- a/templates/webpages/simple_system_setting/list.html +++ b/templates/webpages/simple_system_setting/list.html @@ -40,12 +40,6 @@ -
- -

- [%- "Add" | $T8 %] -

- [% IF SELF.supports_reordering %] [% L.sortable_element("#object_list tbody", url=SELF.url_for(action="reorder", type=SELF.type), with="object_id") %] [% END %] -- 2.20.1