Merge branch 'master' of ssh://lx-office/~/lx-office-erp
authorSven Schöling <s.schoeling@linet-services.de>
Thu, 30 Dec 2010 15:04:19 +0000 (16:04 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 30 Dec 2010 15:04:19 +0000 (16:04 +0100)
14 files changed:
SL/DB/Employee.pm
SL/DB/Manager/Employee.pm [new file with mode: 0644]
SL/Dispatcher.pm
SL/Helper/Flash.pm [new file with mode: 0644]
SL/MoreCommon.pm
SL/OE.pm
bin/mozilla/common.pl
css/lx-office-erp.css
locale/de/all
templates/webpages/common/flash.html [new file with mode: 0644]
templates/webpages/do/form_header.html
templates/webpages/ir/form_header.html
templates/webpages/is/form_header.html
templates/webpages/oe/form_header.html

index 841696b..1ef565e 100644 (file)
@@ -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 (file)
index 0000000..e52eebb
--- /dev/null
@@ -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;
index 35284db..013dfe6 100644 (file)
@@ -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 (file)
index 0000000..e599f6e
--- /dev/null
@@ -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<information>,
+C<warning> or C<error>. 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<render_flash>
+or by including the flash sub-template from a template with the
+following code:
+
+  [%- INCLUDE 'common/flash.html' %]
+
+=head1 EXPORTS
+
+The functions L</flash> and L</flash_later> are always exported.
+
+The function L</render_flash> is only exported upon request.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<flash $category, @messages>
+
+Stores messages for the given category. The category can be either
+C<information>, C<warning> or C<error>. C<info> can also be used as an
+alias for C<information>.
+
+=item C<flash_later $category, @messages>
+
+Stores messages for the given category for the next request. The
+category can be either C<information>, C<warning> or C<error>. C<info>
+can also be used as an alias for C<information>.
+
+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<render_flash>
+
+Outputs the flash message by parsing the C<common/flash.html> template
+file.
+
+This function is not exported by default.
+
+=back
+
+=head1 AUTHOR
+
+Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
+
+=cut
index 0d5413b..8f64861 100644 (file)
@@ -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
index 63fcf1f..677a78b 100644 (file)
--- 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
index 82a988e..143551f 100644 (file)
@@ -14,6 +14,7 @@ use SL::Common;
 use SL::DBUtils;
 use SL::Form;
 use SL::MoreCommon;
+use SL::Helper::Flash;
 
 use strict;
 
index 202bd17..8151719 100644 (file)
@@ -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;
+}
index 1333b26..f00c030 100644 (file)
@@ -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 (file)
index 0000000..b7164fb
--- /dev/null
@@ -0,0 +1,21 @@
+[%- USE HTML -%][%- USE LxERP %]
+[%- IF FLASH %]
+ [%- BLOCK output %]
+  <div class="flash_message_[% type %]">
+   [%- title %]:
+   [% FOREACH message = messages %]
+    [%- HTML.escape(message) %]
+    [%- UNLESS loop.last %]<br>[% END %]
+   [%- END %]
+  </div>
+ [%- 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 %]
index 2410439..29f8ad9 100644 (file)
@@ -50,6 +50,8 @@
 
  <div class="listtop">[% title %]</div>
 
+[%- INCLUDE 'common/flash.html' %]
+
  [%- IF ERRORS && ERRORS.size %]
  <p><font color="#ff0000">[% ERRORS.join('<br>') %]</font></p>
  [%- END %]
index c0260e8..63d5140 100644 (file)
@@ -26,6 +26,8 @@
 
 <p><div class="listtop" width="100%">[% title %]</div></p>
 
+[%- INCLUDE 'common/flash.html' %]
+
 <table width="100%">
   <tr>
     <td valign="top">
index 919f37b..a6c2197 100644 (file)
@@ -26,6 +26,8 @@
 
 <p>[% saved_message %]</p>
 
+[%- INCLUDE 'common/flash.html' %]
+
 <table width="100%">
   <tr>
     <td valign="top">
index 0bd6002..87555df 100644 (file)
@@ -25,6 +25,8 @@
 
     <div class="listtop">[% title %]</div>
 
+[%- INCLUDE 'common/flash.html' %]
+
     <table width="100%">
       <tr height="5"></tr>
       <tr>