Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fa515ecf

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID fa515ecf51805775440941fa6d2b8fa55db772f0
  • Vorgänger b7383969
  • Nachfolger 88933549

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

Unterschiede anzeigen:

SL/AM.pm
2007 2007
  $main::lxdebug->leave_sub();
2008 2008
}
2009 2009

  
2010
sub swap_units {
2011
  $main::lxdebug->enter_sub();
2012

  
2013
  my ($self, $myconfig, $form, $dir, $name_1) = @_;
2014

  
2015
  my $dbh = $form->dbconnect_noauto($myconfig);
2016

  
2017
  my $query;
2018

  
2019
  $query = qq|SELECT sortkey FROM units WHERE name = ?|;
2020
  my ($sortkey_1) = selectrow_query($form, $dbh, $query, $name_1);
2021

  
2022
  $query =
2023
    qq|SELECT sortkey FROM units | .
2024
    qq|WHERE sortkey | . ($dir eq "down" ? ">" : "<") . qq| ? | .
2025
    qq|ORDER BY sortkey | . ($dir eq "down" ? "ASC" : "DESC") . qq| LIMIT 1|;
2026
  my ($sortkey_2) = selectrow_query($form, $dbh, $query, $sortkey_1);
2027

  
2028
  if (defined($sortkey_1)) {
2029
    $query = qq|SELECT name FROM units WHERE sortkey = ${sortkey_2}|;
2030
    my ($name_2) = selectrow_query($form, $dbh, $query);
2031

  
2032
    if (defined($name_2)) {
2033
      $query = qq|UPDATE units SET sortkey = ? WHERE name = ?|;
2034
      my $sth = $dbh->prepare($query);
2035

  
2036
      do_statement($form, $sth, $query, $sortkey_1, $name_2);
2037
      do_statement($form, $sth, $query, $sortkey_2, $name_1);
2038
    }
2039
  }
2040

  
2041
  $dbh->commit();
2042
  $dbh->disconnect();
2043

  
2044
  $main::lxdebug->leave_sub();
2045
}
2046

  
2047 2010
sub taxes {
2048 2011
  $main::lxdebug->enter_sub();
2049 2012

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

  
3
use strict;
4

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

  
7
use SL::DB::Unit;
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->{unit_id} || [] };
19
  my $result = SL::DB::Unit->new->db->do_transaction(sub {
20
    foreach my $idx (0 .. scalar(@ids) - 1) {
21
      SL::DB::Unit->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
2687 2687
  $units = AM->retrieve_units(\%myconfig, $form);
2688 2688
  my $ddbox = AM->unit_select_data($units, undef, 1);
2689 2689

  
2690
  my $updownlink = build_std_url("action=swap_units");
2691

  
2692 2690
  $form->{"title"} = $locale->text("Add and edit units");
2693 2691
  $form->header();
2694 2692
  print($form->parse_html_template("am/edit_units",
2695 2693
                                   { "UNITS"               => \@unit_list,
2696 2694
                                     "NEW_BASE_UNIT_DDBOX" => $ddbox,
2697 2695
                                     "LANGUAGES"           => \@languages,
2698
                                     "updownlink"          => $updownlink }));
2696
                                   }));
2699 2697

  
2700 2698
  $main::lxdebug->leave_sub();
2701 2699
}
......
2933 2931
  $main::lxdebug->leave_sub();
2934 2932
}
2935 2933

  
2936
sub swap_units {
2937
  $main::lxdebug->enter_sub();
2938

  
2939
  my $form     = $main::form;
2940
  my %myconfig = %main::myconfig;
2941

  
2942
  $main::auth->assert('config');
2943

  
2944
  my $dir = $form->{"dir"} eq "down" ? "down" : "up";
2945
  AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
2946

  
2947
  edit_units();
2948

  
2949
  $main::lxdebug->leave_sub();
2950
}
2951

  
2952 2934
sub add_tax {
2953 2935
  $main::lxdebug->enter_sub();
2954 2936

  
locale/de/all
2087 2087
  'quarterly'                   => 'quartalsweise',
2088 2088
  'quotation_list'              => 'angebotsliste',
2089 2089
  'release_material'            => 'Materialausgabebe',
2090
  'reorder item'                => 'Eintrag umsortieren',
2090 2091
  'report_generator_dispatch_to is not defined.' => 'report_generator_dispatch_to ist nicht definiert.',
2091 2092
  'report_generator_nextsub is not defined.' => 'report_generator_nextsub ist nicht definiert.',
2092 2093
  'request_quotation'           => 'Angebotsanforderung',
templates/webpages/am/edit_units.html
1
[%- USE T8 %][%- USE LxERP %]
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 %]
5 9
  <p>[% saved_message %]</p>
......
79 83
  [% 'You can declare different translations for singular and plural for each unit (e.g. &quot;day&quot; and &quot;days).' | $T8 %]
80 84
 </p>
81 85

  
82
 <table>
86
 <table id="unit_list">
87
  <thead>
83 88
  <tr class="listheading">
84
   <th width="32" align="center" valign="center"><img alt="[% 'up' | $T8 %]" src="image/up.png"><img alt="[% 'down' | $T8 %]" src="image/down.png"></th>
89
   <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
85 90
   <th>[% 'Delete' | $T8 %]</th>
86 91
   <th>[% 'Unit' | $T8 %]</th>
87 92
   <th>[% 'Base unit' | $T8 %]</th>
......
90 95
    <th>[% language.description %]</th>
91 96
   [% END %]
92 97
  </tr>
98
  </thead>
93 99

  
100
  <tbody>
94 101
  [% FOREACH row = UNITS %]
95
   <tr class="listrow[% loop.count % 2 %]">
96
    <td width="32" align="center" valign="center">[% IF loop.first %]<img src="image/transparent16x16.gif">[% ELSE %]<a href="[% updownlink %]&dir=up&name=[% HTML.url(row.name) %]"><img alt="[% 'up' | $T8 %]" src="image/up.png" border="0"></a>[% END %][% IF loop.last %]<img src="image/transparent16x16.gif">[% ELSE %]<a href="[% updownlink %]&dir=down&name=[% HTML.url(row.name) %]"><img alt="[% 'down' | $T8 %]" src="image/down.png" border="0"></a>[% END %]</td>
102
   <tr class="listrow[% loop.count % 2 %]" id="unit_id_[% row.id %]">
103
    <td align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
97 104
    [% IF row.in_use %]
98 105
     <td>
99 106
      <input type="hidden" name="unchangeable_[% loop.count %]" value="1">
......
128 135
     </td>
129 136
    [% END %]
130 137
   </tr>
131

  
132
   [% IF loop.last %]<input type="hidden" name="rowcount" value="[% loop.count %]">[% END %]
133 138
  [% END %]
139
  </tbody>
134 140
 </table>
135 141

  
142
 <input type="hidden" name="rowcount" value="[% UNITS.size %]">
143

  
136 144
 <input type="submit" class="submit" name="action" value="[% 'Save' | $T8 %]">
137 145

  
138 146
 </form>
139 147

  
148
 [% L.sortable_element('#unit_list tbody', 'url' => 'controller.pl?action=Unit/reorder', 'with' => 'unit_id') %]
149

  
140 150
</body>
141 151
</html>

Auch abrufbar als: Unified diff