Revision e3bc89a0
Von Bernd Bleßmann vor 4 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 ') |
|
28 |
} |
|
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; |
|
21 | 41 |
} |
22 | 42 |
|
43 |
|
|
23 | 44 |
# |
24 | 45 |
# filters |
25 | 46 |
# |
... | ... | |
29 | 50 |
} |
30 | 51 |
|
31 | 52 |
1; |
53 |
|
|
54 |
|
|
55 |
__END__ |
|
56 |
|
|
57 |
=pod |
|
58 |
|
|
59 |
=encoding utf8 |
|
60 |
|
|
61 |
=head1 NAME |
|
62 |
|
|
63 |
SL::Controller::Warehouse - Controller module for warehouse and bin objects |
|
64 |
|
|
65 |
=head1 FUNCTIONS |
|
66 |
|
|
67 |
=over 4 |
|
68 |
|
|
69 |
=item C<action_test_page> |
|
70 |
|
|
71 |
Renders the test page. |
|
72 |
|
|
73 |
=item C<action_wh_bin_select_update_bins> |
|
74 |
|
|
75 |
This action is used by the C<SL::Presenter::Warehouse::wh_bin_select> |
|
76 |
to update the bin selection after the warehouse selection was changed. |
|
77 |
See also L<SL::Presenter::Warehouse::wh_bin_select> and |
|
78 |
L<js/kivi.Warehouse.js>). |
|
79 |
|
|
80 |
=back |
|
81 |
|
|
82 |
=head1 BUGS |
|
83 |
|
|
84 |
Nothing here yet. |
|
85 |
|
|
86 |
=head1 AUTHOR |
|
87 |
|
|
88 |
Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt> |
|
89 |
|
|
90 |
=cut |
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; |
|
73 |
|
|
74 |
|
|
75 |
__END__ |
|
76 |
|
|
77 |
=pod |
|
78 |
|
|
79 |
=encoding utf8 |
|
80 |
|
|
81 |
=head1 NAME |
|
82 |
|
|
83 |
SL::Presenter::Warehouse - Presenter module for warehouse and bin objects |
|
84 |
|
|
85 |
=head1 SYNOPSIS |
|
86 |
|
|
87 |
In template code use: |
|
88 |
|
|
89 |
[% USE P %] |
|
90 |
[% P.warehouse.wh_bin_select('wh') %] |
|
91 |
with_empty: [% P.warehouse.wh_bin_select('wh2', with_empty=1) %] |
|
92 |
|
|
93 |
=head1 FUNCTIONS |
|
94 |
|
|
95 |
=over 4 |
|
96 |
|
|
97 |
=item C<wh_bin_select $name %attributes> |
|
98 |
|
|
99 |
Returns a rendered version of select tags surrounded by a div tag for selecting |
|
100 |
a warehouse and a bin. The surrounding div tag gets the name C<$name>. |
|
101 |
|
|
102 |
The presenter takes care of updating the bin selection (via js) when the |
|
103 |
warehose selection is changed (see also |
|
104 |
L<SL::Controller::Warehouse::action_wh_bin_select_update_bins> and |
|
105 |
L<js/kivi.Warehouse.js>). |
|
106 |
|
|
107 |
All valid warehouses are presented for selection. |
|
108 |
|
|
109 |
Remaining C<%attributes> not listed here are passed to the |
|
110 |
div and select tag presenters. |
|
111 |
|
|
112 |
C<%attributes> can include: |
|
113 |
|
|
114 |
=over 2 |
|
115 |
|
|
116 |
=item * wh_name |
|
117 |
|
|
118 |
The name for the warehouse select tag. It defaults the name |
|
119 |
of the div with '_wh' added. |
|
120 |
|
|
121 |
=item * bin_name |
|
122 |
|
|
123 |
The name for the bin select tag. It defaults the name |
|
124 |
of the div with '_bin' added. |
|
125 |
|
|
126 |
=item * id |
|
127 |
|
|
128 |
The id of the div tag. It is derived from the div's name if not given. |
|
129 |
|
|
130 |
=item * wh_id |
|
131 |
|
|
132 |
The id for the warehouse select tag. It defaults the id |
|
133 |
of the div with '_wh' added. |
|
134 |
|
|
135 |
=item * bin_id |
|
136 |
|
|
137 |
The id for the bin select tag. It defaults the id |
|
138 |
of the div with '_bin' added. |
|
139 |
|
|
140 |
=item * wh_default |
|
141 |
|
|
142 |
An id of a warehouse object to be preselected. It defaults to the warehouse |
|
143 |
a given default bin belongs to. |
|
144 |
|
|
145 |
=item * bin_default |
|
146 |
|
|
147 |
An id of a bin object to be preselected. |
|
148 |
|
|
149 |
=item * with_empty |
|
150 |
|
|
151 |
Over an empty selection for the warehouse if this is truish. |
|
152 |
|
|
153 |
=back |
|
154 |
|
|
155 |
=back |
|
156 |
|
|
157 |
=head1 BUGS |
|
158 |
|
|
159 |
Nothing here yet. |
|
160 |
|
|
161 |
=head1 AUTHOR |
|
162 |
|
|
163 |
Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt> |
|
164 |
|
|
165 |
=cut |
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