1 package SL::Presenter::Part;
7 use Exporter qw(import);
8 our @EXPORT = qw(part_picker);
11 my ($self, $name, $value, %params) = @_;
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);
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);
21 $::request->presenter->need_reinit_widgets($id);
23 $self->html_tag('span', $ret, class => 'part_picker');
34 SL::Presenter::Part - Part lelated presenter stuff
48 =item C<part_picker $name, $value, %params>
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}>).
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>.
58 C<$value> can be a parts id or a C<Rose::DB:Object> instance.
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>.
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
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
73 If C<%params> contains C<convertible_unit> only parts with a unit
74 that's convertible to unit will be used for autocompletion.
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.
80 Currently you must include C<js/autocomplete_part.js> in your controller, the
81 presenter can not do this from the template.
85 =head1 PART PICKER SPECIFICATION
87 The following list of design goals were applied:
93 Parts should not be perceived by the user as distinct inputs of partnumber and
94 description but as a single object
98 Easy to use without documentation for novice users
102 Fast to use with keyboard for experienced users
106 Possible to use without any keyboard interaction for mouse (or touchscreen)
111 Must not leave the current page in event of ambiguity (cf. current select_item
116 Should be useable with hand scanners or similar alternative keyboard devices
120 Should not require a feedback/check loop in the common case
124 Should not be constraint to exact matches
128 The implementation consists of the following parts which will be referenced later:
134 A hidden input (id input), used to hold the id of the selected part. The only
135 input that gets submitted
139 An input (dummy input) containing a description of the currently selected part,
140 also used by the user to search for parts
144 A jquery.autocomplete mechanism attached to the dummy field
148 A popup layer for both feedback and input of additional data in case of
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.
159 A clickable icon (popup trigger) attached to the dummy input, which triggers the popup layer.
169 Popup triggers are not displayed with css menu, because the spritemap is not loaded.
175 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>