--- /dev/null
+package SL::Controller::Warehouse;
+
+use strict;
+
+use parent qw(SL::Controller::Base);
+
+use SL::DB::Warehouse;
+
+__PACKAGE__->run_before('check_auth');
+
+#
+# actions
+#
+
+sub action_reorder {
+ my ($self) = @_;
+
+ my @ids = @{ $::form->{warehouse_id} || [] };
+ my $result = SL::DB::Warehouse->new->db->do_transaction(sub {
+ foreach my $idx (0 .. scalar(@ids) - 1) {
+ SL::DB::Warehouse->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1);
+ }
+ });
+
+ $self->render(type => 'js', inline => '1;');
+}
+
+#
+# filters
+#
+
+sub check_auth {
+ $::auth->assert('config');
+}
+
+1;
AM->get_all_warehouses(\%myconfig, $form);
- my $previous;
- foreach my $current (@{ $form->{WAREHOUSES} }) {
- if ($previous) {
- $previous->{next_id} = $current->{id};
- $current->{previous_id} = $previous->{id};
- }
-
- $previous = $current;
- }
-
$form->{callback} = build_std_url('action=list_warehouses');
$form->{title} = $locale->text('Warehouses');
$form->{url_base} = build_std_url('callback');
$main::lxdebug->leave_sub();
}
-sub swap_warehouses {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
-
- $main::auth->assert('config');
-
- AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
- list_warehouses();
-
- $main::lxdebug->leave_sub();
-}
-
sub delete_warehouse {
$main::lxdebug->enter_sub();
-[%- USE T8 %]
-[% USE HTML %]<body>
+[%- USE T8 %][% USE LxERP %][% USE L %]
+[% USE HTML %]
+
+<script type="text/javascript" src="js/jquery-ui.js"></script>
+
+<body>
[% IF saved_message %]<p>[% saved_message %]</p>[% END %]
<div class="listtop">[% title %]</div>
<p>
- <table width="100%">
- <tr>
- <td class="listheading" width="0%"></td>
- <td class="listheading" width="0%"></td>
- <td class="listheading" width="70%">[% 'Description' | $T8 %]</td>
- <td class="listheading" width="20%">[% 'Number of bins' | $T8 %]</td>
- <td class="listheading" width="10%">[% 'Invalid' | $T8 %]</td>
+ <table width="100%" id="warehouse_list">
+ <tr class="listheading">
+ <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
+ <th width="70%">[% 'Description' | $T8 %]</th>
+ <th width="20%">[% 'Number of bins' | $T8 %]</th>
+ <th width="10%">[% 'Invalid' | $T8 %]</th>
</tr>
- [% SET row_odd = '1' %][% FOREACH warehouse = WAREHOUSES %]
- <tr class="listrow[% IF row_odd %]1[% SET row_odd = '0' %][% ELSE %]0[% SET row_odd = '1' %][% END %]">
- <td>[% IF warehouse.previous_id %]<a href="[% url_base %]&action=swap_warehouses&id1=[% HTML.url(warehouse.previous_id) %]&id2=[% HTML.url(warehouse.id) %]"><img border="0" src="image/up.png"></a>[% END %]</td>
- <td>[% IF warehouse.next_id %]<a href="[% url_base %]&action=swap_warehouses&id1=[% HTML.url(warehouse.next_id) %]&id2=[% HTML.url(warehouse.id) %]"><img border="0" src="image/down.png"></a>[% END %]</td>
+ [% FOREACH warehouse = WAREHOUSES %]
+ <tr class="listrow[% loop.count % 2 %]" id="warehouse_id_[% warehouse.id %]">
+ <td align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
<td><a href="[% url_base %]&action=edit_warehouse&id=[% HTML.url(warehouse.id) %]">[% HTML.escape(warehouse.description) %]</a></td>
<td>[% HTML.escape(warehouse.number_of_bins) %]</td>
<td>[% IF warehouse.invalid %][% 'Yes' | $T8 %][% ELSE %][% 'No' | $T8 %][% END %]</td>
</form>
</p>
+ [% L.sortable_element('#warehouse_list tbody', 'url' => 'controller.pl?action=Warehouse/reorder', 'with' => 'warehouse_id') %]
+
</body>
</html>