1 package SL::Controller::RequirementSpecComplexity;
5 use parent qw(SL::Controller::Base);
7 use SL::DB::RequirementSpecComplexity;
10 use SL::Locale::String;
12 use Rose::Object::MakeMethods::Generic
14 scalar => [ qw(requirement_spec_complexity) ],
17 __PACKAGE__->run_before('check_auth');
18 __PACKAGE__->run_before('load_requirement_spec_complexity', only => [ qw(edit update destroy) ]);
27 $self->render('requirement_spec_complexity/list',
28 title => t8('Complexities'),
29 REQUIREMENT_SPEC_COMPLEXITIES => SL::DB::Manager::RequirementSpecComplexity->get_all_sorted);
35 $self->{requirement_spec_complexity} = SL::DB::RequirementSpecComplexity->new;
36 $self->render('requirement_spec_complexity/form', title => t8('Create a new complexity'));
41 $self->render('requirement_spec_complexity/form', title => t8('Edit complexity'));
47 $self->{requirement_spec_complexity} = SL::DB::RequirementSpecComplexity->new;
48 $self->create_or_update;
53 $self->create_or_update;
59 if (eval { $self->{requirement_spec_complexity}->delete; 1; }) {
60 flash_later('info', t8('The complexity has been deleted.'));
62 flash_later('error', t8('The complexity is in use and cannot be deleted.'));
65 $self->redirect_to(action => 'list');
71 SL::DB::RequirementSpecComplexity->reorder_list(@{ $::form->{requirement_spec_complexity_id} || [] });
73 $self->render('1;', { type => 'js', inline => 1 });
81 $::auth->assert('config');
88 sub create_or_update {
90 my $is_new = !$self->{requirement_spec_complexity}->id;
91 my $params = delete($::form->{requirement_spec_complexity}) || { };
92 my $title = $is_new ? t8('Create a new complexity') : t8('Edit complexity');
94 $self->{requirement_spec_complexity}->assign_attributes(%{ $params });
96 my @errors = $self->{requirement_spec_complexity}->validate;
99 flash('error', @errors);
100 $self->render('requirement_spec_complexity/form', title => $title);
104 $self->{requirement_spec_complexity}->save;
106 flash_later('info', $is_new ? t8('The complexity has been created.') : t8('The complexity has been saved.'));
107 $self->redirect_to(action => 'list');
110 sub load_requirement_spec_complexity {
112 $self->{requirement_spec_complexity} = SL::DB::RequirementSpecComplexity->new(id => $::form->{id})->load;