From: Sven Schöling Date: Thu, 30 Dec 2010 15:04:19 +0000 (+0100) Subject: Merge branch 'master' of ssh://lx-office/~/lx-office-erp X-Git-Tag: release-2.6.2beta1~26 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/commitdiff_plain/128bad31d931ed3a3df4390170f7a598748f3a83?hp=25b37b7f3ab68650c1d8898b534cac5bdd64c7e5 Merge branch 'master' of ssh://lx-office/~/lx-office-erp --- diff --git a/SL/DB/Employee.pm b/SL/DB/Employee.pm index 841696b6e..1ef565ee6 100644 --- a/SL/DB/Employee.pm +++ b/SL/DB/Employee.pm @@ -1,13 +1,9 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::Employee; use strict; use SL::DB::MetaSetup::Employee; +use SL::DB::Manager::Employee; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; 1; diff --git a/SL/DB/Manager/Employee.pm b/SL/DB/Manager/Employee.pm new file mode 100644 index 000000000..e52eebb1f --- /dev/null +++ b/SL/DB/Manager/Employee.pm @@ -0,0 +1,17 @@ +package SL::DB::Manager::Employee; + +use strict; + +use SL::DB::Helpers::Manager; +use base qw(SL::DB::Helpers::Manager); + +sub object_class { 'SL::DB::Employee' } + +__PACKAGE__->make_manager_methods; + +sub current { + return undef unless $::form && $::form->{login}; + return shift->find_by(login => $::form->{login}); +} + +1; diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 35284db4b..013dfe607 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -170,6 +170,7 @@ sub handle_request { $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password}); $::auth->create_or_refresh_session; + $::auth->delete_session_value('FLASH')->save_session(); delete $::form->{password}; if ($action) { diff --git a/SL/Helper/Flash.pm b/SL/Helper/Flash.pm new file mode 100644 index 000000000..e599f6e6e --- /dev/null +++ b/SL/Helper/Flash.pm @@ -0,0 +1,104 @@ +package SL::Helper::Flash; + +use strict; + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(flash flash_later); +our @EXPORT_OK = qw(render_flash); + +# +# public functions +# + +sub flash { + $::form->{FLASH} = _store_flash($::form->{FLASH}, @_); +} + +sub flash_later { + $::auth->set_session_value(FLASH => _store_flash($::auth->get_session_value('FLASH'), @_))->save_session(); +} + +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 +displayed to the user + +=head1 SYNOPSIS + +The flash is a store for messages that should be displayed to the +user. Each message has a category which is usually C, +C or C. The messages in each category are grouped and +displayed in colors appropriate for their severity (e.g. errors in +red). + +Messages are rendered either by calling the function C +or by including the flash sub-template from a template with the +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 + +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 + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut diff --git a/SL/MoreCommon.pm b/SL/MoreCommon.pm index 0d5413b1a..8f6486135 100644 --- a/SL/MoreCommon.pm +++ b/SL/MoreCommon.pm @@ -4,8 +4,9 @@ require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(save_form restore_form compare_numbers any cross); -our @EXPORT_OK = qw(ary_union ary_intersect ary_diff listify); +our @EXPORT_OK = qw(ary_union ary_intersect ary_diff listify ary_to_hash); +use List::MoreUtils qw(zip); use YAML; use SL::AM; @@ -148,6 +149,22 @@ sub listify { return wantarray ? @ary : scalar @ary; } +sub ary_to_hash { + my $idx_key = shift; + my $value_key = shift; + + return map { ($_, 1) } @_ if !defined($idx_key); + + my @indexes = map { ref $_ eq 'HASH' ? $_->{ $idx_key } : $_->$idx_key(); } @_; + my @values = map { + !defined($value_key) ? $_ + : ref $_ eq 'HASH' ? $_->{ $value_key } + : $_->$value_key() + } @_; + + return zip(@indexes, @values); +} + 1; __END__ @@ -192,4 +209,27 @@ at the moment. This will be corrected in the future. =back +=item ary_to_hash INDEX_KEY, VALUE_KEY, ARRAY + +Returns a hash with the content of ARRAY based on the values of +INDEX_KEY and VALUE_KEY. + +If INDEX_KEY is undefined then the elements of ARRAY are the keys and +'1' is the value for each of them. + +If INDEX_KEY is defined then each element of ARRAY is checked whether +or not it is a hash. If it is then its element at the position +INDEX_KEY will be the resulting hash element's key. Otherwise the +element is assumed to be a blessed reference, and its INDEX_KEY +function will be called. + +The values of the resulting hash follow a similar pattern. If +VALUE_KEY is undefined then the current element itself is the new hash +element's value. If the current element is a hash then its element at +the position VALUE_KEY will be the resulting hash element's +key. Otherwise the element is assumed to be a blessed reference, and +its VALUE_KEY function will be called. + +=back + =cut diff --git a/SL/OE.pm b/SL/OE.pm index 63fcf1f06..677a78b39 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -338,7 +338,7 @@ sub save { $form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1; $form->{"marge_absolut_$i"} = $form->parse_amount($myconfig, $form->{"marge_absolut_$i"}) * 1; - + $form->{"lastcost_$i"} = $form->parse_amount($myconfig, $form->{"lastcost_$i"}); # set values to 0 if nothing entered diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index 82a988ec5..143551f74 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -14,6 +14,7 @@ use SL::Common; use SL::DBUtils; use SL::Form; use SL::MoreCommon; +use SL::Helper::Flash; use strict; diff --git a/css/lx-office-erp.css b/css/lx-office-erp.css index 202bd179e..8151719df 100644 --- a/css/lx-office-erp.css +++ b/css/lx-office-erp.css @@ -288,3 +288,27 @@ label { height:0; visibility:hidden; } + +.flash_message_error { + background-color:#FFD6D6; + border: 1px solid #AE0014; + margin-top: 5px; + margin-bottom: 5px; + padding: 5px; +} + +.flash_message_warning { + background-color:#FFE8C7; + border: 1px solid #FF6600; + margin-top: 5px; + margin-bottom: 5px; + padding: 5px; +} + +.flash_message_info { + background-color:#DCF2FF; + border: 1px solid #4690FF; + margin-top: 5px; + margin-bottom: 5px; + padding: 5px; +} diff --git a/locale/de/all b/locale/de/all index 1333b2658..f00c0307f 100644 --- a/locale/de/all +++ b/locale/de/all @@ -1871,6 +1871,7 @@ $self->{texts} = { 'Warehouse management' => 'Lagerverwaltung/Bestandsveränderung', 'Warehouse saved.' => 'Lager gespeichert.', 'Warehouses' => 'Lager', + 'Warning' => 'Warnung', 'Warnings during template upgrade' => 'Warnungen bei Aktualisierung der Dokumentenvorlagen', 'WebDAV link' => 'WebDAV-Link', 'Weight' => 'Gewicht', diff --git a/templates/webpages/common/flash.html b/templates/webpages/common/flash.html new file mode 100644 index 000000000..b7164fb92 --- /dev/null +++ b/templates/webpages/common/flash.html @@ -0,0 +1,21 @@ +[%- USE HTML -%][%- USE LxERP %] +[%- IF FLASH %] + [%- BLOCK output %] +
+ [%- title %]: + [% FOREACH message = messages %] + [%- HTML.escape(message) %] + [%- UNLESS loop.last %]
[% END %] + [%- END %] +
+ [%- END %] + [%- IF FLASH.error && FLASH.error.size %] + [%- PROCESS output title=LxERP.t8('Error') type='error' messages = FLASH.error %] + [%- END %] + [%- IF FLASH.warning && FLASH.warning.size %] + [%- PROCESS output title=LxERP.t8('Warning') type='warning' messages = FLASH.warning %] + [%- END %] + [%- IF FLASH.info && FLASH.info.size %] + [%- PROCESS output title=LxERP.t8('Information') type='info' messages = FLASH.info %] + [%- END %] +[%- END %] diff --git a/templates/webpages/do/form_header.html b/templates/webpages/do/form_header.html index 2410439c3..29f8ad97f 100644 --- a/templates/webpages/do/form_header.html +++ b/templates/webpages/do/form_header.html @@ -50,6 +50,8 @@
[% title %]
+[%- INCLUDE 'common/flash.html' %] + [%- IF ERRORS && ERRORS.size %]

[% ERRORS.join('
') %]

[%- END %] diff --git a/templates/webpages/ir/form_header.html b/templates/webpages/ir/form_header.html index c0260e861..63d514072 100644 --- a/templates/webpages/ir/form_header.html +++ b/templates/webpages/ir/form_header.html @@ -26,6 +26,8 @@

[% title %]

+[%- INCLUDE 'common/flash.html' %] +
diff --git a/templates/webpages/is/form_header.html b/templates/webpages/is/form_header.html index 919f37b66..a6c21975b 100644 --- a/templates/webpages/is/form_header.html +++ b/templates/webpages/is/form_header.html @@ -26,6 +26,8 @@

[% saved_message %]

+[%- INCLUDE 'common/flash.html' %] +
diff --git a/templates/webpages/oe/form_header.html b/templates/webpages/oe/form_header.html index 0bd60026e..87555df39 100644 --- a/templates/webpages/oe/form_header.html +++ b/templates/webpages/oe/form_header.html @@ -25,6 +25,8 @@
[% title %]
+[%- INCLUDE 'common/flash.html' %] +