Fehlerhafte renders für Ajax reordering
[kivitendo-erp.git] / SL / Controller / Unit.pm
1 package SL::Controller::Unit;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::DB::Unit;
8
9 __PACKAGE__->run_before('check_auth');
10
11 #
12 # actions
13 #
14
15 sub action_reorder {
16   my ($self) = @_;
17
18   my @ids = @{ $::form->{unit_id} || [] };
19   my $result = SL::DB::Unit->new->db->do_transaction(sub {
20     foreach my $idx (0 .. scalar(@ids) - 1) {
21       SL::DB::Unit->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1);
22     }
23   });
24
25   $self->render('1;', { type => 'js', inline => 1 });
26 }
27
28 #
29 # filters
30 #
31
32 sub check_auth {
33   $::auth->assert('config');
34 }
35
36 1;