Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision df33875f

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID df33875fc30c508b60af9421d0061e66cdc0d55a
  • Vorgänger 880a2e9f
  • Nachfolger 35d63a9f

Partpicker: Filtermöglichkeit nach konvertierbaren Einheiten ('convertible_unit')

Unterschiede anzeigen:

SL/Controller/Part.pm
92 92
}
93 93

  
94 94
sub init_parts {
95
  $_[0]->get_models;
95
  $_[0]->get_models(with_objects => [ qw(unit_obj) ]);
96 96
}
97 97

  
98 98
1;
SL/DB/Manager/Unit.pm
6 6
use base qw(SL::DB::Helper::Manager);
7 7

  
8 8
use SL::DB::Helper::Sorted;
9
use SL::DB::Helper::Filtered;
9 10

  
10 11
sub object_class { 'SL::DB::Unit' }
11 12

  
12 13
__PACKAGE__->make_manager_methods;
14
__PACKAGE__->add_filter_specs(
15
  convertible_to => sub {
16
    my ($key, $value, $prefix) = @_;
17
    return __PACKAGE__->convertible_to_filter($key, $value, $prefix);
18
  },
19
);
13 20

  
14 21
sub _sort_spec {
15 22
  return ( default => [ 'sortkey', 1 ],
......
18 25
                      });
19 26
}
20 27

  
28
sub convertible_to_filter {
29
  my ($class, $key, $unit_name, $prefix) = @_;
30

  
31
  return () unless $unit_name;
32

  
33
  $prefix //= '';
34

  
35
  my $unit = $class->find_by(name => $unit_name);
36
  if (!$unit) {
37
    $::lxdebug->warn("Unit manager: No unit with name $unit_name");
38
    return ();
39
  }
40

  
41
  return ("${prefix}name" => [ map { $_->name } @{ $unit->convertible_units } ]);
42
}
43

  
21 44
1;
SL/Presenter/Part.pm
15 15

  
16 16
  my $ret =
17 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)) .
18
    join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(column type unit convertible_unit)) .
19 19
    $self->input_tag("", (ref $value && $value->can('description')) ? $value->description : '', id => "${id}_name", %params);
20 20

  
21 21
  $self->html_tag('span', $ret, class => 'part_picker');
......
63 63
for autocompletion. You may comma separate multiple units as in
64 64
C<h,min>.
65 65

  
66
If C<%params> contains C<convertible_unit> only parts with a unit
67
that's convertible to unit will be used for autocompletion.
68

  
66 69
Obsolete parts will by default not displayed for selection. However they are
67 70
accepted as default values and can persist during updates. As with other
68 71
selectors though, they are not selectable once overridden.
js/autocomplete_part.js
13 13
    var $dummy  = $('#' + real_id + '_name');
14 14
    var $type   = $('#' + real_id + '_type');
15 15
    var $unit   = $('#' + real_id + '_unit');
16
    var $convertible_unit = $('#' + real_id + '_convertible_unit');
16 17
    var $column = $('#' + real_id + '_column');
17 18
    var state   = STATES.PICKED;
18 19
    var last_real = $real.val();
......
32 33
      var data = {
33 34
        'filter.all:substr::ilike': term,
34 35
        'filter.obsolete': 0,
35
        column:   $column.val()===undefined ? '' : $column.val(),
36
        'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '',
37
        column:   $column && $column.val() ? $column.val() : '',
36 38
        current:  $real.val(),
37 39
      };
38 40

  
......
154 156
      dummy:          function() { return $dummy },
155 157
      type:           function() { return $type },
156 158
      unit:           function() { return $unit },
159
      convertible_unit: function() { return $convertible_unit },
157 160
      column:         function() { return $column },
158 161
      update_results: update_results,
159 162
      set_item:       set_item,

Auch abrufbar als: Unified diff