$main::lxdebug->leave_sub();
}
-sub swap_units {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form, $dir, $name_1) = @_;
-
- my $dbh = $form->dbconnect_noauto($myconfig);
-
- my $query;
-
- $query = qq|SELECT sortkey FROM units WHERE name = ?|;
- my ($sortkey_1) = selectrow_query($form, $dbh, $query, $name_1);
-
- $query =
- qq|SELECT sortkey FROM units | .
- qq|WHERE sortkey | . ($dir eq "down" ? ">" : "<") . qq| ? | .
- qq|ORDER BY sortkey | . ($dir eq "down" ? "ASC" : "DESC") . qq| LIMIT 1|;
- my ($sortkey_2) = selectrow_query($form, $dbh, $query, $sortkey_1);
-
- if (defined($sortkey_1)) {
- $query = qq|SELECT name FROM units WHERE sortkey = ${sortkey_2}|;
- my ($name_2) = selectrow_query($form, $dbh, $query);
-
- if (defined($name_2)) {
- $query = qq|UPDATE units SET sortkey = ? WHERE name = ?|;
- my $sth = $dbh->prepare($query);
-
- do_statement($form, $sth, $query, $sortkey_1, $name_2);
- do_statement($form, $sth, $query, $sortkey_2, $name_1);
- }
- }
-
- $dbh->commit();
- $dbh->disconnect();
-
- $main::lxdebug->leave_sub();
-}
-
sub taxes {
$main::lxdebug->enter_sub();
--- /dev/null
+package SL::Controller::Unit;
+
+use strict;
+
+use parent qw(SL::Controller::Base);
+
+use SL::DB::Unit;
+
+__PACKAGE__->run_before('check_auth');
+
+#
+# actions
+#
+
+sub action_reorder {
+ my ($self) = @_;
+
+ my @ids = @{ $::form->{unit_id} || [] };
+ my $result = SL::DB::Unit->new->db->do_transaction(sub {
+ foreach my $idx (0 .. scalar(@ids) - 1) {
+ SL::DB::Unit->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1);
+ }
+ });
+
+ $self->render(type => 'js', inline => '1;');
+}
+
+#
+# filters
+#
+
+sub check_auth {
+ $::auth->assert('config');
+}
+
+1;
$units = AM->retrieve_units(\%myconfig, $form);
my $ddbox = AM->unit_select_data($units, undef, 1);
- my $updownlink = build_std_url("action=swap_units");
-
$form->{"title"} = $locale->text("Add and edit units");
$form->header();
print($form->parse_html_template("am/edit_units",
{ "UNITS" => \@unit_list,
"NEW_BASE_UNIT_DDBOX" => $ddbox,
"LANGUAGES" => \@languages,
- "updownlink" => $updownlink }));
+ }));
$main::lxdebug->leave_sub();
}
$main::lxdebug->leave_sub();
}
-sub swap_units {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
-
- $main::auth->assert('config');
-
- my $dir = $form->{"dir"} eq "down" ? "down" : "up";
- AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
-
- edit_units();
-
- $main::lxdebug->leave_sub();
-}
-
sub add_tax {
$main::lxdebug->enter_sub();
'quarterly' => 'quartalsweise',
'quotation_list' => 'angebotsliste',
'release_material' => 'Materialausgabebe',
+ 'reorder item' => 'Eintrag umsortieren',
'report_generator_dispatch_to is not defined.' => 'report_generator_dispatch_to ist nicht definiert.',
'report_generator_nextsub is not defined.' => 'report_generator_nextsub ist nicht definiert.',
'request_quotation' => 'Angebotsanforderung',
-[%- USE T8 %][%- USE LxERP %]
-[% 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>
[% 'You can declare different translations for singular and plural for each unit (e.g. "day" and "days).' | $T8 %]
</p>
- <table>
+ <table id="unit_list">
+ <thead>
<tr class="listheading">
- <th width="32" align="center" valign="center"><img alt="[% 'up' | $T8 %]" src="image/up.png"><img alt="[% 'down' | $T8 %]" src="image/down.png"></th>
+ <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
<th>[% 'Delete' | $T8 %]</th>
<th>[% 'Unit' | $T8 %]</th>
<th>[% 'Base unit' | $T8 %]</th>
<th>[% language.description %]</th>
[% END %]
</tr>
+ </thead>
+ <tbody>
[% FOREACH row = UNITS %]
- <tr class="listrow[% loop.count % 2 %]">
- <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>
+ <tr class="listrow[% loop.count % 2 %]" id="unit_id_[% row.id %]">
+ <td align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
[% IF row.in_use %]
<td>
<input type="hidden" name="unchangeable_[% loop.count %]" value="1">
</td>
[% END %]
</tr>
-
- [% IF loop.last %]<input type="hidden" name="rowcount" value="[% loop.count %]">[% END %]
[% END %]
+ </tbody>
</table>
+ <input type="hidden" name="rowcount" value="[% UNITS.size %]">
+
<input type="submit" class="submit" name="action" value="[% 'Save' | $T8 %]">
</form>
+ [% L.sortable_element('#unit_list tbody', 'url' => 'controller.pl?action=Unit/reorder', 'with' => 'unit_id') %]
+
</body>
</html>