From 8893354909b940b99cb05e85e1964bfc5e805baa Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 11 May 2011 10:39:15 +0200 Subject: [PATCH] Sortieren von Preisfaktoren auf Drag-n-Drop & AJAX mittels jQuery UI Sortable umgestellt --- SL/Controller/PriceFactor.pm | 36 +++++++++++++++++++ bin/mozilla/am.pl | 22 ------------ templates/webpages/am/list_price_factors.html | 28 ++++++++------- 3 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 SL/Controller/PriceFactor.pm diff --git a/SL/Controller/PriceFactor.pm b/SL/Controller/PriceFactor.pm new file mode 100644 index 000000000..31f0e46f1 --- /dev/null +++ b/SL/Controller/PriceFactor.pm @@ -0,0 +1,36 @@ +package SL::Controller::PriceFactor; + +use strict; + +use parent qw(SL::Controller::Base); + +use SL::DB::PriceFactor; + +__PACKAGE__->run_before('check_auth'); + +# +# actions +# + +sub action_reorder { + my ($self) = @_; + + my @ids = @{ $::form->{price_factor_id} || [] }; + my $result = SL::DB::PriceFactor->new->db->do_transaction(sub { + foreach my $idx (0 .. scalar(@ids) - 1) { + SL::DB::PriceFactor->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1); + } + }); + + $self->render(type => 'js', inline => '1;'); +} + +# +# filters +# + +sub check_auth { + $::auth->assert('config'); +} + +1; diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index eacf5df1f..588ad9ae5 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -3123,16 +3123,8 @@ sub list_price_factors { AM->get_all_price_factors(\%myconfig, \%$form); - my $previous; foreach my $current (@{ $form->{PRICE_FACTORS} }) { - if ($previous) { - $previous->{next_id} = $current->{id}; - $current->{previous_id} = $previous->{id}; - } - $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1); - - $previous = $current; } $form->{callback} = build_std_url('action=list_price_factors'); @@ -3186,20 +3178,6 @@ sub delete_price_factor { $main::lxdebug->leave_sub(); } -sub swap_price_factors { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - $main::auth->assert('config'); - - AM->swap_sortkeys(\%myconfig, $form, 'price_factors'); - list_price_factors(); - - $main::lxdebug->leave_sub(); -} - sub add_warehouse { $main::lxdebug->enter_sub(); diff --git a/templates/webpages/am/list_price_factors.html b/templates/webpages/am/list_price_factors.html index 73c9f3130..4c81bbb11 100644 --- a/templates/webpages/am/list_price_factors.html +++ b/templates/webpages/am/list_price_factors.html @@ -1,23 +1,25 @@ -[%- USE T8 %] -[% USE HTML %] +[%- USE T8 %][% USE L %][% USE LxERP %] +[% USE HTML %] + + + + [% IF MESSAGE %]

[% MESSAGE %]

[% END %]
[% title %]

- - - - - - +
[% 'Description' | $T8 %][% 'Factor' | $T8 %]
+ + + + - [% SET row_odd = '1' %][% FOREACH factor = PRICE_FACTORS %] - - - + [% FOREACH factor = PRICE_FACTORS %] + + @@ -36,5 +38,7 @@

+ [% L.sortable_element('#price_factor_list tbody', 'url' => 'controller.pl?action=PriceFactor/reorder', 'with' => 'price_factor_id') %] + -- 2.20.1
[ LxERP.t8('reorder item') %][% 'Description' | $T8 %][% 'Factor' | $T8 %]
[% IF factor.previous_id %][% END %][% IF factor.next_id %][% END %]
[ LxERP.t8('reorder item') %] [% HTML.escape(factor.description) %] [% HTML.escape(factor.factor) %]