a4ad69177e65b106e0b03f510f7206b19af66e25
[kivitendo-erp.git] / SL / Helper / Flash.pm
1 package SL::Helper::Flash;
2
3 use strict;
4
5 require Exporter;
6 our @ISA    = qw(Exporter);
7 our @EXPORT = qw(flash render_flash);
8
9 sub flash {
10   my $category = shift;
11   $category    = 'info' if $category eq 'information';
12
13   $::form->{FLASH}                ||= { };
14   $::form->{FLASH}->{ $category } ||= [ ];
15   push @{ $::form->{FLASH}->{ $category } }, @_;
16 }
17
18 sub render_flash {
19   return $::form->parse_html_template('common/flash');
20 }
21
22 1;
23
24 __END__
25
26 =head1 NAME
27
28 SL::Helpers::Flash - helper functions for storing messages to be
29 displayed to the user
30
31 =head1 SYNOPSIS
32
33 The flash is a store for messages that should be displayed to the
34 user. Each message has a category which is usually C<information>,
35 C<warning> or C<error>. The messages in each category are grouped and
36 displayed in colors appropriate for their severity (e.g. errors in
37 red).
38
39 Messages are rendered either by calling the function C<render_flash>
40 or by including the flash sub-template from a template with the
41 following code:
42
43   [%- INCLUDE 'common/flash.html' %]
44
45 =head1 FUNCTIONS
46
47 =over 4
48
49 =item C<flash $category, $message>
50
51 Stores a message for the given category. The category can be either
52 C<information>, C<warning> or C<error>. C<info> can also be used as an
53 alias for C<information>.
54
55 =item C<render_flash>
56
57 Outputs the flash message by parsing the C<common/flash.html> template
58 file.
59
60 =back
61
62 =head1 AUTHOR
63
64 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
65
66 =cut