$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');
-}
-sub action_move_down {
- my ($self) = @_;
- $self->{payment_term}->move_position_down;
- $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(type => 'js', inline => '1;');
}
#
[% USE HTML %][% USE T8 %][% USE L %][% USE LxERP %]
+
+<script type="text/javascript" src="js/jquery-ui.js"></script>
+
<body>
<div class="listtop">[% FORM.title %]</div>
</p>
[%- ELSE %]
- <table>
+ <table id="payment_term_list">
+ <thead>
<tr class="listheading">
- <th align="center"><img src="image/up.png"></th>
- <th align="center"><img src="image/down.png"></th>
+ <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
<th>[%- 'Description' | $T8 %]</th>
<th>[%- 'Long Description' | $T8 %]</th>
<th align="right">[%- 'Netto Terms' | $T8 %]</th>
<th align="right">[%- 'Skonto Terms' | $T8 %]</th>
<th align="right">[%- 'Skonto' | $T8 %]</th>
</tr>
+ </thead>
+ <tbody>
[%- FOREACH payment_term = PAYMENT_TERMS %]
- <tr class="listrow[% loop.count % 2 %]">
- <td align="center">
- [%- UNLESS loop.first %]
- <a href="[% SELF.url_for(action => 'move_up', id => payment_term.id) %]"><img src="image/up.png" border="0"></a>
- [%- END %]
- </td>
- <td align="center">
- [%- UNLESS loop.last %]
- <a href="[% SELF.url_for(action => 'move_down', id => payment_term.id) %]"><img src="image/down.png" border="0"></a>
- [%- END %]
- </td>
+ <tr class="listrow[% loop.count % 2 %]" id="payment_term_id_[% payment_term.id %]">
+ <td align="center" class="dragdrop"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
<td>
<a href="[% SELF.url_for(action => 'edit', id => payment_term.id) %]">
[%- HTML.escape(payment_term.description) %]
<td align="right">[%- HTML.escape(payment_term.percent_skonto_as_number) %] %</td>
</tr>
[%- END %]
+ </tbody>
</table>
[%- END %]
</p>
</form>
+ [% L.sortable_element('#payment_term_list tbody', url => 'controller.pl?action=PaymentTerm/reorder', with => 'payment_term_id') %]
+
</body>
</html>