Revision eb1089c2
Von Bernd Bleßmann vor 5 Monaten hinzugefügt
SL/Controller/Warehouse.pm | ||
---|---|---|
5 | 5 |
use parent qw(SL::Controller::Base); |
6 | 6 | |
7 | 7 |
use SL::DB::Warehouse; |
8 |
use SL::Presenter::Tag qw(select_tag); |
|
8 | 9 | |
9 | 10 |
__PACKAGE__->run_before('check_auth'); |
11 |
__PACKAGE__->run_before(sub { $::auth->assert('developer') }, |
|
12 |
only => [ qw(test_page) ]); |
|
10 | 13 | |
11 | 14 |
# |
12 | 15 |
# actions |
13 | 16 |
# |
14 | 17 | |
18 |
sub action_test_page { |
|
19 |
$_[0]->render('warehouse/test_page'); |
|
20 |
} |
|
21 | ||
15 | 22 |
sub action_reorder { |
16 | 23 |
my ($self) = @_; |
17 | 24 | |
18 | 25 |
SL::DB::Warehouse->reorder_list(@{ $::form->{warehouse_id} || [] }); |
19 | 26 | |
20 |
$self->render(\'', { type => 'json' }); |
|
27 |
$self->render(\'', { type => 'json' }); # make emacs happy again ')
|
|
21 | 28 |
} |
22 | 29 | |
30 |
sub action_wh_bin_select_update_bins { |
|
31 |
my ($self) = @_; |
|
32 | ||
33 |
my $wh_id = $::form->{wh_id}; |
|
34 |
my $bin_dom_id = $::form->{bin_dom_id} || 'bin'; |
|
35 | ||
36 |
my $bins = $wh_id ? SL::DB::Warehouse->new(id => $wh_id)->load->bins_sorted_naturally |
|
37 |
: [{id => '', description => ''}]; |
|
38 | ||
39 |
$self->js->run('kivi.Warehouse.wh_bin_select_update_bins', $bin_dom_id, [map { {key => $_->{id}, value => $_->{description}} } @$bins]) |
|
40 |
->render; |
|
41 |
} |
|
42 | ||
43 | ||
23 | 44 |
# |
24 | 45 |
# filters |
25 | 46 |
# |
SL/Presenter/ALL.pm | ||
---|---|---|
28 | 28 |
use SL::Presenter::BankAccount; |
29 | 29 |
use SL::Presenter::BankTransaction; |
30 | 30 |
use SL::Presenter::MaterialComponents; |
31 |
use SL::Presenter::Warehouse; |
|
31 | 32 | |
32 | 33 |
our %presenters = ( |
33 | 34 |
chart => 'SL::Presenter::Chart', |
... | ... | |
56 | 57 |
bank_account => 'SL::Presenter::BankAccount', |
57 | 58 |
bank_transaction => 'SL::Presenter::BankTransaction', |
58 | 59 |
M => 'SL::Presenter::MaterialComponents', |
60 |
warehouse => 'SL::Presenter::Warehouse', |
|
59 | 61 |
); |
60 | 62 | |
61 | 63 |
sub wrap { |
SL/Presenter/Warehouse.pm | ||
---|---|---|
1 |
package SL::Presenter::Warehouse; |
|
2 | ||
3 |
use strict; |
|
4 | ||
5 |
use SL::DB::Bin; |
|
6 |
use SL::DB::Warehouse; |
|
7 |
use SL::Locale::String qw(t8); |
|
8 |
use SL::Presenter::EscapedText qw(escape is_escaped); |
|
9 |
use SL::Presenter::Tag qw(name_to_id div_tag select_tag); |
|
10 | ||
11 |
use Exporter qw(import); |
|
12 |
our @EXPORT_OK = qw( |
|
13 |
wh_bin_select |
|
14 |
); |
|
15 |
our %EXPORT_TAGS = (ALL => \@EXPORT_OK); |
|
16 | ||
17 | ||
18 |
sub wh_bin_select { |
|
19 |
my ($name, %attributes) = @_; |
|
20 | ||
21 |
my $div_name = $name; |
|
22 |
my $wh_name = delete $attributes{wh_name} || "${div_name}_wh"; |
|
23 |
my $bin_name = delete $attributes{bin_name} || "${div_name}_bin"; |
|
24 |
my $div_id = delete $attributes{id} || name_to_id($name); |
|
25 |
my $wh_id = delete $attributes{wh_id} || name_to_id($wh_name) || "${div_id}_wh"; |
|
26 |
my $bin_id = delete $attributes{bin_id} || name_to_id($bin_name) || "${div_id}_bin"; |
|
27 | ||
28 |
my $bin_default = delete $attributes{bin_default}; |
|
29 |
my $wh_default = delete $attributes{wh_default} || ($bin_default && SL::DB::Bin->new(id => $bin_default)->load->warehouse_id); |
|
30 |
my $with_empty = delete $attributes{with_empty}; |
|
31 | ||
32 |
my %wh_additional_condition = $wh_default ? (id => $wh_default) : undef; |
|
33 |
my $all_warehouses = SL::DB::Manager::Warehouse->get_all_sorted( where => [or => [invalid => undef, invalid => 0, %wh_additional_condition]]); |
|
34 |
my $all_bins = $wh_default ? SL::DB::Warehouse->new(id => $wh_default)->load->bins_sorted_naturally |
|
35 |
: $with_empty ? undef |
|
36 |
: $all_warehouses->[0]->bins_sorted_naturally; |
|
37 | ||
38 |
my %div_attributes = ( |
|
39 |
name => $div_name, |
|
40 |
id => $div_id, |
|
41 |
%attributes |
|
42 |
); |
|
43 | ||
44 |
my %wh_attributes = ( |
|
45 |
name => $wh_name, |
|
46 |
id => $wh_id, |
|
47 |
default => $wh_default, |
|
48 |
with_empty => $with_empty, |
|
49 |
title_key => 'description', |
|
50 |
onchange => 'kivi.Warehouse.wh_changed(this);', |
|
51 |
'data-bin-dom-name' => $bin_name, |
|
52 |
'data-bin-dom-id' => $bin_id, |
|
53 |
%attributes |
|
54 |
); |
|
55 | ||
56 |
my %bin_attributes = ( |
|
57 |
name => $bin_name, |
|
58 |
id => $bin_id, |
|
59 |
default => $bin_default, |
|
60 |
title_key => 'description', |
|
61 |
%attributes |
|
62 |
); |
|
63 | ||
64 |
$::request->layout->add_javascripts('kivi.Warehouse.js'); |
|
65 | ||
66 |
div_tag(select_tag("${name}_wh", $all_warehouses, %wh_attributes) . |
|
67 |
select_tag($bin_name, $all_bins, %bin_attributes), |
|
68 |
%div_attributes); |
|
69 |
} |
|
70 | ||
71 | ||
72 |
1; |
js/kivi.Warehouse.js | ||
---|---|---|
1 |
namespace('kivi.Warehouse', function(ns) { |
|
2 | ||
3 |
ns.wh_changed = function(target) { |
|
4 |
const wh_id = $(target).val(); |
|
5 |
const bin_dom_name = $(target).data('bin-dom-name'); |
|
6 |
const bin_dom_id = $(target).data('bin-dom-id'); |
|
7 |
$.post("controller.pl", { action: 'Warehouse/wh_bin_select_update_bins', |
|
8 |
wh_id: wh_id, |
|
9 |
bin_dom_id: bin_dom_id }, |
|
10 |
kivi.eval_json_result); |
|
11 |
}; |
|
12 | ||
13 |
ns.wh_bin_select_update_bins = function(bin_dom_id, bins) { |
|
14 |
const $bin_select = $('#' + bin_dom_id); |
|
15 |
$bin_select.empty(); |
|
16 |
$.each(bins, function(idx, elt) { |
|
17 |
$bin_select.append($('<option/>', {value: elt.key, text: elt.value})); |
|
18 |
}); |
|
19 |
}; |
|
20 | ||
21 |
}); |
locale/de/all | ||
---|---|---|
4820 | 4820 |
'Warehouse (name)' => 'Lager (Name)', |
4821 | 4821 |
'Warehouse From' => 'Quelllager', |
4822 | 4822 |
'Warehouse Migration' => 'Lagermigration', |
4823 |
'Warehouse Test' => 'Lager-Test', |
|
4823 | 4824 |
'Warehouse To' => 'Ziellager', |
4824 | 4825 |
'Warehouse content' => 'Lagerbestand', |
4825 | 4826 |
'Warehouse deleted.' => 'Lager gelöscht.', |
4826 | 4827 |
'Warehouse management' => 'Lagerverwaltung/Bestandsveränderung', |
4827 | 4828 |
'Warehouse saved.' => 'Lager gespeichert.', |
4829 |
'Warehouse/Bin Testpage' => 'Lager/Lagerplatz-Testseite', |
|
4828 | 4830 |
'Warehouses' => 'Lager', |
4829 | 4831 |
'Warn before saving orders with duplicate parts (new controller only)' => 'Beim Speichern warnen, wenn doppelte Artikel in einem Auftrag sind', |
4830 | 4832 |
'Warn before saving orders without a delivery date' => 'Warnung ausgeben, falls Aufträge kein Lieferdatum haben.', |
locale/en/all | ||
---|---|---|
4818 | 4818 |
'Warehouse (name)' => '', |
4819 | 4819 |
'Warehouse From' => '', |
4820 | 4820 |
'Warehouse Migration' => '', |
4821 |
'Warehouse Test' => '', |
|
4821 | 4822 |
'Warehouse To' => '', |
4822 | 4823 |
'Warehouse content' => '', |
4823 | 4824 |
'Warehouse deleted.' => '', |
4824 | 4825 |
'Warehouse management' => '', |
4825 | 4826 |
'Warehouse saved.' => '', |
4827 |
'Warehouse/Bin Testpage' => '', |
|
4826 | 4828 |
'Warehouses' => '', |
4827 | 4829 |
'Warn before saving orders with duplicate parts (new controller only)' => '', |
4828 | 4830 |
'Warn before saving orders without a delivery date' => '', |
menus/user/00-erp.yaml | ||
---|---|---|
1674 | 1674 |
order: 400 |
1675 | 1675 |
params: |
1676 | 1676 |
action: Project/test_page |
1677 |
- parent: develop |
|
1678 |
id: warehouse_test |
|
1679 |
name: Warehouse Test |
|
1680 |
access: developer |
|
1681 |
order: 430 |
|
1682 |
params: |
|
1683 |
action: Warehouse/test_page |
|
1677 | 1684 |
- parent: develop |
1678 | 1685 |
id: ckeditor_test |
1679 | 1686 |
name: CKEditor5 Test |
templates/design40_webpages/warehouse/test_page.html | ||
---|---|---|
1 |
[% USE T8 %] |
|
2 |
[% USE P %] |
|
3 | ||
4 |
<h1>[% 'Warehouse/Bin Testpage' | $T8 %]</h1> |
|
5 | ||
6 |
<div class="wrapper"> |
|
7 |
[% P.warehouse.wh_bin_select('wh') %] |
|
8 | ||
9 |
with_empty: [% P.warehouse.wh_bin_select('wh2', with_empty=1) %] |
|
10 |
</div> |
templates/webpages/warehouse/test_page.html | ||
---|---|---|
1 |
[% USE T8 %] |
|
2 |
[% USE P %] |
|
3 | ||
4 |
<h1>[% 'Warehouse/Bin Testpage' | $T8 %]</h1> |
|
5 | ||
6 |
<div> |
|
7 |
[% P.warehouse.wh_bin_select('wh') %] |
|
8 | ||
9 |
with_empty: [% P.warehouse.wh_bin_select('wh2', with_empty=1) %] |
|
10 |
</div> |
Auch abrufbar als: Unified diff
Presenter für Lager/Lagerplatz-Auswahl