1 package SL::Controller::PartClassification;
 
   5 use parent qw(SL::Controller::Base);
 
   7 use SL::DB::PartClassification;
 
  10 use Rose::Object::MakeMethods::Generic
 
  12  scalar => [ qw(part_classification) ],
 
  15 __PACKAGE__->run_before('check_auth');
 
  16 __PACKAGE__->run_before('load_part_classification', only => [ qw(edit update destroy) ]);
 
  19 # This Controller is responsible for creating,editing or deleting
 
  20 # Part Classifications.
 
  22 # The use of Part Classifications is described in SL::DB::PartClassification
 
  26 # List all available part classifications
 
  32   $self->render('part_classification/list',
 
  33                 title                => $::locale->text('Parts Classifications'),
 
  34                 PART_CLASSIFICATIONS => SL::DB::Manager::PartClassification->get_all_sorted);
 
  37 # A Form for a new creatable part classifications is generated
 
  42   $self->{part_classification} = SL::DB::PartClassification->new;
 
  43   $self->render('part_classification/form', title => $::locale->text('Create a new parts classification'));
 
  46 # Edit an existing part classifications
 
  50   $self->render('part_classification/form', title => $::locale->text('Edit parts classification'));
 
  53 # A new part classification is saved
 
  58   $self->{part_classification} = SL::DB::PartClassification->new;
 
  59   $self->create_or_update;
 
  62 # An existing part classification is saved
 
  66   $self->create_or_update;
 
  69 # An existing part classification is deleted
 
  71 # The basic classifications cannot be deleted, also classifications which are in use
 
  76   if ( $self->{part_classification}->id < 5 ) {
 
  77     flash_later('error', $::locale->text('The basic parts classification cannot be deleted.'));
 
  79   elsif (eval { $self->{part_classification}->delete; 1; }) {
 
  80     flash_later('info',  $::locale->text('The parts classification has been deleted.'));
 
  82     flash_later('error', $::locale->text('The parts classification is in use and cannot be deleted.'));
 
  85   $self->redirect_to(action => 'list');
 
  87 # reordering the lines
 
  92   SL::DB::PartClassification->reorder_list(@{ $::form->{part_classification_id} || [] });
 
  94   $self->render(\'', { type => 'json' });
 
 101 # check authentication, only "config" is allowed
 
 104   $::auth->assert('config');
 
 111 # submethod for update the database
 
 113 sub create_or_update {
 
 115   my $is_new = !$self->{part_classification}->id;
 
 117   $::form->{part_classification}->{used_for_purchase} = 0 if ! $::form->{part_classification}->{used_for_purchase};
 
 118   $::form->{part_classification}->{used_for_sale}     = 0 if ! $::form->{part_classification}->{used_for_sale};
 
 119   $::form->{part_classification}->{report_separate}   = 0 if ! $::form->{part_classification}->{report_separate};
 
 121   my $params = delete($::form->{part_classification}) || { };
 
 123   $self->{part_classification}->assign_attributes(%{ $params });
 
 125   my @errors = $self->{part_classification}->validate;
 
 128     flash('error', @errors);
 
 129     $self->render('part_classification/form', title => $is_new ? $::locale->text('Create a new parts classification') : $::locale->text('Edit parts classification'));
 
 133   $self->{part_classification}->save;
 
 135   flash_later('info', $is_new ? $::locale->text('The parts classification has been created.') : $::locale->text('The parts classification has been saved.'));
 
 136   $self->redirect_to(action => 'list');
 
 139 # submethod for loading one item from the database
 
 141 sub load_part_classification {
 
 143   $self->{part_classification} = SL::DB::PartClassification->new(id => $::form->{id})->load;
 
 156 SL::Controller::PartClassification
 
 160 This Controller is responsible for creating,editing or deleting
 
 161 Part Classifications.
 
 165 The use of Part Classifications is described in L<SL::DB::PartClassification>
 
 171  $self->action_create();
 
 173 A new part classification is saved
 
 177 =head2 action_destroy
 
 179  $self->action_destroy();
 
 181 An existing part classification is deleted
 
 183 The basic classifications cannot be deleted, also classifications which are in use
 
 189  $self->action_edit();
 
 191 Edit an existing part classifications
 
 197  $self->action_list();
 
 199 List all available part classifications
 
 207 A Form for a new creatable part classifications is generated
 
 211 =head2 action_reorder
 
 213  $self->action_reorder();
 
 221  $self->action_update();
 
 223 An existing part classification is saved
 
 228 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>