1 package SL::Presenter::Part;
6 use SL::DB::PartClassification;
7 use SL::Locale::String qw(t8);
9 use Exporter qw(import);
10 our @EXPORT = qw(part_picker part select_classification classification_abbreviation type_abbreviation separate_abbreviation);
15 my ($self, $part, %params) = @_;
17 $params{display} ||= 'inline';
19 croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
22 $params{no_link} ? '' : '<a href="controller.pl?action=Part/edit&part.id=' . $self->escape($part->id) . '">',
23 $self->escape($part->partnumber),
24 $params{no_link} ? '' : '</a>',
26 return $self->escaped_text($text);
30 my ($self, $name, $value, %params) = @_;
32 $value = SL::DB::Manager::Part->find_by(id => $value) if $value && !ref $value;
33 my $id = delete($params{id}) || $self->name_to_id($name);
34 my $fat_set_item = delete $params{fat_set_item};
36 my @classes = $params{class} ? ($params{class}) : ();
37 push @classes, 'part_autocomplete';
38 push @classes, 'partpicker_fat_set_item' if $fat_set_item;
41 $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) .
42 join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(part_type unit convertible_unit)) .
43 $self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
45 $::request->layout->add_javascripts('autocomplete_part.js');
46 $::request->presenter->need_reinit_widgets($id);
48 $self->html_tag('span', $ret, class => 'part_picker');
52 # shortcut for article type
54 sub type_abbreviation {
55 my ($self, $part_type) = @_;
56 $main::lxdebug->message(LXDebug->DEBUG2(),"parttype=".$part_type);
57 return $::locale->text('Assembly (typeabbreviation)') if $part_type eq 'assembly';
58 return $::locale->text('Part (typeabbreviation)') if $part_type eq 'part';
59 return $::locale->text('Assortment (typeabbreviation)') if $part_type eq 'assortment';
60 return $::locale->text('Service (typeabbreviation)');
64 # Translations for Abbreviations:
66 # $::locale->text('None (typeabbreviation)')
67 # $::locale->text('Purchase (typeabbreviation)')
68 # $::locale->text('Sales (typeabbreviation)')
69 # $::locale->text('Merchandise (typeabbreviation)')
70 # $::locale->text('Production (typeabbreviation)')
72 # and for descriptions
73 # $::locale->text('Purchase')
74 # $::locale->text('Sales')
75 # $::locale->text('Merchandise')
76 # $::locale->text('Production')
79 # shortcut for article type
81 sub classification_abbreviation {
83 SL::DB::Manager::PartClassification->cache_all();
84 my $obj = SL::DB::PartClassification->load_cached($id);
85 $obj && $obj->abbreviation ? t8($obj->abbreviation) : '';
89 # generate selection tag
91 sub select_classification {
92 my ($self, $name, %attributes) = @_;
93 $attributes{value_key} = 'id';
94 $attributes{title_key} = 'description';
95 my $collection = SL::DB::Manager::PartClassification->get_all_sorted();
96 $_->description($::locale->text($_->description)) for @{ $collection };
97 return $self->select_tag( $name, $collection, %attributes );
108 SL::Presenter::Part - Part related presenter stuff
112 # Create an html link for editing/opening a part/service/assembly
113 my $object = my $object = SL::DB::Manager::Part->get_first;
114 my $html = SL::Presenter->get->part($object, display => 'inline');
116 see also L<SL::Presenter>
126 =item C<part, $object, %params>
128 Returns a rendered version (actually an instance of
129 L<SL::Presenter::EscapedText>) of the part object C<$object>
131 C<%params> can include:
137 Either C<inline> (the default) or C<table-cell>. At the moment both
138 representations are identical and produce the part's name linked
139 to the corresponding 'edit' action.
147 =item C<classification_abbreviation $classification_id>
149 Returns the shortcut of the classification
155 =item C<select_classification $name,%params>
157 Returns a HTML Select Tag with all available Classifications
159 C<%params> can include:
165 The Id of the selected item .
173 =item C<part_picker $name, $value, %params>
175 All-in-one picker widget for parts. The name will be both id and name
176 of the resulting hidden C<id> input field (but the ID can be
177 overwritten with C<$params{id}>).
179 An additional dummy input will be generated which is used to find
180 parts. For a detailed description of its behaviour, see section
181 C<PART PICKER SPECIFICATION>.
183 C<$value> can be a parts id or a C<Rose::DB:Object> instance.
185 If C<%params> contains C<part_type> only parts of this type will be used
186 for autocompletion. You may comma separate multiple types as in
189 If C<%params> contains C<unit> only parts with this unit will be used
190 for autocompletion. You may comma separate multiple units as in
193 If C<%params> contains C<convertible_unit> only parts with a unit
194 that's convertible to unit will be used for autocompletion.
196 Obsolete parts will by default not be displayed for selection. However they are
197 accepted as default values and can persist during updates. As with other
198 selectors though, they are not selectable once overridden.
200 C<part_picker> will register it's javascript for inclusion in the next header
201 rendering. If you write a standard controller that only call C<render> once, it
202 will just work. In case the header is generated in a different render call
203 (multiple blocks, ajax, old C<bin/mozilla> style controllers) you need to
204 include C<js/autocomplete_part.js> yourself.
208 =head1 PART PICKER SPECIFICATION
210 The following list of design goals were applied:
216 Parts should not be perceived by the user as distinct inputs of partnumber and
217 description but as a single object
221 Easy to use without documentation for novice users
225 Fast to use with keyboard for experienced users
229 Possible to use without any keyboard interaction for mouse (or touchscreen)
234 Must not leave the current page in event of ambiguity (cf. current select_item
239 Should be useable with hand scanners or similar alternative keyboard devices
243 Should not require a feedback/check loop in the common case
247 Should not be constrained to exact matches
251 The implementation consists of the following parts which will be referenced later:
257 A hidden input (id input), used to hold the id of the selected part. The only
258 input that gets submitted
262 An input (dummy input) containing a description of the currently selected part,
263 also used by the user to search for parts
267 A jquery.autocomplete mechanism attached to the dummy field
271 A popup layer for both feedback and input of additional data in case of
276 An internal status of the part picker, indicating whether id input and dummy
277 input are consistent. After leaving the dummy input the part picker must
278 place itself in a consistent status.
282 A clickable icon (popup trigger) attached to the dummy input, which triggers the popup layer.
292 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
294 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>