1 package SL::Controller::DeliveryTerm;
5 use parent qw(SL::Controller::Base);
7 use SL::DB::DeliveryTerm;
11 use Rose::Object::MakeMethods::Generic
13 scalar => [ qw(delivery_term languages) ],
16 __PACKAGE__->run_before('check_auth');
17 __PACKAGE__->run_before('load_delivery_term', only => [ qw(edit update destroy) ]);
18 __PACKAGE__->run_before('load_languages', only => [ qw(new list edit create update) ]);
28 $self->render('delivery_term/list',
29 title => $::locale->text('Delivery terms'),
30 DELIVERY_TERMS => SL::DB::Manager::DeliveryTerm->get_all_sorted);
36 $self->{delivery_term} = SL::DB::DeliveryTerm->new;
37 $self->render('delivery_term/form', title => $::locale->text('Create a new delivery term'));
42 $self->render('delivery_term/form', title => $::locale->text('Edit delivery term'));
48 $self->{delivery_term} = SL::DB::DeliveryTerm->new;
49 $self->create_or_update;
54 $self->create_or_update;
60 if (eval { $self->{delivery_term}->delete; 1; }) {
61 flash_later('info', $::locale->text('The delivery term has been deleted.'));
63 flash_later('error', $::locale->text('The delivery term is in use and cannot be deleted.'));
66 $self->redirect_to(action => 'list');
72 SL::DB::DeliveryTerm->reorder_list(@{ $::form->{delivery_term_id} || [] });
74 $self->render(\'', { type => 'json' }); # ' make Emacs happy
82 $::auth->assert('config');
89 sub create_or_update {
91 my $is_new = !$self->{delivery_term}->id;
92 my $params = delete($::form->{delivery_term}) || { };
94 $self->{delivery_term}->assign_attributes(%{ $params });
96 my @errors = $self->{delivery_term}->validate;
99 flash('error', @errors);
100 $self->render('delivery_term/form', title => $is_new ? $::locale->text('Create a new delivery term') : $::locale->text('Edit delivery term'));
104 $self->{delivery_term}->save;
105 foreach my $language (@{ $self->{languages} }) {
106 $self->{delivery_term}->save_attribute_translation('description_long', $language, $::form->{"translation_" . $language->id});
109 flash_later('info', $is_new ? $::locale->text('The delivery term has been created.') : $::locale->text('The delivery term has been saved.'));
110 $self->redirect_to(action => 'list');
113 sub load_delivery_term {
115 $self->{delivery_term} = SL::DB::DeliveryTerm->new(id => $::form->{id})->load;
120 $self->{languages} = SL::DB::Manager::Language->get_all_sorted;