Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / Controller / PaymentTerm.pm
index 631428e..3a768a2 100644 (file)
@@ -13,7 +13,8 @@ use Rose::Object::MakeMethods::Generic
  scalar => [ qw(payment_term languages) ],
 );
 
-__PACKAGE__->run_before('load_payment_term', only => [ qw(         edit        update destroy move_up move_down) ]);
+__PACKAGE__->run_before('check_auth');
+__PACKAGE__->run_before('load_payment_term', only => [ qw(         edit        update destroy) ]);
 __PACKAGE__->run_before('load_languages',    only => [ qw(new list edit create update) ]);
 
 #
@@ -64,16 +65,25 @@ sub action_destroy {
   $self->redirect_to(action => 'list');
 }
 
-sub action_move_up {
+sub action_reorder {
   my ($self) = @_;
-  $self->{payment_term}->move_position_up;
-  $self->redirect_to(action => 'list');
+
+  my @ids = @{ $::form->{payment_term_id} || [] };
+  my $result = SL::DB::PaymentTerm->new->db->do_transaction(sub {
+    foreach my $idx (0 .. scalar(@ids) - 1) {
+      SL::DB::PaymentTerm->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1);
+    }
+  });
+
+  $self->render('1;', { type => 'js', inline => 1 });
 }
 
-sub action_move_down {
-  my ($self) = @_;
-  $self->{payment_term}->move_position_down;
-  $self->redirect_to(action => 'list');
+#
+# filters
+#
+
+sub check_auth {
+  $::auth->assert('config');
 }
 
 #