Revision 65d8e1fe
Von Tamino Steinert vor 5 Monaten hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
use SL::Helper::Flash qw(flash_later);
|
||
use SL::HTML::Util;
|
||
use SL::Presenter::Tag qw(select_tag hidden_tag div_tag);
|
||
use SL::Presenter::ReclamationFilter qw(filter);
|
||
use SL::Presenter::Filter::Reclamation;
|
||
use SL::Locale::String qw(t8);
|
||
use SL::SessionFile::Random;
|
||
use SL::PriceSource;
|
||
... | ... | |
sub action_list {
|
||
my ($self) = @_;
|
||
|
||
$::form->{filter} ||= {};
|
||
|
||
$self->_setup_search_action_bar;
|
||
$self->prepare_report;
|
||
my $report = $self->prepare_report;
|
||
$self->report_generator_list_objects(
|
||
report => $self->{report},
|
||
report => $report,
|
||
objects => $self->models->get,
|
||
options => {
|
||
action_bar_additional_submit_values => {
|
||
... | ... | |
closed => t8('Closed'),
|
||
},
|
||
query => [
|
||
SL::DB::Manager::Reclamation->type_filter($self->type),
|
||
(record_type => $self->type),
|
||
(salesman_id => SL::DB::Manager::Employee->current->id) x ($self->reclamation->is_sales && !$::auth->assert('sales_all_edit', 1)),
|
||
(employee_id => SL::DB::Manager::Employee->current->id) x ($self->reclamation->is_sales && !$::auth->assert('sales_all_edit', 1)),
|
||
(employee_id => SL::DB::Manager::Employee->current->id) x (!$self->reclamation->is_sales && !$::auth->assert('purchase_all_edit', 1)),
|
||
... | ... | |
my ($self) = @_;
|
||
|
||
my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
|
||
$report->{title} = t8('Sales Reclamations');
|
||
if ($self->type eq PURCHASE_RECLAMATION_TYPE()){
|
||
$report->{title} = t8('Purchase Reclamations');
|
||
}
|
||
|
||
$self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
|
||
$self->models->add_additional_url_params(type => $self->type);
|
||
... | ... | |
|
||
my $callback = $self->models->get_callback;
|
||
|
||
$self->{report} = $report;
|
||
|
||
# TODO: shipto_id is not linked to custom_shipto
|
||
my @columns_order = qw(
|
||
id
|
||
... | ... | |
unless ($::form->{active_in_report}) {
|
||
$::form->{active_in_report}->{$_} = 1 foreach @default_columns;
|
||
}
|
||
|
||
$self->models->add_additional_url_params(
|
||
active_in_report => $::form->{active_in_report});
|
||
map { $column_defs{$_}->{visible} = $::form->{active_in_report}->{"$_"} }
|
||
keys %column_defs;
|
||
active_in_report => $::form->{active_in_report}
|
||
);
|
||
|
||
$column_defs{$_}->{visible} = $::form->{active_in_report}->{"$_"} || 0
|
||
foreach keys %column_defs;
|
||
|
||
## add cvars TODO: Add own cvars
|
||
#my %cvar_column_defs = map {
|
||
... | ... | |
# make all sortable
|
||
my @sortable = keys %column_defs;
|
||
|
||
my $filter_html = SL::Presenter::ReclamationFilter::filter(
|
||
my $filter_html = SL::Presenter::Filter::Reclamation::filter(
|
||
$::form->{filter}, $self->type, active_in_report => $::form->{active_in_report}
|
||
);
|
||
|
||
... | ... | |
$report->set_columns(%column_defs);
|
||
$report->set_column_order(@columns_order);
|
||
#$report->set_export_options(qw(list filter), @cvar_column_form_names); TODO: for cvars
|
||
$report->set_export_options(qw(list filter active_in_report));
|
||
$report->set_export_options('list', qw(filter active_in_report));
|
||
$report->set_options_from_form;
|
||
$self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
|
||
|
||
return $report;
|
||
}
|
||
|
||
sub _setup_edit_action_bar {
|
||
... | ... | |
$bar->add(
|
||
action => [
|
||
t8('Update'),
|
||
submit => [ '#search_form', { action => 'Reclamation/list', type => $self->type } ],
|
||
submit => [ '#filter_form', { action => 'Reclamation/list', type => $self->type } ],
|
||
accesskey => 'enter',
|
||
],
|
||
link => [
|
SL/Presenter/Filter.pm | ||
---|---|---|
package SL::Presenter::Filter;
|
||
|
||
use strict;
|
||
|
||
use SL::Presenter::EscapedText qw(escape is_escaped);
|
||
use SL::Presenter::Tag qw(html_tag input_tag select_tag date_tag checkbox_tag);
|
||
use SL::Locale::String qw(t8);
|
||
|
||
use Carp;
|
||
use List::Util qw(min);
|
||
use Params::Validate qw(:all);
|
||
|
||
sub create_filter {
|
||
validate_pos(@_,
|
||
{
|
||
type => HASHREF,
|
||
default => {},
|
||
callbacks => {
|
||
has_all_keys => sub {
|
||
foreach my $main_key (keys %{$_[0]}) {
|
||
foreach my $sub_key (qw(
|
||
position text input_type input_name
|
||
)) {
|
||
return die "Key '$sub_key' is missing under '$main_key'."
|
||
unless exists $_[0]->{$main_key}->{$sub_key};
|
||
}
|
||
}
|
||
return 1;
|
||
}
|
||
},
|
||
},
|
||
(0) x (@_ - 1) # allow extra parameters
|
||
);
|
||
my $filter_elements = shift @_;
|
||
my %params = validate_with(
|
||
params => \@_,
|
||
spec => {
|
||
},
|
||
allow_extra => 1,
|
||
);
|
||
|
||
my @filter_element_params =
|
||
sort { $a->{position} <=> $b->{position} }
|
||
grep { $_->{active} }
|
||
values %{$filter_elements};
|
||
|
||
my @filter_elements;
|
||
for my $filter_element_param (@filter_element_params) {
|
||
|
||
my $filter_element = _create_input_element($filter_element_param, %params);
|
||
|
||
push @filter_elements, $filter_element;
|
||
}
|
||
|
||
my $filter_form_div = _create_filter_form(\@filter_elements, %params);
|
||
|
||
is_escaped($filter_form_div);
|
||
}
|
||
|
||
sub _create_input_element {
|
||
my $element_param = shift @_;
|
||
my %params = validate_with(
|
||
params => \@_,
|
||
spec => {
|
||
no_show => {
|
||
type => BOOLEAN,
|
||
default => 0
|
||
},
|
||
active_in_report => {
|
||
type => HASHREF,
|
||
default => {}
|
||
},
|
||
},
|
||
allow_extra => 1,
|
||
);
|
||
|
||
my $element_th = html_tag('th', $element_param->{text}, align => 'right');
|
||
|
||
my $element_input = '';
|
||
|
||
if($element_param->{input_type} eq 'input_tag') {
|
||
|
||
$element_input = input_tag($element_param->{input_name}, $element_param->{input_default});
|
||
|
||
} elsif ($element_param->{input_type} eq 'select_tag') {
|
||
|
||
$element_input = select_tag($element_param->{input_name}, $element_param->{input_values}, default => $element_param->{input_default})
|
||
|
||
} elsif ($element_param->{input_type} eq 'yes_no_tag') {
|
||
|
||
$element_input = select_tag($element_param->{input_name}, [ [ 1 => t8('Yes') ], [ 0 => t8('No') ] ], default => $element_param->{input_default}, with_empty => 1)
|
||
|
||
} elsif($element_param->{input_type} eq 'date_tag') {
|
||
|
||
my $after_input =
|
||
html_tag('th', t8("After"), align => 'right') .
|
||
html_tag('td',
|
||
date_tag("filter." . $element_param->{input_name} . ":date::ge", $element_param->{input_default_ge})
|
||
)
|
||
;
|
||
my $before_input =
|
||
html_tag('th', t8("Before"), align => 'right') .
|
||
html_tag('td',
|
||
date_tag("filter." . $element_param->{input_name} . ":date::le", $element_param->{input_default_le})
|
||
)
|
||
;
|
||
|
||
$element_input =
|
||
html_tag('table',
|
||
html_tag('tr', $after_input)
|
||
.
|
||
html_tag('tr', $before_input)
|
||
)
|
||
;
|
||
} else {
|
||
confess "unknown input_type " . $element_param->{input_type};
|
||
}
|
||
|
||
my $element_input_td = html_tag('td',
|
||
$element_input,
|
||
nowrap => 1,
|
||
);
|
||
|
||
my $element_checkbox_td = '';
|
||
unless($params{no_show} || $element_param->{report_id} eq '') {
|
||
my $checkbox = checkbox_tag(
|
||
'active_in_report.' . $element_param->{report_id},
|
||
checked => $params{active_in_report}->{$element_param->{report_id}},
|
||
for_submit => 1
|
||
);
|
||
$element_checkbox_td = html_tag('td', $checkbox);
|
||
}
|
||
|
||
return $element_th . $element_input_td . $element_checkbox_td;
|
||
}
|
||
|
||
sub _create_filter_form {
|
||
my $ref_elements = shift @_;
|
||
my %params = validate_with(
|
||
params => \@_,
|
||
spec => {
|
||
},
|
||
allow_extra => 1,
|
||
);
|
||
|
||
my $filter_table = _create_input_div($ref_elements, %params);
|
||
|
||
my $filter_form = html_tag('form', $filter_table, method => 'post', action => 'controller.pl', id => 'filter_form');
|
||
|
||
return $filter_form;
|
||
}
|
||
|
||
sub _create_input_div {
|
||
my $ref_elements = shift @_;
|
||
my %params = validate_with(
|
||
params => \@_,
|
||
spec => {
|
||
count_columns => {
|
||
type => SCALAR,
|
||
default => 4,
|
||
},
|
||
no_show => {
|
||
type => BOOLEAN,
|
||
default => 0,
|
||
},
|
||
},
|
||
allow_extra => 1,
|
||
);
|
||
my @elements = @{$ref_elements};
|
||
|
||
my $div_columns = "";
|
||
|
||
my $elements_per_column = (int((scalar(@{$ref_elements}) - 1) / $params{count_columns}) + 1);
|
||
for my $i (0 .. (min(scalar @elements, $params{count_columns}) - 1)) {
|
||
|
||
my $rows = "";
|
||
for my $j (0 .. ($elements_per_column - 1) ) {
|
||
my $idx = $elements_per_column * $i + $j;
|
||
my $element = $elements[$idx];
|
||
$rows .= html_tag('tr', $element);
|
||
|
||
}
|
||
$div_columns .= html_tag('div',
|
||
html_tag('table',
|
||
html_tag('tr',
|
||
html_tag('td')
|
||
. html_tag('th', t8('Filter'))
|
||
. ( $params{no_show} ? '' : html_tag('th', t8('Show')) )
|
||
)
|
||
. $rows
|
||
),
|
||
style => "flex:1");
|
||
}
|
||
|
||
my $input_div = html_tag('div', $div_columns, style => "display:flex;flex-wrap:wrap");
|
||
|
||
return $input_div;
|
||
}
|
||
|
||
1;
|
||
|
||
__END__
|
||
|
||
=pod
|
||
|
||
=encoding utf8
|
||
|
||
=head1 NAME
|
||
|
||
SL::Presenter::Filter - Presenter module for a generic Filter.
|
||
|
||
=head1 SYNOPSIS
|
||
|
||
my $filter_elements = {
|
||
id => {
|
||
'position' => 1,
|
||
'text' => t8("ID"),
|
||
'input_type' => 'input_tag',
|
||
'input_name' => 'filter.id:number',
|
||
'input_default' => $::form->{filter}->{'id:number'},
|
||
'report_id' => 'id',
|
||
'active' => 1,
|
||
},
|
||
# ...
|
||
};
|
||
|
||
my $filter_html = SL::Presenter::Filter::create_filter(
|
||
$filter_elements,
|
||
active_in_report => ['id'],
|
||
);
|
||
|
||
|
||
=head1 FUNCTIONS
|
||
|
||
=over 4
|
||
|
||
=item C<create_filter $filter_elements, %params>
|
||
|
||
Returns a rendered version (actually an instance of
|
||
L<SL::Presenter::EscapedText>) of a filter form for reclamations of type
|
||
C<$reclamation_type>.
|
||
|
||
C<$filter_elements> is a hash reference with the values declaring which inputs
|
||
to create.
|
||
|
||
=over 2
|
||
|
||
FILTER ELEMENTS
|
||
|
||
A filter element is a hash reference. Each filter has a unique key and can have
|
||
entries for:
|
||
|
||
=over 4
|
||
|
||
=item * position (mandatory |
S:Presenter:Filter: Separaten Presenter für komplexe Berichtsfilter