From: Moritz Bunkus
Date: Wed, 11 May 2011 08:06:06 +0000 (+0200)
Subject: Sortieren von Einheiten auf Drag-n-Drop & AJAX mittels jQuery UI Sortable umgestellt
X-Git-Tag: release-2.6.3~25^2~65^2~3
X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=fa515ecf51805775440941fa6d2b8fa55db772f0;p=kivitendo-erp.git
Sortieren von Einheiten auf Drag-n-Drop & AJAX mittels jQuery UI Sortable umgestellt
---
diff --git a/SL/AM.pm b/SL/AM.pm
index a4db43992..445abd2e3 100644
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -2007,43 +2007,6 @@ sub save_units {
$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();
diff --git a/SL/Controller/Unit.pm b/SL/Controller/Unit.pm
new file mode 100644
index 000000000..018a7b387
--- /dev/null
+++ b/SL/Controller/Unit.pm
@@ -0,0 +1,36 @@
+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;
diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl
index 7fd49d07a..eacf5df1f 100644
--- a/bin/mozilla/am.pl
+++ b/bin/mozilla/am.pl
@@ -2687,15 +2687,13 @@ sub edit_units {
$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();
}
@@ -2933,22 +2931,6 @@ sub show_am_history {
$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();
diff --git a/image/updown.png b/image/updown.png
new file mode 100644
index 000000000..3eb6a9ce3
Binary files /dev/null and b/image/updown.png differ
diff --git a/locale/de/all b/locale/de/all
index 249d78dde..ded1a3279 100644
--- a/locale/de/all
+++ b/locale/de/all
@@ -2087,6 +2087,7 @@ $self->{texts} = {
'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',
diff --git a/templates/webpages/am/edit_units.html b/templates/webpages/am/edit_units.html
index ddc953915..4d3b3e3e0 100644
--- a/templates/webpages/am/edit_units.html
+++ b/templates/webpages/am/edit_units.html
@@ -1,5 +1,9 @@
-[%- USE T8 %][%- USE LxERP %]
-[% USE HTML %]
+[%- USE T8 %][%- USE LxERP %][% USE L %]
+[% USE HTML %]
+
+
+
+
[% IF saved_message %]
[% saved_message %]
@@ -79,9 +83,10 @@
[% 'You can declare different translations for singular and plural for each unit (e.g. "day" and "days).' | $T8 %]
-