From 4bcb450849ddc6e67f7c7181b20c5912b604cdd1 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 4 Sep 2012 15:29:55 +0200 Subject: [PATCH] DeliveryPlan-Controller auf Paginate-Controller-Helper umstellen --- SL/Controller/DeliveryPlan.pm | 36 +++++++++++++------ .../webpages/delivery_plan/report_bottom.html | 6 ++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/SL/Controller/DeliveryPlan.pm b/SL/Controller/DeliveryPlan.pm index e280a1b99..cc6ec4f7e 100644 --- a/SL/Controller/DeliveryPlan.pm +++ b/SL/Controller/DeliveryPlan.pm @@ -5,22 +5,41 @@ use parent qw(SL::Controller::Base); use Clone qw(clone); use SL::DB::OrderItem; +use SL::Controller::Helper::GetModels; +use SL::Controller::Helper::Paginated; use SL::Controller::Helper::ParseFilter; use SL::Controller::Helper::ReportGenerator; +use Rose::Object::MakeMethods::Generic +( + scalar => [ qw(db_args) ], +); + __PACKAGE__->run_before(sub { $::auth->assert('sales_order_edit'); }); +__PACKAGE__->get_models_url_params(sub { + my ($self) = @_; + return ( + %{ $self->{flat_filter} || {} }, + sort_dir => $self->{sort_dir}, + sort_by => $self->{sort_by}, + ); +}); +__PACKAGE__->make_paginated( + MODEL => 'OrderItem', + PAGINATE_ARGS => 'db_args', + ONLY => [ qw(list) ], +); + sub action_list { my ($self) = @_; my %list_params = ( sort_by => $::form->{sort_by} || 'reqdate', sort_dir => $::form->{sort_dir}, filter => $::form->{filter}, - page => $::form->{page}, ); - my $db_args = $self->setup_for_list(%list_params); - $self->{pages} = SL::DB::Manager::OrderItem->paginate(%list_params, args => $db_args); + $self->db_args($self->setup_for_list(%list_params)); $self->{flat_filter} = { map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') }; $self->make_filter_summary; @@ -36,10 +55,9 @@ sub action_list { report_generator_export_options => [ 'list', qw(filter sort_by sort_dir), ], - db_args => $db_args, ); - $self->{orderitems} = SL::DB::Manager::OrderItem->get_all(%$db_args); + $self->{orderitems} = $self->get_models(%{ $self->db_args }); $self->list_objects; } @@ -56,7 +74,6 @@ sub setup_for_list { launder_to => $self->{filter}, ), sort_by => $self->set_sort_params(%params), - page => $params{page}, ); $args{query} = [ @{ $args{query} || [] }, @@ -160,12 +177,9 @@ sub prepare_report { for my $col (@sortable) { - $column_defs{$col}{link} = $self->url_for( - action => 'list', + $column_defs{$col}{link} = $self->get_callback( sort_by => $col, sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}), - page => $self->{pages}{cur}, - %{ $self->{flat_filter} }, ); } @@ -184,7 +198,7 @@ sub prepare_report { ); $report->set_options_from_form; - SL::DB::Manager::OrderItem->disable_paginating(args => $params{db_args}) if $report->{options}{output_format} =~ /^(pdf|csv)$/i; + $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i; $self->{report_data} = { column_defs => \%column_defs, diff --git a/templates/webpages/delivery_plan/report_bottom.html b/templates/webpages/delivery_plan/report_bottom.html index 1843c054c..79e152304 100644 --- a/templates/webpages/delivery_plan/report_bottom.html +++ b/templates/webpages/delivery_plan/report_bottom.html @@ -1,4 +1,2 @@ -[% SET report_bottom_url_args = {} %] -[% report_bottom_url_args.import(SELF.flat_filter) %] -[% report_bottom_url_args.import({action='list', sort_dir=SELF.sort_dir, sort_by=SELF.sort_by}) %] -[% PROCESS 'common/paginate.html' pages=SELF.pages, base_url=SELF.url_for(report_bottom_url_args) %] +[% USE L %] +[%- L.paginate_controls %] -- 2.20.1