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