Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8b34d295

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 8b34d2951ae9a949476331eb5b8f6249df616b5b
  • Vorgänger 3772d03a
  • Nachfolger f4800c43

Druckerverwaltung auf Admin-Controller umgestellt

Unterschiede anzeigen:

SL/Controller/Admin.pm
5 5
use parent qw(SL::Controller::Base);
6 6

  
7 7
use IO::File;
8
use List::Util qw(first);
8 9

  
9 10
use SL::DB::AuthUser;
10 11
use SL::DB::AuthGroup;
12
use SL::DB::Printer;
11 13
use SL::Helper::Flash;
12 14
use SL::Locale::String qw(t8);
13 15
use SL::User;
14 16

  
15 17
use Rose::Object::MakeMethods::Generic
16 18
(
17
  '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) ],
19
  'scalar --get_set_init' => [ qw(client user group printer nologin_file_name db_cfg is_locked
20
                                  all_dateformats all_numberformats all_countrycodes all_stylesheets all_menustyles all_clients all_groups all_users all_rights all_printers) ],
18 21
);
19 22

  
20 23
__PACKAGE__->run_before(\&setup_layout);
24
__PACKAGE__->run_before(\&setup_client, only => [ qw(list_printers new_printer edit_printer save_printer delete_printer) ]);
21 25

  
22 26
sub get_auth_level { "admin" };
23 27
sub keep_auth_vars {
......
290 294
  $self->redirect_to(action => 'show');
291 295
}
292 296

  
297
#
298
# actions: printers
299
#
300

  
301
sub action_list_printers {
302
  my ($self) = @_;
303
  $self->render('admin/list_printers', title => t8('Printer management'));
304
}
305

  
306
sub action_new_printer {
307
  my ($self) = @_;
308

  
309
  $self->printer(SL::DB::Printer->new);
310
  $self->edit_printer_form(title => t8('Create a new printer'));
311
}
312

  
313
sub action_edit_printer {
314
  my ($self) = @_;
315
  $self->edit_printer_form(title => t8('Edit Printer'));
316
}
317

  
318
sub action_save_printer {
319
  my ($self) = @_;
320
  my $params = delete($::form->{printer}) || { };
321
  my $is_new = !$params->{id};
322

  
323
  $self->printer($is_new ? SL::DB::Printer->new : SL::DB::Printer->new(id => $params->{id})->load)->assign_attributes(%{ $params });
324

  
325
  my @errors = $self->printer->validate;
326

  
327
  if (@errors) {
328
    flash('error', @errors);
329
    $self->edit_printer_form(title => $is_new ? t8('Create a new printer') : t8('Edit Printer'));
330
    return;
331
  }
332

  
333
  $self->printer->save;
334

  
335
  flash_later('info', $is_new ? t8('The printer has been created.') : t8('The printer has been saved.'));
336
  $self->redirect_to(action => 'list_printers', 'client.id' => $self->client->id);
337
}
338

  
339
sub action_delete_printer {
340
  my ($self) = @_;
341

  
342
  if (!$self->printer->delete) {
343
    flash('error', t8('The printer could not be deleted.'));
344
    $self->edit_printer_form(title => t8('Edit Printer'));
345
    return;
346
  }
347

  
348
  flash_later('info', t8('The printer has been deleted.'));
349
  $self->redirect_to(action => 'list_printers', 'client.id' => $self->client->id);
350
}
351

  
293 352
#
294 353
# actions: locking, unlocking
295 354
#
......
319 378
# initializers
320 379
#
321 380

  
322
sub init_db_cfg            { $::lx_office_conf{'authentication/database'}                                            }
323
sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin';                                     }
324
sub init_is_locked         { -e $_[0]->nologin_file_name                                                             }
325
sub init_client            { SL::DB::AuthClient->new(id => ($::form->{id} || ($::form->{client} || {})->{id}))->load }
326
sub init_user              { SL::DB::AuthUser  ->new(id => ($::form->{id} || ($::form->{user}   || {})->{id}))->load }
327
sub init_group             { SL::DB::AuthGroup ->new(id => ($::form->{id} || ($::form->{group}  || {})->{id}))->load }
328
sub init_all_clients       { SL::DB::Manager::AuthClient->get_all_sorted                                             }
329
sub init_all_users         { SL::DB::Manager::AuthUser->get_all_sorted                                               }
330
sub init_all_groups        { SL::DB::Manager::AuthGroup->get_all_sorted                                              }
331
sub init_all_dateformats   { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd)      ]                                      }
332
sub init_all_numberformats { [ qw(1,000.00 1000.00 1.000,00 1000,00)          ]                                      }
333
sub init_all_stylesheets   { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ]                                      }
381
sub init_db_cfg            { $::lx_office_conf{'authentication/database'}                                                    }
382
sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin';                                             }
383
sub init_is_locked         { -e $_[0]->nologin_file_name                                                                     }
384
sub init_client            { SL::DB::Manager::AuthClient->find_by(id => ($::form->{id} || ($::form->{client}  || {})->{id})) }
385
sub init_user              { SL::DB::AuthUser  ->new(id => ($::form->{id} || ($::form->{user}    || {})->{id}))->load        }
386
sub init_group             { SL::DB::AuthGroup ->new(id => ($::form->{id} || ($::form->{group}   || {})->{id}))->load        }
387
sub init_printer           { SL::DB::Printer   ->new(id => ($::form->{id} || ($::form->{printer} || {})->{id}))->load        }
388
sub init_all_clients       { SL::DB::Manager::AuthClient->get_all_sorted                                                     }
389
sub init_all_users         { SL::DB::Manager::AuthUser  ->get_all_sorted                                                     }
390
sub init_all_groups        { SL::DB::Manager::AuthGroup ->get_all_sorted                                                     }
391
sub init_all_printers      { SL::DB::Manager::Printer   ->get_all_sorted                                                     }
392
sub init_all_dateformats   { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd)      ]                                              }
393
sub init_all_numberformats { [ qw(1,000.00 1000.00 1.000,00 1000,00)          ]                                              }
394
sub init_all_stylesheets   { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ]                                              }
334 395
sub init_all_menustyles    {
335 396
  return [
336 397
    { id => 'old', title => $::locale->text('Old (on the side)') },
......
377 438
  $::form->{favicon} = "favicon.ico";
378 439
}
379 440

  
441
sub setup_client {
442
  my ($self) = @_;
443

  
444
  $self->client((first { $_->is_default } @{ $self->all_clients }) || $self->all_clients->[0]) if !$self->client;
445
  $::auth->set_client($self->client->id);
446
}
447

  
448

  
380 449
#
381 450
# displaying forms
382 451
#
......
409 478
  $self->use_multiselect_js->render('admin/edit_group', %params);
410 479
}
411 480

  
481
sub edit_printer_form {
482
  my ($self, %params) = @_;
483
  $self->render('admin/edit_printer', %params);
484
}
485

  
412 486
#
413 487
# helpers
414 488
#

Auch abrufbar als: Unified diff