Partpicker: Filtermöglichkeit nach konvertierbaren Einheiten ('convertible_unit')
[kivitendo-erp.git] / SL / Presenter / Part.pm
1 package SL::Presenter::Part;
2
3 use strict;
4
5 use SL::DB::Part;
6
7 use Exporter qw(import);
8 our @EXPORT = qw(part_picker);
9
10 sub part_picker {
11   my ($self, $name, $value, %params) = @_;
12
13   $value = SL::DB::Manager::Part->find_by(id => $value) if !ref $value;
14   my $id = delete($params{id}) || $self->name_to_id($name);
15
16   my $ret =
17     $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => 'part_autocomplete', type => 'hidden', id => $id) .
18     join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(column type unit convertible_unit)) .
19     $self->input_tag("", (ref $value && $value->can('description')) ? $value->description : '', id => "${id}_name", %params);
20
21   $self->html_tag('span', $ret, class => 'part_picker');
22 }
23
24 1;
25
26 __END__
27
28 =encoding utf-8
29
30 =head1 NAME
31
32 SL::Presenter::Part - Part lelated presenter stuff
33
34 =head1 SYNOPSIS
35
36 see L<SL::Presenter>
37
38 =head1 DESCRIPTION
39
40 see L<SL::Presenter>
41
42 =head1 FUNCTIONS
43
44 =over 4
45
46 =item C<part_picker $name, $value, %params>
47
48 All-in-one picker widget for parts. The name will be both id and name
49 of the resulting hidden C<id> input field (but the ID can be
50 overwritten with C<$params{id}>).
51
52 An additional dummy input will be generated which is used to find
53 parts. For a detailed description of it's behaviour, see section
54 C<PART PICKER SPECIFICATION>.
55
56 C<$value> can be a parts id or a C<Rose::DB:Object> instance.
57
58 If C<%params> contains C<type> only parts of this type will be used
59 for autocompletion. You may comma separate multiple types as in
60 C<part,assembly>.
61
62 If C<%params> contains C<unit> only parts with this unit will be used
63 for autocompletion. You may comma separate multiple units as in
64 C<h,min>.
65
66 If C<%params> contains C<convertible_unit> only parts with a unit
67 that's convertible to unit will be used for autocompletion.
68
69 Obsolete parts will by default not displayed for selection. However they are
70 accepted as default values and can persist during updates. As with other
71 selectors though, they are not selectable once overridden.
72
73 Currently you must include C<js/autocomplete_part.js> in your controller, the
74 presenter can not do this from the template.
75
76 =back
77
78 =head1 BUGS
79
80 =over 4
81
82 =item *
83
84 Picker icons aren't displayed with css menu, because the spritemap is not loaded.
85
86 =back
87
88 =head1 AUTHOR
89
90 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
91
92 =cut