From 05b30be4d26d9f1eb0481996cb864a96963226a2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 14 Jun 2013 13:42:28 +0200 Subject: [PATCH] =?utf8?q?Mandantenkonfiguration:=20Druckvorlagen=20konfig?= =?utf8?q?urieren=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/ClientConfig.pm | 39 ++++++++++++++++++- .../client_config/_miscellaneous.html | 38 +++++++++++++----- templates/webpages/client_config/form.html | 9 +++++ 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/SL/Controller/ClientConfig.pm b/SL/Controller/ClientConfig.pm index a3fdb9caf..29965e1ef 100644 --- a/SL/Controller/ClientConfig.pm +++ b/SL/Controller/ClientConfig.pm @@ -3,6 +3,7 @@ package SL::Controller::ClientConfig; use strict; use parent qw(SL::Controller::Base); +use File::Copy::Recursive (); use List::Util qw(first); use SL::DB::Chart; @@ -12,15 +13,18 @@ use SL::DB::Language; use SL::DB::Unit; use SL::Helper::Flash; use SL::Locale::String qw(t8); +use SL::Template; __PACKAGE__->run_before('check_auth'); use Rose::Object::MakeMethods::Generic ( - '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) ], + '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) ], ); sub action_edit { my ($self, %params) = @_; + + $::form->{use_templates} = $self->defaults->templates ? 'existing' : 'new'; $self->edit_form; } @@ -65,6 +69,25 @@ sub action_save { my @errors = map { $errors_idx{$_} } sort keys %errors_idx; + # Check templates + $::form->{new_templates} =~ s:/::g; + $::form->{new_master_templates} =~ s:/::g; + + if (($::form->{use_templates} eq 'existing') && ($self->defaults->templates !~ m:^templates/[^/]+$:)) { + push @errors, t8('You must select existing print templates or create a new set.'); + + } elsif ($::form->{use_templates} eq 'new') { + if (!$::form->{new_templates}) { + push @errors, t8('You must enter a name for your new print templates.'); + } elsif (-d "templates/" . $::form->{new_templates}) { + push @errors, t8('A directory with the name for the new print templates exists already.'); + } elsif (! -d "templates/print/" . $::form->{new_master_templates}) { + push @errors, t8('The master templates where not found.'); + } + } + + # Show form again if there were any errors. Nothing's been changed + # yet in the database. if (@errors) { flash('error', @errors); return $self->edit_form; @@ -91,6 +114,14 @@ sub action_save { $self->defaults->currency_id($new_currency ? $new_currency->id : $original_currency_id); } + # Create new templates if requested. + if ($::form->{use_templates} eq 'new') { + local $File::Copy::Recursive::SkipFlop = 1; + File::Copy::Recursive::dircopy('templates/print/' . $::form->{new_master_templates}, 'templates/' . $::form->{new_templates}); + $self->defaults->templates('templates/' . $::form->{new_templates}); + } + + # Finally save defaults. $self->defaults->save; flash_later('info', t8('Client Configuration saved!')); @@ -107,6 +138,7 @@ sub init_all_warehouses { SL::DB::Manager::Warehouse->get_all_sorted sub init_all_languages { SL::DB::Manager::Language->get_all_sorted } sub init_all_currencies { SL::DB::Manager::Currency->get_all_sorted } sub init_all_weightunits { SL::DB::Manager::Unit->find_by(name => 'g')->convertible_units } +sub init_all_templates { +{ SL::Template->available_templates } } sub init_posting_options { [ { title => t8("never"), value => 0 }, @@ -172,8 +204,11 @@ sub check_auth { sub edit_form { my ($self) = @_; + $self->render('client_config/form', title => t8('Client Configuration'), - make_chart_title => sub { $_[0]->accno . '--' . $_[0]->description }); + make_chart_title => sub { $_[0]->accno . '--' . $_[0]->description }, + make_templates_value => sub { 'templates/' . $_[0] }, + ); } 1; diff --git a/templates/webpages/client_config/_miscellaneous.html b/templates/webpages/client_config/_miscellaneous.html index 57c62490e..82c8fd4ad 100644 --- a/templates/webpages/client_config/_miscellaneous.html +++ b/templates/webpages/client_config/_miscellaneous.html @@ -10,8 +10,8 @@ - [% LxERP.t8("Address") %] - [% L.textarea_tag('defaults.address', SELF.defaults.address, style=style, rows=4) %] + [% LxERP.t8("Address") %] + [% L.textarea_tag('defaults.address', SELF.defaults.address, style=style, rows=4) %] @@ -46,6 +46,30 @@ [% L.select_tag('defaults.language_id', SELF.all_languages, title_key='description', default=SELF.defaults.language_id, with_empty=1, style=style) %] + [% LxERP.t8("Print templates") %] + + + [% LxERP.t8("Print templates to use") %] + + + + + + + + + + + + + + + + +
[% L.radio_button_tag('use_templates', value='existing', id='use_templates_existing', label=LxERP.t8('Use existing templates'), checked=(FORM.use_templates == 'existing')) %][% L.select_tag('defaults.templates', SELF.all_templates.print_templates, default=SELF.defaults.templates, value_sub=\make_templates_value, style=style) %]
[% 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')) %][% L.select_tag('new_master_templates', SELF.all_templates.master_templates, default=FORM.new_master_templates, style=style) %]
[% LxERP.t8("New name") %][% L.input_tag('new_templates', FORM.new_templates, style=style) %]
+ + + [% LxERP.t8("Currencies") %] @@ -56,15 +80,11 @@ [% FOREACH currency = SELF.all_currencies %] + [% L.hidden_tag("currencies[+].id", currency.id) %] [% IF loop.count == 1 %][% LxERP.t8("Currencies") %][% END %] - - [% L.input_tag("currencies[].name", currency.name, style=style) %] - - - [% L.hidden_tag("currencies[+].id", currency.id) %] - [% L.radio_button_tag('defaults.currency_id', value=currency.id, id='defaults.currency_id_' _ currency.id, checked=(SELF.defaults.currency_id == currency.id)) %] - + [% L.input_tag("currencies[].name", currency.name, style=style) %] + [% L.radio_button_tag('defaults.currency_id', value=currency.id, id='defaults.currency_id_' _ currency.id, checked=(SELF.defaults.currency_id == currency.id)) %] [% IF loop.count == 1 %][% LxERP.t8("Edit the currency names in order to rename them.") %][%- END %] [% END %] diff --git a/templates/webpages/client_config/form.html b/templates/webpages/client_config/form.html index 17b5a7fd6..5a2a9ba26 100644 --- a/templates/webpages/client_config/form.html +++ b/templates/webpages/client_config/form.html @@ -33,9 +33,18 @@ function warehouse_selected(warehouse_id, bin_id, bin_id_name) { }); } +function enable_template_controls() { + var existing = $('#use_templates_existing').prop('checked'); + $('#defaults_templates').prop('disabled', !existing); + $('#new_templates,#new_master_templates').prop('disabled', existing); +} + $(function() { warehouse_selected([% SELF.defaults.warehouse_id || -1 %], [% SELF.defaults.bin_id || -1 %], 'bin_id'); warehouse_selected([% SELF.defaults.warehouse_id_ignore_onhand || -1 %], [% SELF.defaults.bin_id_ignore_onhand || -1 %], 'bin_id_ignore_onhand'); + + enable_template_controls(); + $('#use_templates_existing,#use_templates_new').change(enable_template_controls); }) --> -- 2.20.1