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