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; |
templates/webpages/client_config/_miscellaneous.html | ||
---|---|---|
10 | 10 |
</tr> |
11 | 11 |
|
12 | 12 |
<tr> |
13 |
<td align="right">[% LxERP.t8("Address") %]</td> |
|
14 |
<td>[% L.textarea_tag('defaults.address', SELF.defaults.address, style=style, rows=4) %]</td> |
|
13 |
<td align="right" valign="top">[% LxERP.t8("Address") %]</td>
|
|
14 |
<td valign="top">[% L.textarea_tag('defaults.address', SELF.defaults.address, style=style, rows=4) %]</td>
|
|
15 | 15 |
</tr> |
16 | 16 |
|
17 | 17 |
<tr> |
... | ... | |
46 | 46 |
<td>[% L.select_tag('defaults.language_id', SELF.all_languages, title_key='description', default=SELF.defaults.language_id, with_empty=1, style=style) %]</td> |
47 | 47 |
</tr> |
48 | 48 |
|
49 |
<tr><td class="listheading" colspan="4">[% LxERP.t8("Print templates") %]</td></tr> |
|
50 |
|
|
51 |
<tr> |
|
52 |
<td align="right" valign="top">[% LxERP.t8("Print templates to use") %]</td> |
|
53 |
<td colspan="3" valign="top"> |
|
54 |
<table> |
|
55 |
<tr> |
|
56 |
<td>[% L.radio_button_tag('use_templates', value='existing', id='use_templates_existing', label=LxERP.t8('Use existing templates'), checked=(FORM.use_templates == 'existing')) %]</td> |
|
57 |
<td>[% L.select_tag('defaults.templates', SELF.all_templates.print_templates, default=SELF.defaults.templates, value_sub=\make_templates_value, style=style) %]</td> |
|
58 |
</tr> |
|
59 |
|
|
60 |
<tr> |
|
61 |
<td>[% L.radio_button_tag('use_templates', value='new', id='use_templates_new', label=LxERP.t8('Create new templates from master templates'), checked=(FORM.use_templates == 'new')) %]</td> |
|
62 |
<td>[% L.select_tag('new_master_templates', SELF.all_templates.master_templates, default=FORM.new_master_templates, style=style) %]</td> |
|
63 |
</tr> |
|
64 |
|
|
65 |
<tr> |
|
66 |
<td align="right">[% LxERP.t8("New name") %]</td> |
|
67 |
<td>[% L.input_tag('new_templates', FORM.new_templates, style=style) %]</td> |
|
68 |
</tr> |
|
69 |
</table> |
|
70 |
</td> |
|
71 |
</tr> |
|
72 |
|
|
49 | 73 |
<tr><td class="listheading" colspan="4">[% LxERP.t8("Currencies") %]</td></tr> |
50 | 74 |
|
51 | 75 |
<tr> |
... | ... | |
56 | 80 |
</tr> |
57 | 81 |
|
58 | 82 |
[% FOREACH currency = SELF.all_currencies %] |
83 |
[% L.hidden_tag("currencies[+].id", currency.id) %] |
|
59 | 84 |
<tr> |
60 | 85 |
<td align="right">[% IF loop.count == 1 %][% LxERP.t8("Currencies") %][% END %]</td> |
61 |
<td> |
|
62 |
[% L.input_tag("currencies[].name", currency.name, style=style) %] |
|
63 |
</td> |
|
64 |
<td align="center"> |
|
65 |
[% L.hidden_tag("currencies[+].id", currency.id) %] |
|
66 |
[% L.radio_button_tag('defaults.currency_id', value=currency.id, id='defaults.currency_id_' _ currency.id, checked=(SELF.defaults.currency_id == currency.id)) %] |
|
67 |
</td> |
|
86 |
<td>[% L.input_tag("currencies[].name", currency.name, style=style) %]</td> |
|
87 |
<td align="center">[% L.radio_button_tag('defaults.currency_id', value=currency.id, id='defaults.currency_id_' _ currency.id, checked=(SELF.defaults.currency_id == currency.id)) %]</td> |
|
68 | 88 |
<td>[% IF loop.count == 1 %][% LxERP.t8("Edit the currency names in order to rename them.") %][%- END %]</td> |
69 | 89 |
</tr> |
70 | 90 |
[% END %] |
templates/webpages/client_config/form.html | ||
---|---|---|
33 | 33 |
}); |
34 | 34 |
} |
35 | 35 |
|
36 |
function enable_template_controls() { |
|
37 |
var existing = $('#use_templates_existing').prop('checked'); |
|
38 |
$('#defaults_templates').prop('disabled', !existing); |
|
39 |
$('#new_templates,#new_master_templates').prop('disabled', existing); |
|
40 |
} |
|
41 |
|
|
36 | 42 |
$(function() { |
37 | 43 |
warehouse_selected([% SELF.defaults.warehouse_id || -1 %], [% SELF.defaults.bin_id || -1 %], 'bin_id'); |
38 | 44 |
warehouse_selected([% SELF.defaults.warehouse_id_ignore_onhand || -1 %], [% SELF.defaults.bin_id_ignore_onhand || -1 %], 'bin_id_ignore_onhand'); |
45 |
|
|
46 |
enable_template_controls(); |
|
47 |
$('#use_templates_existing,#use_templates_new').change(enable_template_controls); |
|
39 | 48 |
}) |
40 | 49 |
--> |
41 | 50 |
</script> |
Auch abrufbar als: Unified diff
Mandantenkonfiguration: Druckvorlagen konfigurieren können