X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRecordTemplate.pm;fp=SL%2FController%2FRecordTemplate.pm;h=9ce8e152c550ab5ef775091a98f0f4fd9e45fe4f;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=0000000000000000000000000000000000000000;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44;p=kivitendo-erp.git diff --git a/SL/Controller/RecordTemplate.pm b/SL/Controller/RecordTemplate.pm new file mode 100644 index 000000000..9ce8e152c --- /dev/null +++ b/SL/Controller/RecordTemplate.pm @@ -0,0 +1,128 @@ +package SL::Controller::RecordTemplate; + +use strict; + +use base qw(SL::Controller::Base); + +use SL::Helper::Flash qw(flash); +use SL::Locale::String qw(t8); +use SL::DB::RecordTemplate; + +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => [ qw(template_type template templates data) ], +); + +__PACKAGE__->run_before('check_auth'); + +my %modules = ( + ar_transaction => { + controller => 'ar.pl', + load_action => 'load_record_template', + save_action => 'save_record_template', + form_selector => '#form', + }, + + ap_transaction => { + controller => 'ap.pl', + load_action => 'load_record_template', + save_action => 'save_record_template', + form_selector => '#form', + }, + + gl_transaction => { + controller => 'gl.pl', + load_action => 'load_record_template', + save_action => 'save_record_template', + form_selector => '#form', + }, +); + +# +# actions +# + +sub action_show_dialog { + my ($self) = @_; + $self + ->js + ->dialog->open({ + html => $self->dialog_html, + id => 'record_template_dialog', + dialog => { + title => t8('Record templates'), + }, + }) + ->focus("#template_filter") + ->render; +} + +sub action_rename { + my ($self) = @_; + + $self->template_type($self->template->template_type); + $self->template->update_attributes(template_name => $::form->{template_name}); + + $self + ->js + ->html('#record_template_dialog', $self->dialog_html) + ->focus("#record_template_dialog_new_template_name") + ->reinit_widgets + ->render; +} + +sub action_delete { + my ($self) = @_; + + $self->template_type($self->template->template_type); + $self->template->delete; + + $self + ->js + ->html('#record_template_dialog', $self->dialog_html) + ->focus("#record_template_dialog_new_template_name") + ->reinit_widgets + ->render; +} + +sub action_filter_templates { + my ($self) = @_; + + $self->{template_filter} = $::form->{template_filter}; + + $self + ->js + ->html('#record_template_dialog', $self->dialog_html) + ->focus("#record_template_dialog_new_template_name") + ->reinit_widgets + ->focus("#template_filter") + ->render(); +} + +# +# helpers +# + +sub check_auth { + $::auth->assert('ap_transactions | ar_transactions | gl_transactions'); +} + +sub init_template_type { $::form->{template_type} or die 'need template_type' } +sub init_data { $modules{ $_[0]->template_type } } +sub init_template { SL::DB::RecordTemplate->new(id => $::form->{id})->load } + +sub init_templates { + my ($self) = @_; + return scalar SL::DB::Manager::RecordTemplate->get_all_sorted( + where => [ template_type => $self->template_type, + (template_name => { ilike => '%' . $::form->{template_filter} . '%' })x!! ($::form->{template_filter}) + ], + ); +} + +sub dialog_html { + my ($self) = @_; + + return $self->render('record_template/dialog', { layout => 0, output => 0 }); +} + +1;