Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 88933549

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 8893354909b940b99cb05e85e1964bfc5e805baa
  • Vorgänger fa515ecf
  • Nachfolger 047a0b57

Sortieren von Preisfaktoren auf Drag-n-Drop & AJAX mittels jQuery UI Sortable umgestellt

Unterschiede anzeigen:

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

  
3
use strict;
4

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

  
7
use SL::DB::PriceFactor;
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->{price_factor_id} || [] };
19
  my $result = SL::DB::PriceFactor->new->db->do_transaction(sub {
20
    foreach my $idx (0 .. scalar(@ids) - 1) {
21
      SL::DB::PriceFactor->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
3123 3123

  
3124 3124
  AM->get_all_price_factors(\%myconfig, \%$form);
3125 3125

  
3126
  my $previous;
3127 3126
  foreach my $current (@{ $form->{PRICE_FACTORS} }) {
3128
    if ($previous) {
3129
      $previous->{next_id}    = $current->{id};
3130
      $current->{previous_id} = $previous->{id};
3131
    }
3132

  
3133 3127
    $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
3134

  
3135
    $previous = $current;
3136 3128
  }
3137 3129

  
3138 3130
  $form->{callback} = build_std_url('action=list_price_factors');
......
3186 3178
  $main::lxdebug->leave_sub();
3187 3179
}
3188 3180

  
3189
sub swap_price_factors {
3190
  $main::lxdebug->enter_sub();
3191

  
3192
  my $form     = $main::form;
3193
  my %myconfig = %main::myconfig;
3194

  
3195
  $main::auth->assert('config');
3196

  
3197
  AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
3198
  list_price_factors();
3199

  
3200
  $main::lxdebug->leave_sub();
3201
}
3202

  
3203 3181
sub add_warehouse {
3204 3182
  $main::lxdebug->enter_sub();
3205 3183

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

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

  
6
<body>
3 7

  
4 8
 [% IF MESSAGE %]<p>[% 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="80%">[% 'Description' | $T8 %]</td>
14
    <td class="listheading" width="20%">[% 'Factor' | $T8 %]</td>
13
  <table width="100%" id="price_factor_list">
14
   <tr class="listheading">
15
    <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
16
    <th width="80%">[% 'Description' | $T8 %]</th>
17
    <th width="20%">[% 'Factor' | $T8 %]</th>
15 18
   </tr>
16 19

  
17
   [% SET row_odd = '1' %][% FOREACH factor = PRICE_FACTORS %]
18
   <tr class="listrow[% IF row_odd %]1[% SET row_odd = '0' %][% ELSE %]0[% SET row_odd = '1' %][% END %]">
19
    <td>[% IF factor.previous_id %]<a href="[% url_base %]&action=swap_price_factors&id1=[% HTML.url(factor.previous_id) %]&id2=[% HTML.url(factor.id) %]"><img border="0" src="image/up.png"></a>[% END %]</td>
20
    <td>[% IF factor.next_id %]<a href="[% url_base %]&action=swap_price_factors&id1=[% HTML.url(factor.next_id) %]&id2=[% HTML.url(factor.id) %]"><img border="0" src="image/down.png"></a>[% END %]</td>
20
   [% FOREACH factor = PRICE_FACTORS %]
21
   <tr class="listrow[% loop.count % 2 %]" id="price_factor_id_[% factor.id %]">
22
    <td align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
21 23
    <td><a href="[% url_base %]&action=edit_price_factor&id=[% HTML.url(factor.id) %]">[% HTML.escape(factor.description) %]</a></td>
22 24
    <td>[% HTML.escape(factor.factor) %]</td>
23 25
   </tr>
......
36 38
  </form>
37 39
 </p>
38 40

  
41
 [% L.sortable_element('#price_factor_list tbody', 'url' => 'controller.pl?action=PriceFactor/reorder', 'with' => 'price_factor_id') %]
42

  
39 43
</body>
40 44
</html>

Auch abrufbar als: Unified diff