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};
120 my $params = delete($::form->{part_classification}) || { };
122 $self->{part_classification}->assign_attributes(%{ $params });
124 my @errors = $self->{part_classification}->validate;
127 flash('error', @errors);
128 $self->render('part_classification/form', title => $is_new ? $::locale->text('Create a new parts classification') : $::locale->text('Edit parts classification'));
132 $self->{part_classification}->save;
134 flash_later('info', $is_new ? $::locale->text('The parts classification has been created.') : $::locale->text('The parts classification has been saved.'));
135 $self->redirect_to(action => 'list');
138 # submethod for loading one item from the database
140 sub load_part_classification {
142 $self->{part_classification} = SL::DB::PartClassification->new(id => $::form->{id})->load;
155 SL::Controller::PartClassification
159 This Controller is responsible for creating,editing or deleting
160 Part Classifications.
164 The use of Part Classifications is described in L<SL::DB::PartClassification>
170 $self->action_create();
172 A new part classification is saved
176 =head2 action_destroy
178 $self->action_destroy();
180 An existing part classification is deleted
182 The basic classifications cannot be deleted, also classifications which are in use
188 $self->action_edit();
190 Edit an existing part classifications
196 $self->action_list();
198 List all available part classifications
206 A Form for a new creatable part classifications is generated
210 =head2 action_reorder
212 $self->action_reorder();
220 $self->action_update();
222 An existing part classification is saved
227 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>