44d701e67c08a2f193bd37d1d29c9a6cab6b4e4d
[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     $self->input_tag("", delete $params{type}, id => "${id}_type", type => 'hidden') .
19     $self->input_tag("", (ref $value && $value->can('description')) ? $value->description : '', id => "${id}_name", %params) .
20     $self->input_tag("", delete $params{column}, id => "${id}_column", type => 'hidden');
21
22   $self->html_tag('span', $ret, class => 'part_picker');
23 }
24
25 1;
26
27 __END__
28
29 =encoding utf-8
30
31 =head1 NAME
32
33 SL::Presenter::Part - Part lelated presenter stuff
34
35 =head1 SYNOPSIS
36
37 see L<SL::Presenter>
38
39 =head1 DESCRIPTION
40
41 see L<SL::Presenter>
42
43 =head1 FUNCTIONS
44
45 =over 4
46
47 =item C<part_picker $name, $value, %params>
48
49 All-in-one picker widget for parts. The name will be both id and name
50 of the resulting hidden C<id> input field (but the ID can be
51 overwritten with C<$params{id}>).
52
53 An additional dummy input will be generated which is used to find
54 parts. For a detailed description of it's behaviour, see section
55 C<PART PICKER SPECIFICATION>.
56
57 C<$value> can be a parts id or a C<Rose::DB:Object> instance.
58
59 If C<%params> contains C<type> only parts of this type will be used
60 for autocompletion. You may comma separate multiple types as in
61 C<part,assembly>.
62
63 Obsolete parts will by default not displayed for selection. However they are
64 accepted as default values and can persist during updates. As with other
65 selectors though, they are not selectable once overridden.
66
67 Currently you must include C<js/autocomplete_part.js> in your controller, the
68 presenter can not do this from the template.
69
70 =back
71
72 =head1 BUGS
73
74 =over 4
75
76 =item *
77
78 Picker icons aren't displayed with css menu, because the spritemap is not loaded.
79
80 =back
81
82 =head1 AUTHOR
83
84 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
85
86 =cut