1 package SL::Controller::Employee;
4 use parent qw(SL::Controller::Base);
9 __PACKAGE__->run_before('check_auth');
10 __PACKAGE__->run_before('load_all');
11 __PACKAGE__->run_before('load_from_form');
12 __PACKAGE__->run_before('assign_from_form');
14 our @updatable_columns = qw(deleted);
17 my ($self, %params) = @_;
19 $self->render('employee/list', title => $::locale->text('Employees'));
23 my ($self, %params) = @_;
25 if ($self->{employee}) {
26 $self->render('employee/edit', title => $::locale->text('Edit Employee #1', $self->{employee}->safe_name));
28 flash('error', $::locale->text('Could not load employee'));
29 $self->redirect_to(action => 'list');
34 my ($self, %params) = @_;
36 $self->{employee}->save;
38 flash('info', $::locale->text('Employee #1 saved!'));
40 $self->redirect_to(action => 'edit', 'employee.id' => $self->{employee}->id);
43 #################### private stuff ##########################
46 $::auth->assert('admin');
50 $_[0]{employees} = SL::DB::Manager::Employee->get_all;
54 $_[0]{employee} = SL::DB::Manager::Employee->find_by(id => delete $::form->{employee}{id});
57 sub assign_from_form {
58 my %data = %{ $::form->{employee} || {} };
60 return 1 unless keys %data;
62 $_[0]{employee}->assign_attributes(map { $_ => $data{$_} } @updatable_columns);
67 ######################## behaviour ##########################
69 sub delay_flash_on_redirect { 1 }