Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 047a0b57

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 047a0b577ec117c9061d40728803c70ff8191962
  • Vorgänger 88933549
  • Nachfolger 7fb610a5

Sortieren von Lagerhäusern auf Drag-n-Drop & AJAX mittels jQuery UI Sortable umgestellt

Unterschiede anzeigen:

SL/Controller/Warehouse.pm
1
package SL::Controller::Warehouse;
2

  
3
use strict;
4

  
5
use parent qw(SL::Controller::Base);
6

  
7
use SL::DB::Warehouse;
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->{warehouse_id} || [] };
19
  my $result = SL::DB::Warehouse->new->db->do_transaction(sub {
20
    foreach my $idx (0 .. scalar(@ids) - 1) {
21
      SL::DB::Warehouse->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1);
22
    }
23
  });
24

  
25
  $self->render(type => 'js', inline => '1;');
26
}
27

  
28
#
29
# filters
30
#
31

  
32
sub check_auth {
33
  $::auth->assert('config');
34
}
35

  
36
1;
bin/mozilla/am.pl
3230 3230

  
3231 3231
  AM->get_all_warehouses(\%myconfig, $form);
3232 3232

  
3233
  my $previous;
3234
  foreach my $current (@{ $form->{WAREHOUSES} }) {
3235
    if ($previous) {
3236
      $previous->{next_id}    = $current->{id};
3237
      $current->{previous_id} = $previous->{id};
3238
    }
3239

  
3240
    $previous = $current;
3241
  }
3242

  
3243 3233
  $form->{callback} = build_std_url('action=list_warehouses');
3244 3234
  $form->{title}    = $locale->text('Warehouses');
3245 3235
  $form->{url_base} = build_std_url('callback');
......
3272 3262
  $main::lxdebug->leave_sub();
3273 3263
}
3274 3264

  
3275
sub swap_warehouses {
3276
  $main::lxdebug->enter_sub();
3277

  
3278
  my $form     = $main::form;
3279
  my %myconfig = %main::myconfig;
3280

  
3281
  $main::auth->assert('config');
3282

  
3283
  AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
3284
  list_warehouses();
3285

  
3286
  $main::lxdebug->leave_sub();
3287
}
3288

  
3289 3265
sub delete_warehouse {
3290 3266
  $main::lxdebug->enter_sub();
3291 3267

  
templates/webpages/am/list_warehouses.html
1
[%- USE T8 %]
2
[% USE HTML %]<body>
1
[%- USE T8 %][% USE LxERP %][% USE L %]
2
[% USE HTML %]
3

  
4
<script type="text/javascript" src="js/jquery-ui.js"></script>
5

  
6
<body>
3 7

  
4 8
 [% IF saved_message %]<p>[% saved_message %]</p>[% END %]
5 9

  
6 10
 <div class="listtop">[% title %]</div>
7 11

  
8 12
 <p>
9
  <table width="100%">
10
   <tr>
11
    <td class="listheading" width="0%"></td>
12
    <td class="listheading" width="0%"></td>
13
    <td class="listheading" width="70%">[% 'Description' | $T8 %]</td>
14
    <td class="listheading" width="20%">[% 'Number of bins' | $T8 %]</td>
15
    <td class="listheading" width="10%">[% 'Invalid' | $T8 %]</td>
13
  <table width="100%" id="warehouse_list">
14
   <tr class="listheading">
15
    <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
16
    <th width="70%">[% 'Description' | $T8 %]</th>
17
    <th width="20%">[% 'Number of bins' | $T8 %]</th>
18
    <th width="10%">[% 'Invalid' | $T8 %]</th>
16 19
   </tr>
17 20

  
18
   [% SET row_odd = '1' %][% FOREACH warehouse = WAREHOUSES %]
19
   <tr class="listrow[% IF row_odd %]1[% SET row_odd = '0' %][% ELSE %]0[% SET row_odd = '1' %][% END %]">
20
    <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>
21
    <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>
21
   [% FOREACH warehouse = WAREHOUSES %]
22
   <tr class="listrow[% loop.count % 2 %]" id="warehouse_id_[% warehouse.id %]">
23
    <td align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
22 24
    <td><a href="[% url_base %]&action=edit_warehouse&id=[% HTML.url(warehouse.id) %]">[% HTML.escape(warehouse.description) %]</a></td>
23 25
    <td>[% HTML.escape(warehouse.number_of_bins) %]</td>
24 26
    <td>[% IF warehouse.invalid %][% 'Yes' | $T8 %][% ELSE %][% 'No' | $T8 %][% END %]</td>
......
37 39
  </form>
38 40
 </p>
39 41

  
42
 [% L.sortable_element('#warehouse_list tbody', 'url' => 'controller.pl?action=Warehouse/reorder', 'with' => 'warehouse_id') %]
43

  
40 44
</body>
41 45
</html>

Auch abrufbar als: Unified diff