1 package SL::Controller::RequirementSpecType;
 
   5 use parent qw(SL::Controller::Base);
 
   7 use SL::DB::RequirementSpecType;
 
   9 use SL::Locale::String;
 
  11 use Rose::Object::MakeMethods::Generic
 
  13  scalar => [ qw(requirement_spec_type) ],
 
  16 __PACKAGE__->run_before('check_auth');
 
  17 __PACKAGE__->run_before('load_requirement_spec_type', only => [ qw(edit update destroy) ]);
 
  26   $self->render('requirement_spec_type/list',
 
  27                 title                  => t8('Requirement Spec Types'),
 
  28                 REQUIREMENT_SPEC_TYPES => SL::DB::Manager::RequirementSpecType->get_all_sorted);
 
  34   $self->{requirement_spec_type} = SL::DB::RequirementSpecType->new(template_file_name => 'requirement_spec');
 
  35   $self->render('requirement_spec_type/form', title => t8('Create a new requirement spec type'));
 
  40   $self->render('requirement_spec_type/form', title => t8('Edit requirement spec type'));
 
  46   $self->{requirement_spec_type} = SL::DB::RequirementSpecType->new;
 
  47   $self->create_or_update;
 
  52   $self->create_or_update;
 
  58   if (eval { $self->{requirement_spec_type}->delete; 1; }) {
 
  59     flash_later('info',  t8('The requirement spec type has been deleted.'));
 
  61     flash_later('error', t8('The requirement spec type is in use and cannot be deleted.'));
 
  64   $self->redirect_to(action => 'list');
 
  70   SL::DB::RequirementSpecType->reorder_list(@{ $::form->{requirement_spec_type_id} || [] });
 
  72   $self->render(\'', { type => 'json' });
 
  80   $::auth->assert('config');
 
  87 sub create_or_update {
 
  89   my $is_new = !$self->{requirement_spec_type}->id;
 
  90   my $params = delete($::form->{requirement_spec_type}) || { };
 
  91   my $title  = $is_new ? t8('Create a new requirement spec type') : t8('Edit requirement spec type');
 
  93   $self->{requirement_spec_type}->assign_attributes(%{ $params });
 
  95   my @errors = $self->{requirement_spec_type}->validate;
 
  98     flash('error', @errors);
 
  99     $self->render('requirement_spec_type/form', title => $title);
 
 103   $self->{requirement_spec_type}->save;
 
 105   flash_later('info', $is_new ? t8('The requirement spec type has been created.') : t8('The requirement spec type has been saved.'));
 
 106   $self->redirect_to(action => 'list');
 
 109 sub load_requirement_spec_type {
 
 111   $self->{requirement_spec_type} = SL::DB::RequirementSpecType->new(id => $::form->{id})->load;