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
#
SL/DB/Manager/Printer.pm
1
package SL::DB::Manager::Printer;
2

  
3
use strict;
4

  
5
use SL::DB::Helper::Manager;
6
use base qw(SL::DB::Helper::Manager);
7

  
8
use SL::DB::Helper::Paginated;
9
use SL::DB::Helper::Sorted;
10

  
11
sub object_class { 'SL::DB::Printer' }
12

  
13
__PACKAGE__->make_manager_methods;
14

  
15
sub _sort_spec {
16
  return ( default => [ 'printer_description', 1 ],
17
           columns => { SIMPLE => 'ALL' } );
18
}
19

  
20
1;
SL/DB/Printer.pm
3 3
use strict;
4 4

  
5 5
use SL::DB::MetaSetup::Printer;
6

  
7
__PACKAGE__->meta->make_manager_class;
6
use SL::DB::Manager::Printer;
7
use SL::DB::Helper::Util;
8 8

  
9 9
sub description {
10 10
  goto &printer_description;
11 11
}
12 12

  
13
sub validate {
14
  my ($self) = @_;
15

  
16
  my @errors;
17
  push @errors, $::locale->text('The description is missing.')    if !$self->printer_description;
18
  push @errors, $::locale->text('The command is missing.')        if !$self->printer_command;
19
  push @errors, $::locale->text('The description is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'printer_description');
20

  
21
  return @errors;
22
}
23

  
13 24
1;
bin/mozilla/admin.pl
60 60
use SL::Template;
61 61

  
62 62
require "bin/mozilla/common.pl";
63
require "bin/mozilla/admin_printer.pl";
64 63

  
65 64
use strict;
66 65

  
bin/mozilla/admin_printer.pl
1
use strict;
2

  
3
use SL::Printer;
4

  
5
sub get_login {
6
  unless ($::form->{login}) {
7
    get_login_form();
8
    ::end_of_request();
9
  }
10
  return $::form->{login};
11
}
12

  
13
sub get_login_form {
14
  my %users = $::auth->read_all_users;
15

  
16
  $::form->header;
17
  print $::form->parse_html_template('admin_printer/login', {
18
    users => [ values %users ],
19
  });
20
}
21

  
22
sub printer_dispatcher {
23
  for my $action (qw(get_login_form list_printers add_printer edit_printer save_printer delete_printer)) {
24
    if ($::form->{$action}) {
25
      ::call_sub($::locale->findsub($action));
26
      ::end_of_request()
27
    }
28
  }
29
  die "cannot find sub";
30
}
31

  
32
sub printer_management {
33
  &get_login_form;
34
}
35

  
36
sub add_printer {
37
  $::lxdebug->enter_sub;
38

  
39
  my $login   = get_login();
40
  my %users   = $::auth->read_all_users;
41

  
42
  $::form->header;
43
  print $::form->parse_html_template('admin_printer/edit', {
44
    title   => $::locale->text("Add Printer"),
45
    printer => { },
46
    users   => [ values %users ],
47
  });
48

  
49
  $::lxdebug->leave_sub
50
}
51

  
52
sub edit_printer {
53
  $::lxdebug->enter_sub;
54

  
55
  my $login = get_login();
56
  my $id    = $::form->{id} or $::form->{printer}{id} or &add_printer;
57
  my %users   = $::auth->read_all_users;
58

  
59
  my $printer = SL::Printer->get_printer(id => $id, login => $login);
60

  
61
  $::form->header;
62
  print $::form->parse_html_template('admin_printer/edit', {
63
    title   => $::locale->text("Edit Printer"),
64
    printer => $printer,
65
    users   => [ values %users ],
66
  });
67

  
68
  $::lxdebug->leave_sub;
69
}
70

  
71
sub list_printers {
72
  $::lxdebug->enter_sub;
73

  
74
  my $login    = get_login();
75
  my $printers = SL::Printer->all_printers(login => $login);
76
  my %users   = $::auth->read_all_users;
77

  
78
  $::form->header;
79
  print $::form->parse_html_template('admin_printer/list', {
80
    title        => $::locale->text('Printer'),
81
    all_printers => $printers,
82
    edit_link    => build_std_url("login=$login", 'action=edit_printer', 'id='),
83
    users        => [ values %users ],
84
  });
85

  
86
  $::lxdebug->leave_sub;
87
}
88

  
89

  
90
sub save_printer {
91
  $::lxdebug->enter_sub;
92

  
93
  my $login   = get_login();
94
  my $printer = $::form->{printer} || die 'no printer to save';
95

  
96
  $::form->error($::locale->text('Description missing!'))     unless $printer->{printer_description};
97
  $::form->error($::locale->text('Printer Command missing!')) unless $printer->{printer_command};
98

  
99
  SL::Printer->save_printer(%$::form);
100

  
101
  list_printers();
102
  $::lxdebug->leave_sub;
103
}
104

  
105
sub delete_printer {
106
  $::lxdebug->enter_sub;
107

  
108
  my $login   = get_login();
109
  my $printer = $::form->{printer} || die 'no printer to delete';
110

  
111
  SL::Printer->delete_printer(%$::form);
112
  list_printers();
113

  
114
  $::lxdebug->leave_sub;
115
}
116

  
117
1;
templates/webpages/admin/edit_printer.html
1
[%- USE LxERP -%][%- USE HTML -%][%- USE L -%]
2

  
3
[% INCLUDE 'common/flash.html' %]
4

  
5
<h1>[% HTML.escape(title) %]</h1>
6

  
7
<form method="post">
8
 [% L.hidden_tag("client.id", SELF.client.id) %]
9
 [% L.hidden_tag("action", 'Admin/dispatch') %]
10
 [% L.hidden_tag("printer.id", SELF.printer.id) %]
11

  
12
 <table>
13
  <tr>
14
   <th align="right">[% LxERP.t8('Printer Description') %]</th>
15
   <td>[% L.input_tag("printer.printer_description", SELF.printer.printer_description, size=30) %]</td>
16
  <tr>
17
  <tr>
18
   <th align="right">[% LxERP.t8('Printer Command') %]</th>
19
   <td>[% L.input_tag("printer.printer_command", SELF.printer.printer_command, size=30) %]</td>
20
  </tr>
21
  <tr>
22
   <th align="right">[% LxERP.t8('Template Code') %]</th>
23
   <td>[% L.input_tag("printer.template_code", SELF.printer.template_code, size=8) %]</td>
24
  </tr>
25
 </table>
26

  
27
 <p>
28
  <a href="[% SELF.url_for(action='list_printers', 'client.id'=SELF.client.id) %]">[% LxERP.t8("Back") %]</a>
29
  [% L.submit_tag("action_save_printer", LxERP.t8("Save")) %]
30
  [%- IF SELF.printer.id %]
31
   [% L.submit_tag("action_delete_printer", LxERP.t8("Delete"), confirm=LxERP.t8("Are you sure?")) %]
32
 [%- END %]
33
 </p>
34

  
35
</form>
templates/webpages/admin/list_printers.html
1
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%]
2

  
3
[% INCLUDE 'common/flash.html' %]
4

  
5
<h1>[% HTML.escape(title) %]</h1>
6

  
7
[% IF !SELF.all_clients.size %]
8
<div class="error">
9
 [% LxERP.t8("Error") %]:
10
 [% LxERP.t8("No clients have been created yet.") %]
11
</div>
12

  
13
<div>
14
 <a href="[% SELF.url_for(action='show') %]">[% LxERP.t8("Back") %]</a>
15
</div>
16

  
17
[%- ELSE %]
18

  
19
 <div>
20
  [% LxERP.t8("Actions") %]:
21
  <span class="link_separator"></span>
22
  <a href="[% SELF.url_for(action='show') %]">[% LxERP.t8("Back") %]</a>
23
  <span class="link_separator">|</span>
24
  <a href="[% SELF.url_for(action='new_printer', 'client.id'=SELF.client.id) %]">[% LxERP.t8("Add printer") %]</a>
25
 </div>
26

  
27
 <hr>
28

  
29
 <p>
30
  [% LxERP.t8("Client to configure the printers for") %]:
31
  [% L.select_tag('client.id', SELF.all_clients, id='client_id', title_key='name', default=SELF.client.id) %]
32
 </p>
33

  
34
 [%- IF !SELF.all_printers.size %]
35

  
36
  <p>
37
   [% LxERP.t8("No printers have been created yet.") %]
38
  </p>
39

  
40
 [%- ELSE %]
41

  
42
  <table width="100%">
43
   <tr class="listheading">
44
    <th>[% LxERP.t8('Description') %]</th>
45
    <th>[% LxERP.t8('Printer Command') %]</th>
46
    <th>[% LxERP.t8('Template Code') %]</th>
47
   </tr>
48

  
49
   [%- FOREACH printer = SELF.all_printers %]
50
    <tr valign="top" class="listrow">
51
     <td><a href="[% SELF.url_for(action='edit_printer', 'client.id'=SELF.client.id, id=printer.id) %]">[% HTML.escape(printer.printer_description) %]</a></td>
52
     <td>[% HTML.escape(printer.printer_command) %]</td>
53
     <td>[% HTML.escape(printer.template_code) %]</td>
54
    </tr>
55
   [%- END %]
56
  </table>
57

  
58
 [%- END %]
59

  
60
 <script type="text/javascript">
61
<!--
62
  $(function() {
63
    $('#client_id').change(function() {
64
      window.location.href = "controller.pl?action=Admin/list_printers&client.id=" + $('#client_id').val();
65
    });
66
  });
67
-->
68
 </script>
69

  
70
[%- END %]
templates/webpages/admin/show.html
15 15
 <span class="link_separator">|</span>
16 16
 [% L.link(SELF.url_for(action="pg_database_administration", controller="admin.pl"), LxERP.t8("Pg Database Administration")) %]
17 17
 <span class="link_separator">|</span>
18
 [% L.link(SELF.url_for(action="printer_management", controller="admin.pl"), LxERP.t8("Printer Management")) %]
18
 [% L.link(SELF.url_for(action="list_printers"), LxERP.t8("Printer Management")) %]
19 19
 <span class="link_separator">|</span>
20 20
 [% IF SELF.is_locked %]
21 21
  [% L.link(SELF.url_for(action="unlock_system"), LxERP.t8("Unlock System")) %]
templates/webpages/admin_printer/_login_form.html
1
[%- USE T8 %]
2
[%- USE L %]
3
<p>[% 'Please select a user' | $T8 %]: [% L.select_tag('login', users, value_key = 'login', title_key = 'login', default = login) %]</p>
4

  
templates/webpages/admin_printer/edit.html
1
[%- USE T8 %]
2

  
3
<form method=post>
4

  
5
<h1 class=listtop colspan=2>[% title %]</h1>
6

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

  
9
<input type=hidden name="printer.id" value="[% printer.id | html %]">
10
<table width=100%>
11
  <tr height="5"></tr>
12
  <tr>
13
    <th align=left>[% 'Printer' | $T8 %]</th>
14
    <td><input name="printer.printer_description" size=30 value="[% printer.printer_description | html %]"></td>
15
  <tr>
16
  <tr>
17
    <th align=left>[% 'Printer Command' | $T8 %]</th>
18
    <td><input name="printer.printer_command" size=30 value="[% printer.printer_command | html %]"></td>
19
  </tr>
20
  <tr>
21
    <th align=left>[% 'Template Code' | $T8 %]</th>
22
    <td><input name="printer.template_code" size=5 value="[% printer.template_code | html %]"></td>
23
  </tr>
24
  <td colspan=2><hr size=3 noshade></td>
25
  </tr>
26
</table>
27

  
28
<br>
29
<input type=hidden name=action value="printer_dispatcher">
30
<input type=submit class=submit name=list_printers value="[% 'Back' | $T8 %]">
31
<input type=submit class=submit name=save_printer value="[% 'Save' | $T8 %]">
32

  
33
[%- IF id %]
34
<input type=submit class=submit name=delete_printer value="[% 'Delete' | $T8 %]">
35
[%- END %]
36

  
37
</form>
38

  
templates/webpages/admin_printer/list.html
1
[%- USE T8 %]
2

  
3
<form method='post'>
4

  
5
<h1 class=listtop>[% title %]</h1>
6

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

  
9
<table width=100%>
10
  <tr>
11
    <td>
12
      <table width=100%>
13
        <tr class=listheading>
14
          <th>[% 'Description' | $T8 %]</th>
15
          <th>[% 'Printer Command' | $T8 %]</th>
16
          <th>[% 'Template Code' | $T8 %]</th>
17
        </tr>
18
[%- IF all_printers.size %]
19
[%- FOREACH row = all_printers %]
20
        <tr valign=top class="listrow[% loop.count % 2 %]">
21
          <td>&nbsp;<a href="[% edit_link %][% row.id %]">[% row.printer_description %]</a></td>
22
          <td align=left>&nbsp;[% row.printer_command | html %]</td>
23
          <td align=left>&nbsp;[% row.template_code | html %]</td>
24
        </tr>
25
[%- END %]
26
[%- ELSE %]
27
        <tr><td colspan='3'><p class="message_hint">[% 'No data was found.' | $T8 %]</p></td></tr>
28
[%- END %]
29
      </table>
30
    </td>
31
  </tr>
32
  <tr>
33
  <td><hr size=3 noshade></td>
34
  </tr>
35
</table>
36

  
37
<br>
38
 <input type="hidden" name="action" value="printer_dispatcher">
39
 <input type="submit" name='get_login_form' value="[% 'Back' | $T8 %]">
40
 <input type="submit" name="add_printer" value ="[% 'Add' | $T8 %]">
41
</form>
templates/webpages/admin_printer/login.html
1
[% USE T8 %]
2
[% USE L %]
3

  
4
<h1 class=listtop>[% 'Printer Management' | $T8 %]</h1>
5
<form method='post'>
6
<p>[% 'Printers are created for a user database. Please select a user. The associated database will be edited.' | $T8 %]</p>
7

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

  
10
<input type='hidden' name='action' value='printer_dispatcher'>
11
<p>
12
 <a href="controller.pl?action=Admin/show">[% 'Back' | $T8 %]</a>
13
<input type='submit' name='list_printers' value='[% 'Continue' | $T8 %]'>
14
</p>
15

  
16
</form>

Auch abrufbar als: Unified diff