From eae5f8bdbca22f1f8c7ba4439dafbe3b89b6a143 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 23 May 2017 09:47:24 +0200 Subject: [PATCH] =?utf8?q?Part=20Controller=20-=20callbacks=20f=C3=BCr=20A?= =?utf8?q?rtikel=20speichern=20und=20l=C3=B6schen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Nach dem Speichern und Löschen eines Artikels zur vorherigen Seite springen, wenn $::form->{callback} gesetzt ist. Das Default-Verhalten für das Speichern eines Artikels ist es auf der Artikelseite zu bleiben. Das Default-Verhalten für das Löschen eines Artikels ist es zur Login-Seite zu springen. --- SL/Controller/Part.pm | 26 +++++++++++++++++++------- templates/webpages/part/form.html | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 20f6752f1..1c8db0e5d 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -40,6 +40,7 @@ __PACKAGE__->run_before('check_part_id', only => [ qw(edit delete) ]); sub action_add_part { my ($self, %params) = @_; + $::form->{callback} = $self->url_for(action => 'add_part') unless $::form->{callback}; $self->part( SL::DB::Part->new_part ); $self->add; }; @@ -47,6 +48,7 @@ sub action_add_part { sub action_add_service { my ($self, %params) = @_; + $::form->{callback} = $self->url_for(action => 'add_service') unless $::form->{callback}; $self->part( SL::DB::Part->new_service ); $self->add; }; @@ -54,6 +56,7 @@ sub action_add_service { sub action_add_assembly { my ($self, %params) = @_; + $::form->{callback} = $self->url_for(action => 'add_assembly') unless $::form->{callback}; $self->part( SL::DB::Part->new_assembly ); $self->add; }; @@ -61,6 +64,7 @@ sub action_add_assembly { sub action_add_assortment { my ($self, %params) = @_; + $::form->{callback} = $self->url_for(action => 'add_assortment') unless $::form->{callback}; $self->part( SL::DB::Part->new_assortment ); $self->add; }; @@ -130,8 +134,12 @@ sub action_save { flash_later('info', $is_new ? t8('The item has been created.') : t8('The item has been saved.')); - # reload item, this also resets last_modification! - $self->redirect_to(controller => 'Part', action => 'edit', 'part.id' => $self->part->id); + if ( $::form->{callback} ) { + $self->redirect_to($::form->unescape($::form->{callback})); + } else { + # default behaviour after save: reload item, this also resets last_modification! + $self->redirect_to(controller => 'Part', action => 'edit', 'part.id' => $self->part->id); + } } sub action_save_as_new { @@ -164,11 +172,15 @@ sub action_delete { }) or return $self->js->error(t8('The item couldn\'t be deleted!') . " " . $self->part->db->error)->render; flash_later('info', t8('The item has been deleted.')); - my @redirect_params = ( - controller => 'controller.pl', - action => 'LoginScreen/user_login' - ); - $self->redirect_to(@redirect_params); + if ( $::form->{callback} ) { + $self->redirect_to($::form->unescape($::form->{callback})); + } else { + my @redirect_params = ( + controller => 'controller.pl', + action => 'LoginScreen/user_login' + ); + $self->redirect_to(@redirect_params); + } } sub action_use_as_new { diff --git a/templates/webpages/part/form.html b/templates/webpages/part/form.html index 693af3e42..b33d5b07e 100644 --- a/templates/webpages/part/form.html +++ b/templates/webpages/part/form.html @@ -12,6 +12,7 @@ [% L.hidden_tag('part.part_type' , SELF.part.part_type) %] [% L.hidden_tag('part.id' , SELF.part.id) %] [% L.hidden_tag('last_modification', SELF.part.last_modification) %] + [% L.hidden_tag('callback' , FORM.callback) %]