diff --git a/SL/Controller/Reclamation.pm b/SL/Controller/Reclamation.pm index f28aca5d3a..960ca5d140 100644 --- a/SL/Controller/Reclamation.pm +++ b/SL/Controller/Reclamation.pm @@ -6,7 +6,7 @@ use parent qw(SL::Controller::Base); 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; @@ -217,9 +217,9 @@ sub action_list { my ($self) = @_; $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 => { @@ -1186,7 +1186,7 @@ sub init_models { 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)), @@ -1672,10 +1672,6 @@ sub prepare_report { 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); @@ -1683,8 +1679,6 @@ sub prepare_report { my $callback = $self->models->get_callback; - $self->{report} = $report; - # TODO: shipto_id is not linked to custom_shipto my @columns_order = qw( id @@ -1892,10 +1886,13 @@ sub prepare_report { 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 { @@ -1915,7 +1912,7 @@ sub prepare_report { # 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} ); @@ -1940,9 +1937,11 @@ sub prepare_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 { @@ -2139,7 +2138,7 @@ sub _setup_search_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 => [ diff --git a/SL/Presenter/Filter.pm b/SL/Presenter/Filter.pm new file mode 100644 index 0000000000..a50e52a0ee --- /dev/null +++ b/SL/Presenter/Filter.pm @@ -0,0 +1,347 @@ +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 + +Returns a rendered version (actually an instance of +L) 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 + +=head1 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) + +Is a number after which the elements are ordered. This can be a float. + +=item * text (mandatory) + +Is shown before the input field. + +=item * input_name (mandatory) + +C is used to set the name of the field, which should match the +filter syntax. + +=item * input_type (mandatory) + +This must be C, C, C or C. It sets +the input type for the filter. + +=over 2 + +=item * input_tag + +Creates a text input field. The default value of this field is set to the +C entry of the filter element. + +=item * select_tag + +Creates a drop down field. C is used to set the options. +See L for more details. The default value +of this field is set to the C entry. + +=item * yes_no_tag + +Creates a yes/no input field. The default value of this field is set to the +C entry. + +=item * date_tag + +Creates two date input fields. One filters for after the date and the other +filters for before the date. The default values of these fields are set to the +C and C entries of the filter element. +For the first field ":date::ge" and for the second ":date::le" is added to the +end of C. + +=back + +=item * report_id + +Is used to generate the id of the check box after the input field. The value of +the check box can be found in the form under +C<$::form-E{'active_in_report'}-E{report_id}>. + +=item * active + +If falsish the element is ignored. + +=item * input_default, input_default_ge, input_default_le + +Look at I to see how they are used. + +=back + +=back + +C<%params> can include: + +=over 2 + +=item * no_show + +If falsish (the default) then a check box is added after the input field. Which +specifies whether the corresponding column appears in the report. The value of +the check box can be changed by the user. + +=item * active_in_report + +If C<$params{no_show}> is falsish, this is used to set the values of the check +boxes, after the input fields. This should be set to the C +value of the last C<$::form>. + +=back + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Tamino Steinert Etamino.steinert@tamino.stE + +=cut diff --git a/SL/Presenter/ReclamationFilter.pm b/SL/Presenter/Filter/Reclamation.pm similarity index 56% rename from SL/Presenter/ReclamationFilter.pm rename to SL/Presenter/Filter/Reclamation.pm index a7f0dc3548..3f4c2715b1 100644 --- a/SL/Presenter/ReclamationFilter.pm +++ b/SL/Presenter/Filter/Reclamation.pm @@ -1,22 +1,14 @@ -package SL::Presenter::ReclamationFilter; +package SL::Presenter::Filter::Reclamation; + +use parent 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 Exporter qw(import); -our @EXPORT_OK = qw( -filter -); - -use Carp; - -sub filter { - my ($filter, $reclamation_type, %params) = @_; +sub get_default_filter_elements { + my ($filter, $reclamation_type) = @_; - $filter ||= undef; #filter should not be '' (empty string); my %default_filter_elements = ( # {{{ 'reason_names' => { 'position' => 1, @@ -31,7 +23,7 @@ sub filter { 'text' => t8("Reclamation ID"), 'input_type' => 'input_tag', 'input_name' => 'filter.id:number', - 'input_default' =>$filter->{'id:number'}, + 'input_default' => $filter->{'id:number'}, 'report_id' => 'id', 'active' => 0, }, @@ -40,7 +32,7 @@ sub filter { 'text' => t8("Reclamation Number"), 'input_type' => 'input_tag', 'input_name' => 'filter.record_number:substr::ilike', - 'input_default' =>$filter->{'record_number:substr::ilike'}, + 'input_default' => $filter->{'record_number:substr::ilike'}, 'report_id' => 'record_number', 'active' => 1, }, @@ -49,7 +41,7 @@ sub filter { 'text' => t8("Employee Name"), 'input_type' => 'input_tag', 'input_name' => 'filter.employee.name:substr::ilike', - 'input_default' =>$filter->{employee}->{'name:substr::ilike'}, + 'input_default' => $filter->{employee}->{'name:substr::ilike'}, 'report_id' => 'employee', 'active' => 1, }, @@ -58,7 +50,7 @@ sub filter { 'text' => t8("Salesman Name"), 'input_type' => 'input_tag', 'input_name' => 'filter.salesman.name:substr::ilike', - 'input_default' =>$filter->{salesman}->{'name:substr::ilike'}, + 'input_default' => $filter->{salesman}->{'name:substr::ilike'}, 'report_id' => 'salesman', 'active' => 1, }, @@ -102,7 +94,7 @@ sub filter { 'text' => t8("Contact Name"), 'input_type' => 'input_tag', 'input_name' => 'filter.contact.cp_name:substr::ilike', - 'input_default' =>$filter->{contact}->{'cp_name:substr::ilike'}, + 'input_default' => $filter->{contact}->{'cp_name:substr::ilike'}, 'report_id' => 'contact', 'active' => 1, }, @@ -111,7 +103,7 @@ sub filter { 'text' => t8("Language Code"), 'input_type' => 'input_tag', 'input_name' => 'filter.language.article_code:substr::ilike', - 'input_default' =>$filter->{language}->{'article_code:substr::ilike'}, + 'input_default' => $filter->{language}->{'article_code:substr::ilike'}, 'report_id' => 'language', 'active' => 1, }, @@ -120,7 +112,7 @@ sub filter { 'text' => t8("Department Description"), 'input_type' => 'input_tag', 'input_name' => 'filter.department.description:substr::ilike', - 'input_default' =>$filter->{department}->{'description:substr::ilike'}, + 'input_default' => $filter->{department}->{'description:substr::ilike'}, 'report_id' => 'department', 'active' => 1, }, @@ -129,7 +121,7 @@ sub filter { 'text' => t8("Project Number"), 'input_type' => 'input_tag', 'input_name' => 'filter.globalproject.projectnumber:substr::ilike', - 'input_default' =>$filter->{globalproject}->{'projectnumber:substr::ilike'}, + 'input_default' => $filter->{globalproject}->{'projectnumber:substr::ilike'}, 'report_id' => 'globalproject', 'active' => 1, }, @@ -138,7 +130,7 @@ sub filter { 'text' => t8("Project Description"), 'input_type' => 'input_tag', 'input_name' => 'filter.globalproject.description:substr::ilike', - 'input_default' =>$filter->{globalproject}->{'description:substr::ilike'}, + 'input_default' => $filter->{globalproject}->{'description:substr::ilike'}, 'active' => 1, }, 'cv_record_number' => { @@ -158,7 +150,7 @@ sub filter { 'text' => t8("Description"), 'input_type' => 'input_tag', 'input_name' => 'filter.transaction_description:substr::ilike', - 'input_default' =>$filter->{'transaction_description:substr::ilike'}, + 'input_default' => $filter->{'transaction_description:substr::ilike'}, 'report_id' => 'transaction_description', 'active' => 1, }, @@ -167,7 +159,7 @@ sub filter { 'text' => t8("Notes"), 'input_type' => 'input_tag', 'input_name' => 'filter.notes:substr::ilike', - 'input_default' =>$filter->{'notes:substr::ilike'}, + 'input_default' => $filter->{'notes:substr::ilike'}, 'report_id' => 'notes', 'active' => 1, }, @@ -176,7 +168,7 @@ sub filter { 'text' => t8("Internal Notes"), 'input_type' => 'input_tag', 'input_name' => 'filter.intnotes:substr::ilike', - 'input_default' =>$filter->{'intnotes:substr::ilike'}, + 'input_default' => $filter->{'intnotes:substr::ilike'}, 'report_id' => 'intnotes', 'active' => 1, }, @@ -185,7 +177,7 @@ sub filter { 'text' => t8("Shipping Point"), 'input_type' => 'input_tag', 'input_name' => 'filter.shippingpoint:substr::ilike', - 'input_default' =>$filter->{'shippingpoint:substr::ilike'}, + 'input_default' => $filter->{'shippingpoint:substr::ilike'}, 'report_id' => 'shippingpoint', 'active' => 1, }, @@ -194,7 +186,7 @@ sub filter { 'text' => t8("Ship via"), 'input_type' => 'input_tag', 'input_name' => 'filter.shipvia:substr::ilike', - 'input_default' =>$filter->{'shipvia:substr::ilike'}, + 'input_default' => $filter->{'shipvia:substr::ilike'}, 'report_id' => 'shipvia', 'active' => 1, }, @@ -203,7 +195,7 @@ sub filter { 'text' => t8("Total"), 'input_type' => 'input_tag', 'input_name' => 'filter.amount:number', - 'input_default' =>$filter->{'amount:number'}, + 'input_default' => $filter->{'amount:number'}, 'report_id' => 'amount', 'active' => 1, }, @@ -212,7 +204,7 @@ sub filter { 'text' => t8("Subtotal"), 'input_type' => 'input_tag', 'input_name' => 'filter.netamount:number', - 'input_default' =>$filter->{'netamount:number'}, + 'input_default' => $filter->{'netamount:number'}, 'report_id' => 'netamount', 'active' => 1, }, @@ -221,7 +213,7 @@ sub filter { 'text' => t8("Delivery Terms"), 'input_type' => 'input_tag', 'input_name' => 'filter.delivery_term.description:substr::ilike', - 'input_default' =>$filter->{delivery_term}->{'description:substr::ilike'}, + 'input_default' => $filter->{delivery_term}->{'description:substr::ilike'}, 'report_id' => 'delivery_term', 'active' => 1, }, @@ -230,7 +222,7 @@ sub filter { 'text' => t8("Payment Terms"), 'input_type' => 'input_tag', 'input_name' => 'filter.payment.description:substr::ilike', - 'input_default' =>$filter->{payment}->{'description:substr::ilike'}, + 'input_default' => $filter->{payment}->{'description:substr::ilike'}, 'report_id' => 'payment', 'active' => 1, }, @@ -239,7 +231,7 @@ sub filter { 'text' => t8("Currency"), 'input_type' => 'input_tag', 'input_name' => 'filter.currency.name:substr::ilike', - 'input_default' =>$filter->{currency}->{'name:substr::ilike'}, + 'input_default' => $filter->{currency}->{'name:substr::ilike'}, 'report_id' => 'currency', 'active' => 1, }, @@ -248,7 +240,7 @@ sub filter { 'text' => t8("Exchangerate"), 'input_type' => 'input_tag', 'input_name' => 'filter.exchangerate:number', - 'input_default' =>$filter->{'exchangerate:number'}, + 'input_default' => $filter->{'exchangerate:number'}, 'report_id' => 'exchangerate', 'active' => 1, }, @@ -257,7 +249,7 @@ sub filter { 'text' => t8("Tax Included"), 'input_type' => 'yes_no_tag', 'input_name' => 'filter.taxincluded', - 'input_default' =>$filter->{taxincluded}, + 'input_default' => $filter->{taxincluded}, 'report_id' => 'taxincluded', 'active' => 1, }, @@ -266,7 +258,7 @@ sub filter { 'text' => t8("Tax zone"), 'input_type' => 'input_tag', 'input_name' => 'filter.taxzone.description:substr::ilike', - 'input_default' =>$filter->{taxzone}->{'description:substr::ilike'}, + 'input_default' => $filter->{taxzone}->{'description:substr::ilike'}, 'report_id' => 'taxzone', 'active' => 1, }, @@ -325,7 +317,7 @@ sub filter { 'text' => t8("Delivered"), 'input_type' => 'yes_no_tag', 'input_name' => 'filter.delivered', - 'input_default' =>$filter->{delivered}, + 'input_default' => $filter->{delivered}, 'report_id' => 'delivered', 'active' => 1, }, @@ -334,142 +326,24 @@ sub filter { 'text' => t8("Closed"), 'input_type' => 'yes_no_tag', 'input_name' => 'filter.closed', - 'input_default' =>$filter->{closed}, + 'input_default' => $filter->{closed}, 'report_id' => 'closed', 'active' => 1, }, ); # }}} - - # combine default and param values for filter_element, - # only replace the lowest occurrence - my %filter_elements = %default_filter_elements; - while(my ($key, $value) = each (%{$params{filter_elements}})) { - if(exists $filter_elements{$key}) { - $filter_elements{$key} = ({ - %{$filter_elements{$key}}, - %{$value}, - }); - } else { - $filter_elements{$key} = $value; - } - } - - 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) { - unless($filter_element_param->{active}) { - next; - } - - 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, %params) = @_; - - 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 '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) - ) - ; - } - - 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; + return \%default_filter_elements; } -sub _create_filter_form { - my ($ref_elements, %params) = @_; - - my $filter_table = _create_input_div($ref_elements, %params); - - my $filter_form = html_tag('form', $filter_table, method => 'post', action => 'controller.pl', id => 'search_form'); - - return $filter_form; -} - -sub _create_input_div { - my ($ref_elements, %params) = @_; - my @elements = @{$ref_elements}; - - my $div_columns = ""; - - $params{count_columns} ||= 4; - my $elements_per_column = (int((scalar(@{$ref_elements}) - 1) / $params{count_columns}) + 1); - for my $i (0 .. ($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); +sub filter { + my ($filter, $reclamation_type, %params) = @_; - } - $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"); - } + $filter ||= undef; #filter should not be '' (empty string); - my $input_div = html_tag('div', $div_columns, style => "display:flex;flex-wrap:wrap"); + # combine default and param values for filter_element, + # only replace the lowest occurrence + my $filter_elements = get_default_filter_elements($filter, $reclamation_type); - return $input_div; + return SL::Presenter::Filter::create_filter($filter_elements, %params); } 1; @@ -482,13 +356,13 @@ __END__ =head1 NAME -SL::Presenter::ReclamationFilter - Presenter module for a generic Filter on +SL::Presenter::Filter::Reclamation - Presenter module for a generic Filter on Reclamation. =head1 SYNOPSIS # in Reclamation Controller - 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} ); @@ -506,95 +380,7 @@ C<$reclamation_type>. C<$filter> should be the C value of the last C<$::form>. This is used to get the previous values of the input fields. -C<%params> can include: - -=over 2 - -=item * no_show - -If falsish (the default) then a check box is added after the input field. Which -specifies whether the corresponding column appears in the report. The value of -the check box can be changed by the user. - -=item * active_in_report - -If C<$params{no_show}> is falsish, this is used to set the values of the check -boxes, after the input fields. This can be set to the C value -of the last C<$::form>. - -=item * filter_elements - -Is combined with the default filter elements. This can be used to override -default values of the filter elements or to add a new ones. - - #deactivate the id and record_number fields - $params{filter_elements} = ({ - id => {active => 0}, - record_number => {active => 0} - }); - -=back - -=back - -=head1 FILTER ELEMENTS - -A filter element is stored in and as a hash map. Each filter has a unique key -and should have entries for: - -=over 4 - -=item * position - -Is a number after which the elements are ordered. This can be a float. - -=item * text - -Is shown before the input field. - -=item * input_type - -This must be C, C or C. It sets the input type -for the filter. - -=over 2 - -=item * input_tag - -Creates a text input field. The default value of this field is set to the -C entry of the filter element. C is used to set the -name of the field, which should match the filter syntax. - -=item * yes_no_tag - -Creates a yes/no input field. The default value of this field is set to the -C entry of the filter element. C is used to set the -name of the field, which should match the filter syntax. - -=item * date_tag - -Creates two date input fields. One filters for after the date and the other -filters for before the date. The default values of these fields are set to the -C and C entries of the filter element. -C is used to set the names of these fields, which should match the -filter syntax. For the first field ":date::ge" and for the second ":date::le" is -added to the end of C. - -=back - -=item * report_id - -Is used to generate the id of the check box after the input field. The value of -the check box can be found in the form under -C<$::form-E{'active_in_report'}-E{report_id}>. - -=item * active - -If falsish the element is ignored. - -=item * input_name, input_default, input_default_ge, input_default_le - -Look at I to see how they are used. +C<%params> fields get forwarded to C. =back