Partpicker: Nicht kaputtgehen ohne default part.
[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 $value && !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 All-in-one picker widget for parts. The name will be both id and name of the
59 resulting hidden C<id> input field. An additional dummy input will be generated
60 which is used to find parts. For a detailed description of it's behaviour, see
61 section L</PART PICKER SPECIFICATION>.
62
63 If C<%params> contains C<type> only parts of this type will be used
64 for autocompletion. You may comma separate multiple types as in
65 C<part,assembly>.
66
67 If C<%params> contains C<unit> only parts with this unit will be used
68 for autocompletion. You may comma separate multiple units as in
69 C<h,min>.
70
71 If C<%params> contains C<convertible_unit> only parts with a unit
72 that's convertible to unit will be used for autocompletion.
73
74 Obsolete parts will by default not displayed for selection. However they are
75 accepted as default values and can persist during updates. As with other
76 selectors though, they are not selectable once overridden.
77
78 Currently you must include C<js/autocomplete_part.js> in your controller, the
79 presenter can not do this from the template.
80
81 =back
82
83 =head1 PART PICKER SPECIFICATION
84
85 The following list of design goals were applied:
86
87 =over 4
88
89 =item *
90
91 Parts should not be perceived by the user as distinct inputs of partnumber and
92 description but as a single object
93
94 =item *
95
96 Easy to use without documentation for novice users
97
98 =item *
99
100 Fast to use with keyboard for experienced users
101
102 =item *
103
104 Possible to use without any keyboard interaction for mouse (or touchscreen)
105 users
106
107 =item *
108
109 Must not leave the current page in event of ambiguity (cf. current select_item
110 mechanism)
111
112 =item *
113
114 Should be useable with hand scanners or similar alternative keyboard devices
115
116 =item *
117
118 Should not require a feedback/check loop in the common case
119
120 =item *
121
122 Should not be constraint to exact matches
123
124 =back
125
126 The implementation consists of the following parts which will be referenced later:
127
128 =over 4
129
130 =item 1
131
132 A hidden input (id input), used to hold the id of the selected part. The only
133 input that gets submitted
134
135 =item 2
136
137 An input (dummy input) containing a description of the currently selected part,
138 also used by the user to search for parts
139
140 =item 3
141
142 A jquery.autocomplete mechanism attached to the dummy field
143
144 =item 4
145
146 A popup layer for both feedback and input of additional data in case of
147 ambiguity.
148
149 =item 5
150
151 An internal status of the part picker, indicating wether id input and dummy
152 input are consistent. After leaving the dummy input the part picker must
153 place itself in a consistent status.
154
155 =item 6
156
157 A clickable icon (popup trigger) attached to the dummy input, which triggers the popup layer.
158
159 =back
160
161 =head1 BUGS
162
163 =over 4
164
165 =item *
166
167 Popup triggers are not displayed with css menu, because the spritemap is not loaded.
168
169 =back
170
171 =head1 AUTHOR
172
173 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
174
175 =cut