From: Moritz Bunkus Date: Wed, 12 Jun 2013 09:44:33 +0000 (+0200) Subject: Druckerverwaltung auf Admin-Controller umgestellt X-Git-Tag: release-3.1.0beta1~331^2~39 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=8b34d2951ae9a949476331eb5b8f6249df616b5b;p=kivitendo-erp.git Druckerverwaltung auf Admin-Controller umgestellt --- diff --git a/SL/Controller/Admin.pm b/SL/Controller/Admin.pm index 6f9d2249a..357d7b711 100644 --- a/SL/Controller/Admin.pm +++ b/SL/Controller/Admin.pm @@ -5,19 +5,23 @@ use strict; use parent qw(SL::Controller::Base); use IO::File; +use List::Util qw(first); use SL::DB::AuthUser; use SL::DB::AuthGroup; +use SL::DB::Printer; use SL::Helper::Flash; use SL::Locale::String qw(t8); use SL::User; use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(client user group nologin_file_name db_cfg all_dateformats all_numberformats all_countrycodes all_stylesheets all_menustyles all_clients all_groups all_users all_rights is_locked) ], + 'scalar --get_set_init' => [ qw(client user group printer nologin_file_name db_cfg is_locked + all_dateformats all_numberformats all_countrycodes all_stylesheets all_menustyles all_clients all_groups all_users all_rights all_printers) ], ); __PACKAGE__->run_before(\&setup_layout); +__PACKAGE__->run_before(\&setup_client, only => [ qw(list_printers new_printer edit_printer save_printer delete_printer) ]); sub get_auth_level { "admin" }; sub keep_auth_vars { @@ -290,6 +294,61 @@ sub action_delete_group { $self->redirect_to(action => 'show'); } +# +# actions: printers +# + +sub action_list_printers { + my ($self) = @_; + $self->render('admin/list_printers', title => t8('Printer management')); +} + +sub action_new_printer { + my ($self) = @_; + + $self->printer(SL::DB::Printer->new); + $self->edit_printer_form(title => t8('Create a new printer')); +} + +sub action_edit_printer { + my ($self) = @_; + $self->edit_printer_form(title => t8('Edit Printer')); +} + +sub action_save_printer { + my ($self) = @_; + my $params = delete($::form->{printer}) || { }; + my $is_new = !$params->{id}; + + $self->printer($is_new ? SL::DB::Printer->new : SL::DB::Printer->new(id => $params->{id})->load)->assign_attributes(%{ $params }); + + my @errors = $self->printer->validate; + + if (@errors) { + flash('error', @errors); + $self->edit_printer_form(title => $is_new ? t8('Create a new printer') : t8('Edit Printer')); + return; + } + + $self->printer->save; + + flash_later('info', $is_new ? t8('The printer has been created.') : t8('The printer has been saved.')); + $self->redirect_to(action => 'list_printers', 'client.id' => $self->client->id); +} + +sub action_delete_printer { + my ($self) = @_; + + if (!$self->printer->delete) { + flash('error', t8('The printer could not be deleted.')); + $self->edit_printer_form(title => t8('Edit Printer')); + return; + } + + flash_later('info', t8('The printer has been deleted.')); + $self->redirect_to(action => 'list_printers', 'client.id' => $self->client->id); +} + # # actions: locking, unlocking # @@ -319,18 +378,20 @@ sub action_lock_system { # initializers # -sub init_db_cfg { $::lx_office_conf{'authentication/database'} } -sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin'; } -sub init_is_locked { -e $_[0]->nologin_file_name } -sub init_client { SL::DB::AuthClient->new(id => ($::form->{id} || ($::form->{client} || {})->{id}))->load } -sub init_user { SL::DB::AuthUser ->new(id => ($::form->{id} || ($::form->{user} || {})->{id}))->load } -sub init_group { SL::DB::AuthGroup ->new(id => ($::form->{id} || ($::form->{group} || {})->{id}))->load } -sub init_all_clients { SL::DB::Manager::AuthClient->get_all_sorted } -sub init_all_users { SL::DB::Manager::AuthUser->get_all_sorted } -sub init_all_groups { SL::DB::Manager::AuthGroup->get_all_sorted } -sub init_all_dateformats { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ] } -sub init_all_numberformats { [ qw(1,000.00 1000.00 1.000,00 1000,00) ] } -sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ] } +sub init_db_cfg { $::lx_office_conf{'authentication/database'} } +sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin'; } +sub init_is_locked { -e $_[0]->nologin_file_name } +sub init_client { SL::DB::Manager::AuthClient->find_by(id => ($::form->{id} || ($::form->{client} || {})->{id})) } +sub init_user { SL::DB::AuthUser ->new(id => ($::form->{id} || ($::form->{user} || {})->{id}))->load } +sub init_group { SL::DB::AuthGroup ->new(id => ($::form->{id} || ($::form->{group} || {})->{id}))->load } +sub init_printer { SL::DB::Printer ->new(id => ($::form->{id} || ($::form->{printer} || {})->{id}))->load } +sub init_all_clients { SL::DB::Manager::AuthClient->get_all_sorted } +sub init_all_users { SL::DB::Manager::AuthUser ->get_all_sorted } +sub init_all_groups { SL::DB::Manager::AuthGroup ->get_all_sorted } +sub init_all_printers { SL::DB::Manager::Printer ->get_all_sorted } +sub init_all_dateformats { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ] } +sub init_all_numberformats { [ qw(1,000.00 1000.00 1.000,00 1000,00) ] } +sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ] } sub init_all_menustyles { return [ { id => 'old', title => $::locale->text('Old (on the side)') }, @@ -377,6 +438,14 @@ sub setup_layout { $::form->{favicon} = "favicon.ico"; } +sub setup_client { + my ($self) = @_; + + $self->client((first { $_->is_default } @{ $self->all_clients }) || $self->all_clients->[0]) if !$self->client; + $::auth->set_client($self->client->id); +} + + # # displaying forms # @@ -409,6 +478,11 @@ sub edit_group_form { $self->use_multiselect_js->render('admin/edit_group', %params); } +sub edit_printer_form { + my ($self, %params) = @_; + $self->render('admin/edit_printer', %params); +} + # # helpers # diff --git a/SL/DB/Manager/Printer.pm b/SL/DB/Manager/Printer.pm new file mode 100644 index 000000000..ec1e8319c --- /dev/null +++ b/SL/DB/Manager/Printer.pm @@ -0,0 +1,20 @@ +package SL::DB::Manager::Printer; + +use strict; + +use SL::DB::Helper::Manager; +use base qw(SL::DB::Helper::Manager); + +use SL::DB::Helper::Paginated; +use SL::DB::Helper::Sorted; + +sub object_class { 'SL::DB::Printer' } + +__PACKAGE__->make_manager_methods; + +sub _sort_spec { + return ( default => [ 'printer_description', 1 ], + columns => { SIMPLE => 'ALL' } ); +} + +1; diff --git a/SL/DB/Printer.pm b/SL/DB/Printer.pm index fd58eb55c..83f914806 100644 --- a/SL/DB/Printer.pm +++ b/SL/DB/Printer.pm @@ -3,11 +3,22 @@ package SL::DB::Printer; use strict; use SL::DB::MetaSetup::Printer; - -__PACKAGE__->meta->make_manager_class; +use SL::DB::Manager::Printer; +use SL::DB::Helper::Util; sub description { goto &printer_description; } +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The description is missing.') if !$self->printer_description; + push @errors, $::locale->text('The command is missing.') if !$self->printer_command; + push @errors, $::locale->text('The description is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'printer_description'); + + return @errors; +} + 1; diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index e0694762e..20f901b0a 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -60,7 +60,6 @@ use SL::DBUtils; use SL::Template; require "bin/mozilla/common.pl"; -require "bin/mozilla/admin_printer.pl"; use strict; diff --git a/bin/mozilla/admin_printer.pl b/bin/mozilla/admin_printer.pl deleted file mode 100644 index 9d514b3c8..000000000 --- a/bin/mozilla/admin_printer.pl +++ /dev/null @@ -1,117 +0,0 @@ -use strict; - -use SL::Printer; - -sub get_login { - unless ($::form->{login}) { - get_login_form(); - ::end_of_request(); - } - return $::form->{login}; -} - -sub get_login_form { - my %users = $::auth->read_all_users; - - $::form->header; - print $::form->parse_html_template('admin_printer/login', { - users => [ values %users ], - }); -} - -sub printer_dispatcher { - for my $action (qw(get_login_form list_printers add_printer edit_printer save_printer delete_printer)) { - if ($::form->{$action}) { - ::call_sub($::locale->findsub($action)); - ::end_of_request() - } - } - die "cannot find sub"; -} - -sub printer_management { - &get_login_form; -} - -sub add_printer { - $::lxdebug->enter_sub; - - my $login = get_login(); - my %users = $::auth->read_all_users; - - $::form->header; - print $::form->parse_html_template('admin_printer/edit', { - title => $::locale->text("Add Printer"), - printer => { }, - users => [ values %users ], - }); - - $::lxdebug->leave_sub -} - -sub edit_printer { - $::lxdebug->enter_sub; - - my $login = get_login(); - my $id = $::form->{id} or $::form->{printer}{id} or &add_printer; - my %users = $::auth->read_all_users; - - my $printer = SL::Printer->get_printer(id => $id, login => $login); - - $::form->header; - print $::form->parse_html_template('admin_printer/edit', { - title => $::locale->text("Edit Printer"), - printer => $printer, - users => [ values %users ], - }); - - $::lxdebug->leave_sub; -} - -sub list_printers { - $::lxdebug->enter_sub; - - my $login = get_login(); - my $printers = SL::Printer->all_printers(login => $login); - my %users = $::auth->read_all_users; - - $::form->header; - print $::form->parse_html_template('admin_printer/list', { - title => $::locale->text('Printer'), - all_printers => $printers, - edit_link => build_std_url("login=$login", 'action=edit_printer', 'id='), - users => [ values %users ], - }); - - $::lxdebug->leave_sub; -} - - -sub save_printer { - $::lxdebug->enter_sub; - - my $login = get_login(); - my $printer = $::form->{printer} || die 'no printer to save'; - - $::form->error($::locale->text('Description missing!')) unless $printer->{printer_description}; - $::form->error($::locale->text('Printer Command missing!')) unless $printer->{printer_command}; - - SL::Printer->save_printer(%$::form); - - list_printers(); - $::lxdebug->leave_sub; -} - -sub delete_printer { - $::lxdebug->enter_sub; - - my $login = get_login(); - my $printer = $::form->{printer} || die 'no printer to delete'; - - SL::Printer->delete_printer(%$::form); - list_printers(); - - $::lxdebug->leave_sub; -} - -1; diff --git a/templates/webpages/admin/edit_printer.html b/templates/webpages/admin/edit_printer.html new file mode 100644 index 000000000..8e2f5a224 --- /dev/null +++ b/templates/webpages/admin/edit_printer.html @@ -0,0 +1,35 @@ +[%- USE LxERP -%][%- USE HTML -%][%- USE L -%] + +[% INCLUDE 'common/flash.html' %] + +

[% HTML.escape(title) %]

+ +
+ [% L.hidden_tag("client.id", SELF.client.id) %] + [% L.hidden_tag("action", 'Admin/dispatch') %] + [% L.hidden_tag("printer.id", SELF.printer.id) %] + + + + + + + + + + + + + + +
[% LxERP.t8('Printer Description') %][% L.input_tag("printer.printer_description", SELF.printer.printer_description, size=30) %]
[% LxERP.t8('Printer Command') %][% L.input_tag("printer.printer_command", SELF.printer.printer_command, size=30) %]
[% LxERP.t8('Template Code') %][% L.input_tag("printer.template_code", SELF.printer.template_code, size=8) %]
+ +

+ [% LxERP.t8("Back") %] + [% L.submit_tag("action_save_printer", LxERP.t8("Save")) %] + [%- IF SELF.printer.id %] + [% L.submit_tag("action_delete_printer", LxERP.t8("Delete"), confirm=LxERP.t8("Are you sure?")) %] + [%- END %] +

+ +
diff --git a/templates/webpages/admin/list_printers.html b/templates/webpages/admin/list_printers.html new file mode 100644 index 000000000..4da7effa8 --- /dev/null +++ b/templates/webpages/admin/list_printers.html @@ -0,0 +1,70 @@ +[%- USE HTML -%][%- USE LxERP -%][%- USE L -%] + +[% INCLUDE 'common/flash.html' %] + +

[% HTML.escape(title) %]

+ +[% IF !SELF.all_clients.size %] +
+ [% LxERP.t8("Error") %]: + [% LxERP.t8("No clients have been created yet.") %] +
+ +
+ [% LxERP.t8("Back") %] +
+ +[%- ELSE %] + +
+ [% LxERP.t8("Actions") %]: + + [% LxERP.t8("Back") %] + | + [% LxERP.t8("Add printer") %] +
+ +
+ +

+ [% LxERP.t8("Client to configure the printers for") %]: + [% L.select_tag('client.id', SELF.all_clients, id='client_id', title_key='name', default=SELF.client.id) %] +

+ + [%- IF !SELF.all_printers.size %] + +

+ [% LxERP.t8("No printers have been created yet.") %] +

+ + [%- ELSE %] + + + + + + + + + [%- FOREACH printer = SELF.all_printers %] + + + + + + [%- END %] +
[% LxERP.t8('Description') %][% LxERP.t8('Printer Command') %][% LxERP.t8('Template Code') %]
[% HTML.escape(printer.printer_description) %][% HTML.escape(printer.printer_command) %][% HTML.escape(printer.template_code) %]
+ + [%- END %] + + + +[%- END %] diff --git a/templates/webpages/admin/show.html b/templates/webpages/admin/show.html index 734deaebd..e046518de 100644 --- a/templates/webpages/admin/show.html +++ b/templates/webpages/admin/show.html @@ -15,7 +15,7 @@ | [% L.link(SELF.url_for(action="pg_database_administration", controller="admin.pl"), LxERP.t8("Pg Database Administration")) %] | - [% L.link(SELF.url_for(action="printer_management", controller="admin.pl"), LxERP.t8("Printer Management")) %] + [% L.link(SELF.url_for(action="list_printers"), LxERP.t8("Printer Management")) %] | [% IF SELF.is_locked %] [% L.link(SELF.url_for(action="unlock_system"), LxERP.t8("Unlock System")) %] diff --git a/templates/webpages/admin_printer/_login_form.html b/templates/webpages/admin_printer/_login_form.html deleted file mode 100644 index 4789d1294..000000000 --- a/templates/webpages/admin_printer/_login_form.html +++ /dev/null @@ -1,4 +0,0 @@ -[%- USE T8 %] -[%- USE L %] -

[% 'Please select a user' | $T8 %]: [% L.select_tag('login', users, value_key = 'login', title_key = 'login', default = login) %]

- diff --git a/templates/webpages/admin_printer/edit.html b/templates/webpages/admin_printer/edit.html deleted file mode 100644 index 7aef54db9..000000000 --- a/templates/webpages/admin_printer/edit.html +++ /dev/null @@ -1,38 +0,0 @@ -[%- USE T8 %] - -
- -

[% title %]

- -[%- PROCESS 'admin_printer/_login_form.html' %] - - - - - - - - - - - - - - - - - - -
[% 'Printer' | $T8 %]
[% 'Printer Command' | $T8 %]
[% 'Template Code' | $T8 %]

- -
- - - - -[%- IF id %] - -[%- END %] - -
- diff --git a/templates/webpages/admin_printer/list.html b/templates/webpages/admin_printer/list.html deleted file mode 100644 index 6a413d853..000000000 --- a/templates/webpages/admin_printer/list.html +++ /dev/null @@ -1,41 +0,0 @@ -[%- USE T8 %] - -
- -

[% title %]

- -[%- PROCESS 'admin_printer/_login_form.html' %] - - - - - - - - -
- - - - - - -[%- IF all_printers.size %] -[%- FOREACH row = all_printers %] - - - - - -[%- END %] -[%- ELSE %] - -[%- END %] -
[% 'Description' | $T8 %][% 'Printer Command' | $T8 %][% 'Template Code' | $T8 %]
 [% row.printer_description %] [% row.printer_command | html %] [% row.template_code | html %]

[% 'No data was found.' | $T8 %]

-

- -
- - - -
diff --git a/templates/webpages/admin_printer/login.html b/templates/webpages/admin_printer/login.html deleted file mode 100644 index 7ddee95ea..000000000 --- a/templates/webpages/admin_printer/login.html +++ /dev/null @@ -1,16 +0,0 @@ -[% USE T8 %] -[% USE L %] - -

[% 'Printer Management' | $T8 %]

-
-

[% 'Printers are created for a user database. Please select a user. The associated database will be edited.' | $T8 %]

- -[%- PROCESS 'admin_printer/_login_form.html' %] - - -

- [% 'Back' | $T8 %] - -

- -