"alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können
[kivitendo-erp.git] / SL / Controller / RecordTemplate.pm
1 package SL::Controller::RecordTemplate;
2
3 use strict;
4
5 use base qw(SL::Controller::Base);
6
7 use SL::Helper::Flash qw(flash);
8 use SL::Locale::String qw(t8);
9 use SL::DB::RecordTemplate;
10
11 use Rose::Object::MakeMethods::Generic (
12   'scalar --get_set_init' => [ qw(template_type template templates data) ],
13 );
14
15 __PACKAGE__->run_before('check_auth');
16
17 my %modules = (
18   ar_transaction => {
19     controller    => 'ar.pl',
20     load_action   => 'load_record_template',
21     save_action   => 'save_record_template',
22     form_selector => '#form',
23   },
24
25   ap_transaction => {
26     controller    => 'ap.pl',
27     load_action   => 'load_record_template',
28     save_action   => 'save_record_template',
29     form_selector => '#form',
30   },
31
32   gl_transaction => {
33     controller    => 'gl.pl',
34     load_action   => 'load_record_template',
35     save_action   => 'save_record_template',
36     form_selector => '#form',
37   },
38 );
39
40 #
41 # actions
42 #
43
44 sub action_show_dialog {
45   my ($self) = @_;
46   $self
47     ->js
48     ->dialog->open({
49       html   => $self->dialog_html,
50       id     => 'record_template_dialog',
51       dialog => {
52         title => t8('Record templates'),
53       },
54     })
55     ->focus("#template_filter")
56     ->render;
57 }
58
59 sub action_rename {
60   my ($self) = @_;
61
62   $self->template_type($self->template->template_type);
63   $self->template->update_attributes(template_name => $::form->{template_name});
64
65   $self
66     ->js
67     ->html('#record_template_dialog', $self->dialog_html)
68     ->focus("#record_template_dialog_new_template_name")
69     ->reinit_widgets
70     ->render;
71 }
72
73 sub action_delete {
74   my ($self) = @_;
75
76   $self->template_type($self->template->template_type);
77   $self->template->delete;
78
79   $self
80     ->js
81     ->html('#record_template_dialog', $self->dialog_html)
82     ->focus("#record_template_dialog_new_template_name")
83     ->reinit_widgets
84     ->render;
85 }
86
87 sub action_filter_templates {
88   my ($self) = @_;
89
90   $self->{template_filter} = $::form->{template_filter};
91
92   $self
93     ->js
94     ->html('#record_template_dialog', $self->dialog_html)
95     ->focus("#record_template_dialog_new_template_name")
96     ->reinit_widgets
97     ->focus("#template_filter")
98     ->render();
99 }
100
101 #
102 # helpers
103 #
104
105 sub check_auth {
106   $::auth->assert('ap_transactions | ar_transactions | gl_transactions');
107 }
108
109 sub init_template_type { $::form->{template_type} or die 'need template_type'   }
110 sub init_data          { $modules{ $_[0]->template_type }                       }
111 sub init_template      { SL::DB::RecordTemplate->new(id => $::form->{id})->load }
112
113 sub init_templates {
114   my ($self) = @_;
115   return scalar SL::DB::Manager::RecordTemplate->get_all_sorted(
116     where => [ template_type => $self->template_type,
117               (template_name => { ilike => '%' . $::form->{template_filter} . '%' })x!! ($::form->{template_filter})
118              ],
119   );
120 }
121
122 sub dialog_html {
123   my ($self) = @_;
124
125   return $self->render('record_template/dialog', { layout => 0, output => 0 });
126 }
127
128 1;