From fa515ecf51805775440941fa6d2b8fa55db772f0 Mon Sep 17 00:00:00 2001
From: Moritz Bunkus
Date: Wed, 11 May 2011 10:06:06 +0200
Subject: [PATCH] Sortieren von Einheiten auf Drag-n-Drop & AJAX mittels jQuery
UI Sortable umgestellt
---
SL/AM.pm | 37 --------------------------
SL/Controller/Unit.pm | 36 +++++++++++++++++++++++++
bin/mozilla/am.pl | 20 +-------------
image/updown.png | Bin 0 -> 540 bytes
locale/de/all | 1 +
templates/webpages/am/edit_units.html | 26 ++++++++++++------
6 files changed, 56 insertions(+), 64 deletions(-)
create mode 100644 SL/Controller/Unit.pm
create mode 100644 image/updown.png
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 0000000000000000000000000000000000000000..3eb6a9ce3f05fef318648a3e317ac3f438dd0f2e
GIT binary patch
literal 540
zcmV+%0^|LOP)*Y>8!Nbe_rV5w`+@g{%~_O!X=kJZzh!1^&`{Vi{T2qWCt>OBAT_pH!7
z{L)-W*T6!`=O{p+$L$Q?+-Ze1wt~c<##X@EzGU`WD?l(+105j4qVoA;18ch%XvC`fDYmjCIGA5tpmuA
zSBTfBR=ZmtAMIgrYOMkA86Z~(!ffi8SYTSytjSzj)_6LVIeQHH$BDFJ3ke_sdx{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 %]
-