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 If C<%params> contains C<type> only parts of this type will be used
61 for autocompletion. You may comma separate multiple types as in
64 If C<%params> contains C<unit> only parts with this unit will be used
65 for autocompletion. You may comma separate multiple units as in
68 If C<%params> contains C<convertible_unit> only parts with a unit
69 that's convertible to unit will be used for autocompletion.
71 Obsolete parts will by default not displayed for selection. However they are
72 accepted as default values and can persist during updates. As with other
73 selectors though, they are not selectable once overridden.
75 Currently you must include C<js/autocomplete_part.js> in your controller, the
76 presenter can not do this from the template.
80 =head1 PART PICKER SPECIFICATION
82 The following list of design goals were applied:
88 Parts should not be perceived by the user as distinct inputs of partnumber and
89 description but as a single object
93 Easy to use without documentation for novice users
97 Fast to use with keyboard for experienced users
101 Possible to use without any keyboard interaction for mouse (or touchscreen)
106 Must not leave the current page in event of ambiguity (cf. current select_item
111 Should be useable with hand scanners or similar alternative keyboard devices
115 Should not require a feedback/check loop in the common case
119 Should not be constraint to exact matches
123 The implementation consists of the following parts which will be referenced later:
129 A hidden input (id input), used to hold the id of the selected part. The only
130 input that gets submitted
134 An input (dummy input) containing a description of the currently selected part,
135 also used by the user to search for parts
139 A jquery.autocomplete mechanism attached to the dummy field
143 A popup layer for both feedback and input of additional data in case of
148 An internal status of the part picker, indicating wether id input and dummy
149 input are consistent. After leaving the dummy input the part picker must
150 place itself in a consistent status.
154 A clickable icon (popup trigger) attached to the dummy input, which triggers the popup layer.
164 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>