1 package SL::Controller::Business;
5 use parent qw(SL::Controller::Base);
10 use Rose::Object::MakeMethods::Generic
12 scalar => [ qw(business) ],
15 __PACKAGE__->run_before('check_auth');
16 __PACKAGE__->run_before('load_business', only => [ qw(edit update destroy) ]);
25 $self->render('business/list',
26 title => $::locale->text('Businesses'),
27 BUSINESSS => SL::DB::Manager::Business->get_all_sorted);
33 $self->{business} = SL::DB::Business->new;
34 $self->render('business/form', title => $::locale->text('Create a new business'));
39 $self->render('business/form', title => $::locale->text('Edit business'));
45 $self->{business} = SL::DB::Business->new;
46 $self->create_or_update;
51 $self->create_or_update;
57 if (eval { $self->{business}->delete; 1; }) {
58 flash_later('info', $::locale->text('The business has been deleted.'));
60 flash_later('error', $::locale->text('The business is in use and cannot be deleted.'));
63 $self->redirect_to(action => 'list');
71 $::auth->assert('config');
78 sub create_or_update {
80 my $is_new = !$self->{business}->id;
81 my $params = delete($::form->{business}) || { };
83 $self->{business}->assign_attributes(%{ $params });
85 my @errors = $self->{business}->validate;
88 flash('error', @errors);
89 $self->render('business/form', title => $is_new ? $::locale->text('Create a new business') : $::locale->text('Edit business'));
93 $self->{business}->save;
95 flash_later('info', $is_new ? $::locale->text('The business has been created.') : $::locale->text('The business has been saved.'));
96 $self->redirect_to(action => 'list');
101 $self->{business} = SL::DB::Business->new(id => $::form->{id})->load;