GDPDU: DATEV-ähnlicher Buchungsexport Rohversion
[kivitendo-erp.git] / SL / Controller / RequirementSpecStatus.pm
1 package SL::Controller::RequirementSpecStatus;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::DB::RequirementSpecStatus;
8 use SL::Helper::Flash;
9 use SL::Locale::String;
10
11 use Rose::Object::MakeMethods::Generic
12 (
13  scalar => [ qw(requirement_spec_status valid_names) ],
14 );
15
16 __PACKAGE__->run_before('check_auth');
17 __PACKAGE__->run_before('load_requirement_spec_status', only => [ qw(edit update destroy) ]);
18 __PACKAGE__->run_before(sub { $_[0]->valid_names(\@SL::DB::RequirementSpecStatus::valid_names) });
19
20 #
21 # actions
22 #
23
24 sub action_list {
25   my ($self) = @_;
26
27   $self->render('requirement_spec_status/list',
28                 title                     => t8('Requirement Spec Statuses'),
29                 REQUIREMENT_SPEC_STATUSES => SL::DB::Manager::RequirementSpecStatus->get_all_sorted);
30 }
31
32 sub action_new {
33   my ($self) = @_;
34
35   $self->{requirement_spec_status} = SL::DB::RequirementSpecStatus->new;
36   $self->render('requirement_spec_status/form', title => t8('Create a new requirement spec status'));
37 }
38
39 sub action_edit {
40   my ($self) = @_;
41   $self->render('requirement_spec_status/form', title => t8('Edit requirement spec status'));
42 }
43
44 sub action_create {
45   my ($self) = @_;
46
47   $self->{requirement_spec_status} = SL::DB::RequirementSpecStatus->new;
48   $self->create_or_update;
49 }
50
51 sub action_update {
52   my ($self) = @_;
53   $self->create_or_update;
54 }
55
56 sub action_destroy {
57   my ($self) = @_;
58
59   if (eval { $self->{requirement_spec_status}->delete; 1; }) {
60     flash_later('info',  t8('The requirement spec status has been deleted.'));
61   } else {
62     flash_later('error', t8('The requirement spec status is in use and cannot be deleted.'));
63   }
64
65   $self->redirect_to(action => 'list');
66 }
67
68 sub action_reorder {
69   my ($self) = @_;
70
71   SL::DB::RequirementSpecStatus->reorder_list(@{ $::form->{requirement_spec_status_id} || [] });
72
73   $self->render(\'', { type => 'json' });
74 }
75
76 #
77 # filters
78 #
79
80 sub check_auth {
81   $::auth->assert('config');
82 }
83
84 #
85 # helpers
86 #
87
88 sub create_or_update {
89   my $self   = shift;
90   my $is_new = !$self->{requirement_spec_status}->id;
91   my $params = delete($::form->{requirement_spec_status}) || { };
92   my $title  = $is_new ? t8('Create a new requirement spec status') : t8('Edit requirement spec status');
93
94   $self->{requirement_spec_status}->assign_attributes(%{ $params });
95
96   my @errors = $self->{requirement_spec_status}->validate;
97
98   if (@errors) {
99     flash('error', @errors);
100     $self->render('requirement_spec_status/form', title => $title);
101     return;
102   }
103
104   $self->{requirement_spec_status}->save;
105
106   flash_later('info', $is_new ? t8('The requirement spec status has been created.') : t8('The requirement spec status has been saved.'));
107   $self->redirect_to(action => 'list');
108 }
109
110 sub load_requirement_spec_status {
111   my ($self) = @_;
112   $self->{requirement_spec_status} = SL::DB::RequirementSpecStatus->new(id => $::form->{id})->load;
113 }
114
115 1;