1 package SL::Controller::Employee;
4 use parent qw(SL::Controller::Base);
8 use SL::Locale::String qw(t8);
10 __PACKAGE__->run_before('check_auth');
11 __PACKAGE__->run_before('load_all');
12 __PACKAGE__->run_before('load_from_form');
13 __PACKAGE__->run_before('assign_from_form');
15 our @updatable_columns = qw(deleted);
18 my ($self, %params) = @_;
20 $self->render('employee/list', title => $::locale->text('Employees'));
24 my ($self, %params) = @_;
26 if ($self->{employee}) {
27 $self->setup_edit_action_bar;
28 $self->render('employee/edit', title => $::locale->text('Edit Employee #1', $self->{employee}->safe_name));
30 flash_later('error', $::locale->text('Could not load employee'));
31 $self->redirect_to(action => 'list');
36 my ($self, %params) = @_;
38 $self->{employee}->save;
40 flash('info', $::locale->text('Employee #1 saved!', $self->{employee}->safe_name));
42 $self->redirect_to(action => 'edit', 'employee.id' => $self->{employee}->id);
45 #################### private stuff ##########################
48 $::auth->assert('admin');
52 $_[0]{employees} = SL::DB::Manager::Employee->get_all;
56 $_[0]{employee} = SL::DB::Manager::Employee->find_by(id => delete $::form->{employee}{id});
59 sub assign_from_form {
60 my %data = %{ $::form->{employee} || {} };
62 return 1 unless keys %data;
64 $_[0]{employee}->assign_attributes(map { $_ => $data{$_} } @updatable_columns);
68 sub setup_edit_action_bar {
71 for my $bar ($::request->layout->get('actionbar')) {
75 submit => [ '#form', { action => 'Employee/save' } ],
83 link => $self->url_for(action => 'list'),
89 ######################## behaviour ##########################
91 sub delay_flash_on_redirect { 1 }