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 SL::DB->client->with_transaction(sub {
41 $self->{employee}->save;
43 if ($self->{employee}->deleted) {
44 my $auth_user = SL::DB::Manager::AuthUser->get_first(login => $self->{employee}->login);
46 SL::DB::Manager::AuthClientUser->delete_all(
48 client_id => $::auth->client->{id},
49 user_id => $auth_user->id,
57 flash('info', $::locale->text('Employee #1 saved!', $self->{employee}->safe_name));
59 $self->redirect_to(action => 'edit', 'employee.id' => $self->{employee}->id);
62 #################### private stuff ##########################
65 $::auth->assert('admin');
69 $_[0]{employees} = SL::DB::Manager::Employee->get_all;
73 $_[0]{employee} = SL::DB::Manager::Employee->find_by(id => delete $::form->{employee}{id});
76 sub assign_from_form {
77 my %data = %{ $::form->{employee} || {} };
79 return 1 unless keys %data;
81 $_[0]{employee}->assign_attributes(map { $_ => $data{$_} } @updatable_columns);
85 sub setup_edit_action_bar {
88 for my $bar ($::request->layout->get('actionbar')) {
92 submit => [ '#form', { action => 'Employee/save' } ],
100 link => $self->url_for(action => 'list'),
106 ######################## behaviour ##########################
108 sub delay_flash_on_redirect { 1 }