Revision 05b30be4
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/Controller/ClientConfig.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
use parent qw(SL::Controller::Base); |
5 | 5 |
|
6 |
use File::Copy::Recursive (); |
|
6 | 7 |
use List::Util qw(first); |
7 | 8 |
|
8 | 9 |
use SL::DB::Chart; |
... | ... | |
12 | 13 |
use SL::DB::Unit; |
13 | 14 |
use SL::Helper::Flash; |
14 | 15 |
use SL::Locale::String qw(t8); |
16 |
use SL::Template; |
|
15 | 17 |
|
16 | 18 |
__PACKAGE__->run_before('check_auth'); |
17 | 19 |
|
18 | 20 |
use Rose::Object::MakeMethods::Generic ( |
19 |
'scalar --get_set_init' => [ qw(defaults all_warehouses all_weightunits all_languages all_currencies posting_options payment_options accounting_options inventory_options profit_options accounts) ], |
|
21 |
'scalar --get_set_init' => [ qw(defaults all_warehouses all_weightunits all_languages all_currencies all_templates posting_options payment_options accounting_options inventory_options profit_options accounts) ],
|
|
20 | 22 |
); |
21 | 23 |
|
22 | 24 |
sub action_edit { |
23 | 25 |
my ($self, %params) = @_; |
26 |
|
|
27 |
$::form->{use_templates} = $self->defaults->templates ? 'existing' : 'new'; |
|
24 | 28 |
$self->edit_form; |
25 | 29 |
} |
26 | 30 |
|
... | ... | |
65 | 69 |
|
66 | 70 |
my @errors = map { $errors_idx{$_} } sort keys %errors_idx; |
67 | 71 |
|
72 |
# Check templates |
|
73 |
$::form->{new_templates} =~ s:/::g; |
|
74 |
$::form->{new_master_templates} =~ s:/::g; |
|
75 |
|
|
76 |
if (($::form->{use_templates} eq 'existing') && ($self->defaults->templates !~ m:^templates/[^/]+$:)) { |
|
77 |
push @errors, t8('You must select existing print templates or create a new set.'); |
|
78 |
|
|
79 |
} elsif ($::form->{use_templates} eq 'new') { |
|
80 |
if (!$::form->{new_templates}) { |
|
81 |
push @errors, t8('You must enter a name for your new print templates.'); |
|
82 |
} elsif (-d "templates/" . $::form->{new_templates}) { |
|
83 |
push @errors, t8('A directory with the name for the new print templates exists already.'); |
|
84 |
} elsif (! -d "templates/print/" . $::form->{new_master_templates}) { |
|
85 |
push @errors, t8('The master templates where not found.'); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
# Show form again if there were any errors. Nothing's been changed |
|
90 |
# yet in the database. |
|
68 | 91 |
if (@errors) { |
69 | 92 |
flash('error', @errors); |
70 | 93 |
return $self->edit_form; |
... | ... | |
91 | 114 |
$self->defaults->currency_id($new_currency ? $new_currency->id : $original_currency_id); |
92 | 115 |
} |
93 | 116 |
|
117 |
# Create new templates if requested. |
|
118 |
if ($::form->{use_templates} eq 'new') { |
|
119 |
local $File::Copy::Recursive::SkipFlop = 1; |
|
120 |
File::Copy::Recursive::dircopy('templates/print/' . $::form->{new_master_templates}, 'templates/' . $::form->{new_templates}); |
|
121 |
$self->defaults->templates('templates/' . $::form->{new_templates}); |
|
122 |
} |
|
123 |
|
|
124 |
# Finally save defaults. |
|
94 | 125 |
$self->defaults->save; |
95 | 126 |
|
96 | 127 |
flash_later('info', t8('Client Configuration saved!')); |
... | ... | |
107 | 138 |
sub init_all_languages { SL::DB::Manager::Language->get_all_sorted } |
108 | 139 |
sub init_all_currencies { SL::DB::Manager::Currency->get_all_sorted } |
109 | 140 |
sub init_all_weightunits { SL::DB::Manager::Unit->find_by(name => 'g')->convertible_units } |
141 |
sub init_all_templates { +{ SL::Template->available_templates } } |
|
110 | 142 |
|
111 | 143 |
sub init_posting_options { |
112 | 144 |
[ { title => t8("never"), value => 0 }, |
... | ... | |
172 | 204 |
|
173 | 205 |
sub edit_form { |
174 | 206 |
my ($self) = @_; |
207 |
|
|
175 | 208 |
$self->render('client_config/form', title => t8('Client Configuration'), |
176 |
make_chart_title => sub { $_[0]->accno . '--' . $_[0]->description }); |
|
209 |
make_chart_title => sub { $_[0]->accno . '--' . $_[0]->description }, |
|
210 |
make_templates_value => sub { 'templates/' . $_[0] }, |
|
211 |
); |
|
177 | 212 |
} |
178 | 213 |
|
179 | 214 |
1; |
Auch abrufbar als: Unified diff
Mandantenkonfiguration: Druckvorlagen konfigurieren können