From 7fb610a59d0fe90d59796a98cd65846b646341e2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 11 May 2011 11:14:12 +0200 Subject: [PATCH] Sortieren von benutzerdefinierten Variablen auf Drag-n-Drop & AJAX mittels jQuery UI Sortable umgestellt --- SL/Controller/CustomVariableConfig.pm | 36 +++++++++++++++ bin/mozilla/amcvar.pl | 22 --------- .../webpages/amcvar/list_cvar_configs.html | 45 ++++++++----------- 3 files changed, 55 insertions(+), 48 deletions(-) create mode 100644 SL/Controller/CustomVariableConfig.pm diff --git a/SL/Controller/CustomVariableConfig.pm b/SL/Controller/CustomVariableConfig.pm new file mode 100644 index 000000000..0c47799de --- /dev/null +++ b/SL/Controller/CustomVariableConfig.pm @@ -0,0 +1,36 @@ +package SL::Controller::CustomVariableConfig; + +use strict; + +use parent qw(SL::Controller::Base); + +use SL::DB::CustomVariableConfig; + +__PACKAGE__->run_before('check_auth'); + +# +# actions +# + +sub action_reorder { + my ($self) = @_; + + my @ids = @{ $::form->{cvarcfg_id} || [] }; + my $result = SL::DB::CustomVariableConfig->new->db->do_transaction(sub { + foreach my $idx (0 .. scalar(@ids) - 1) { + SL::DB::CustomVariableConfig->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/amcvar.pl b/bin/mozilla/amcvar.pl index 3be956a72..fc4f26f14 100644 --- a/bin/mozilla/amcvar.pl +++ b/bin/mozilla/amcvar.pl @@ -90,17 +90,8 @@ sub list_cvar_configs { my @configs = @{ CVar->get_configs(module => $form->{module}) }; - my $previous_config; - foreach my $config (@configs) { $config->{type_tr} = $translations{$config->{type}}; - - if ($previous_config) { - $previous_config->{next_id} = $config->{id}; - $config->{previous_id} = $previous_config->{id}; - } - - $previous_config = $config; } $form->{title} = $locale->text('List of custom variables'); @@ -219,19 +210,6 @@ sub display_cvar_config_form { $main::lxdebug->leave_sub(); } -sub swap_cvar_configs { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - AM->swap_sortkeys(\%myconfig, $form, 'custom_variable_configs'); - - list_cvar_configs(); - - $main::lxdebug->leave_sub(); -} - sub dispatcher { my $form = $main::form; my $locale = $main::locale; diff --git a/templates/webpages/amcvar/list_cvar_configs.html b/templates/webpages/amcvar/list_cvar_configs.html index f2890f780..7652a01d6 100644 --- a/templates/webpages/amcvar/list_cvar_configs.html +++ b/templates/webpages/amcvar/list_cvar_configs.html @@ -1,5 +1,9 @@ -[%- USE T8 %] -[% USE HTML %] +[%- USE T8 %][% USE LxERP %][% USE L %] +[% USE HTML %] + + + + [% IF MESSAGE %]

[% MESSAGE %]

[% END %] @@ -20,35 +24,22 @@

- - - - - - - - - +
[% 'Name' | $T8 %][% 'Description' | $T8 %][% 'Type' | $T8 %][% 'Searchable' | $T8 %][% 'Includeable in reports' | $T8 %]
+ + + + + + + [%- IF module == 'IC' %] - + [%- END %] [%- FOREACH cfg = CONFIGS %] - - - - + +
[ LxERP.t8('reorder item') %][% 'Name' | $T8 %][% 'Description' | $T8 %][% 'Type' | $T8 %][% 'Searchable' | $T8 %][% 'Includeable in reports' | $T8 %][% 'Editable' | $T8 %][% 'Editable' | $T8 %]
- [%- IF cfg.previous_id %] - - - [%- END %] - - [%- IF cfg.next_id %] - - - [%- END %] -
[ LxERP.t8('reorder item') %] @@ -98,5 +89,7 @@

+ [% L.sortable_element('#cvarcfg_list tbody', 'url' => 'controller.pl?action=CustomVariableConfig/reorder', 'with' => 'cvarcfg_id') %] + -- 2.20.1