X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FFlash.pm;h=78a94e34f0aef463c5b1cedb4371a74cd39f24a1;hb=6de8e1614fb03b63967d06bd8522b4b46260832e;hp=a4ad69177e65b106e0b03f510f7206b19af66e25;hpb=a7c70594d6b9d8c4b1ef891bbe6a72b42d6bc741;p=kivitendo-erp.git diff --git a/SL/Helper/Flash.pm b/SL/Helper/Flash.pm index a4ad69177..78a94e34f 100644 --- a/SL/Helper/Flash.pm +++ b/SL/Helper/Flash.pm @@ -3,29 +3,49 @@ package SL::Helper::Flash; use strict; require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(flash render_flash); +our @ISA = qw(Exporter); +our @EXPORT = qw(flash flash_later); +our @EXPORT_OK = qw(render_flash); + +# +# public functions +# sub flash { - my $category = shift; - $category = 'info' if $category eq 'information'; + $::form->{FLASH} = _store_flash($::form->{FLASH}, @_); +} - $::form->{FLASH} ||= { }; - $::form->{FLASH}->{ $category } ||= [ ]; - push @{ $::form->{FLASH}->{ $category } }, @_; +sub flash_later { + $::auth->set_session_value({ key => "FLASH", value => _store_flash($::auth->get_session_value('FLASH'), @_), auto_restore => 1 }); } sub render_flash { return $::form->parse_html_template('common/flash'); } +# +# private functions +# + +sub _store_flash { + my $store = shift || { }; + my $category = shift; + $category = 'info' if $category eq 'information'; + + $store ||= { }; + $store->{ $category } ||= [ ]; + push @{ $store->{ $category } }, @_; + + return $store; +} + 1; __END__ =head1 NAME -SL::Helpers::Flash - helper functions for storing messages to be +SL::Helper::Flash - helper functions for storing messages to be displayed to the user =head1 SYNOPSIS @@ -42,21 +62,39 @@ following code: [%- INCLUDE 'common/flash.html' %] +=head1 EXPORTS + +The functions L and L are always exported. + +The function L is only exported upon request. + =head1 FUNCTIONS =over 4 -=item C +=item C -Stores a message for the given category. The category can be either +Stores messages for the given category. The category can be either C, C or C. C can also be used as an alias for C. +=item C + +Stores messages for the given category for the next request. The +category can be either C, C or C. C +can also be used as an alias for C. + +The messages are stored in the user's session and restored upon the +next request. Can be used for transmitting information over HTTP +redirects. + =item C Outputs the flash message by parsing the C template file. +This function is not exported by default. + =back =head1 AUTHOR