1 package SL::Controller::Department;
5 use parent qw(SL::Controller::Base);
7 use SL::DB::Department;
10 use Rose::Object::MakeMethods::Generic
12 scalar => [ qw(department) ],
15 __PACKAGE__->run_before('check_auth');
16 __PACKAGE__->run_before('load_department', only => [ qw(edit update destroy) ]);
25 $self->render('department/list',
26 title => $::locale->text('Departments'),
27 DEPARTMENTS => SL::DB::Manager::Department->get_all_sorted);
33 $self->render('department/form', title => $::locale->text('Create a new department'));
38 $self->render('department/form', title => $::locale->text('Edit department'));
44 $self->{department} = SL::DB::Department->new;
45 $self->create_or_update;
50 $self->create_or_update;
56 if (eval { $self->{department}->delete; 1; }) {
57 flash_later('info', $::locale->text('The department has been deleted.'));
59 flash_later('error', $::locale->text('The department is in use and cannot be deleted.'));
62 $self->redirect_to(action => 'list');
70 $::auth->assert('config');
77 sub create_or_update {
79 my $is_new = !$self->{department}->id;
80 my $params = delete($::form->{department}) || { };
82 $self->{department}->assign_attributes(%{ $params });
84 my @errors = $self->{department}->validate;
87 flash('error', @errors);
88 $self->render('department/form', title => $is_new ? $::locale->text('Create a new department') : $::locale->text('Edit department'));
91 $self->{department}->save;
93 flash_later('info', $is_new ? $::locale->text('The department has been created.') : $::locale->text('The department has been saved.'));
94 $self->redirect_to(action => 'list');
99 $self->{department} = SL::DB::Department->new(id => $::form->{id})->load;