1 package SL::Controller::ReclamationReason;
5 use parent qw(SL::Controller::Base);
7 use SL::DB::ReclamationReason;
9 use SL::Locale::String;
10 use List::MoreUtils qw(any);
13 use Rose::Object::MakeMethods::Generic (
14 scalar => [ qw(reclamation_reason) ],
15 'scalar --get_set_init' => [ qw(reclamation_reason) ],
18 __PACKAGE__->run_before('check_auth');
19 __PACKAGE__->run_before('load_reclamation_reason', only => [ qw(edit delete) ]);
22 $::auth->assert('config');
30 my ($self, %params) = @_;
32 $self->setup_list_action_bar;
34 'reclamation_reason/list',
35 title => $::locale->text('Reclamation Reasons'),
36 RECLAMATION_REASONS => SL::DB::Manager::ReclamationReason->get_all_sorted(),
40 sub action_sort_list {
41 my ($self, %params) = @_;
43 $self->setup_sort_list_action_bar;
45 'reclamation_reason/sort_list',
46 title => $::locale->text('reclamation reasons'),
47 RECLAMATION_REASONS => SL::DB::Manager::ReclamationReason->get_all_sorted(),
54 $self->reclamation_reason(SL::DB::ReclamationReason->new());
55 $self->show_form(title => t8('Add reclamation reason'));
62 title => t8('Edit reclamation reason'),
70 $self->load_reclamation_reason();
73 $self->create_or_save;
79 if (!$self->reclamation_reason->db->with_transaction(sub {
80 $self->reclamation_reason->delete();
81 flash_later('info', $::locale->text('The reclamation reason has been deleted.'));
85 flash_later('error', $::locale->text('The reclamation reason is in use and cannot be deleted.'))
88 $self->redirect_to(action => 'list');
98 SL::DB::ReclamationReason->reorder_list(@{ $::form->{reclamation_reason_id} || [] });
100 $self->render(\'', { type => 'json' });
107 sub setup_form_action_bar {
110 my $is_new = !$self->reclamation_reason->id;
112 for my $bar ($::request->layout->get('actionbar')) {
115 $is_new ? t8('Create') : t8('Save'),
116 submit => [ '#form', { action => 'ReclamationReason/save' } ],
117 checks => [ 'kivi.validate_form' ],
118 accesskey => 'enter',
122 submit => [ '#form', { action => 'ReclamationReason/delete' } ],
123 confirm => t8('Do you really want to delete this reclamation reason?'),
128 link => $self->url_for(action => 'list'),
132 $::request->layout->add_javascripts('kivi.Validator.js');
135 sub setup_list_action_bar {
138 for my $bar ($::request->layout->get('actionbar')) {
142 link => $self->url_for(action => 'new'),
146 link => $self->url_for(action => 'sort_list'),
152 sub setup_sort_list_action_bar {
155 for my $bar ($::request->layout->get('actionbar')) {
159 link => $self->url_for(action => 'new'),
163 link => $self->url_for(action => 'list'),
176 unless ($self->reclamation_reason) {
177 $self->reclamation_reason(SL::DB::ReclamationReason->new());
180 my $is_new = !$self->reclamation_reason->id;
182 my $params = delete($::form->{reclamation_reason}) || { };
183 delete $params->{id};
187 my $db = $self->reclamation_reason->db;
188 if (!$db->with_transaction(sub {
190 # assign attributes and validate
191 $self->reclamation_reason->assign_attributes( %{$params} ) ;
193 push(@errors, $self->reclamation_reason->validate); # check data before DB error
198 $self->reclamation_reason->save;
201 die @errors ? join("\n", @errors) . "\n" : $db->error . "\n";
204 flash_later('info', $is_new ? t8('The reclamation reason has been created.') : t8('The reclamation reason has been saved.'));
205 $self->redirect_to(action => 'list');
209 my ($self, %params) = @_;
211 $self->setup_form_action_bar;
213 'reclamation_reason/form',
218 sub load_reclamation_reason {
221 $self->reclamation_reason(SL::DB::ReclamationReason->new(id => $::form->{id})->load);
232 SL::Controller::ReclamationReason - controller for reclamation_reasons
236 This is a small controller to add end edit reclamation_reasons.
244 Adding, editing, deleting and sorting of reclamation reasons.
248 Reasons can be valid for purchase, sales or both.
258 =item * C<SL/Controller/ReclamationReason.pm>
262 =item * C<template/webpages/reclamation_reason/form.html>
266 =item * C<template/webpages/reclamation_reason/list.html>
270 =item * C<template/webpages/reclamation_reason/sort_list.html>
278 Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt>