Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 426a5bf3

Von Sven Schöling vor fast 8 Jahren hinzugefügt

  • ID 426a5bf3c8b6a5cd2509699ebace0d24e614f2b7
  • Vorgänger a45a5332
  • Nachfolger 8f19c47c

kivi.Part.js: Datenübergabe Picker<->Presenter auf data umgestellt

Ist in Summe kompakter und einfacher erweiterbar.

Unterschiede anzeigen:

SL/Presenter/Part.pm
30 30
  my ($self, $name, $value, %params) = @_;
31 31

  
32 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};
33
  my $id = $params{id} || $self->name_to_id($name);
35 34

  
36 35
  my @classes = $params{class} ? ($params{class}) : ();
37 36
  push @classes, 'part_autocomplete';
38
  push @classes, 'partpicker_fat_set_item' if $fat_set_item;
39 37

  
40 38
  my $ret =
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 classification_id unit convertible_unit)) .
39
    $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id,
40
      'data-part-picker-data' => JSON::to_json(\%params),
41
    ) .
43 42
    $self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
44 43

  
45 44
  $::request->layout->add_javascripts('kivi.Part.js');
js/kivi.Part.js
283 283
    this.o = $.extend({
284 284
      limit: 20,
285 285
      delay: 50,
286
      fat_set_item: $real.hasClass(this.CLASSES.FAT_SET_ITEM),
287 286
      action: {
288 287
        on_enter_match_none: function(){ },
289 288
        on_enter_match_one:  function(){ $('#update_button').click(); },
290 289
        on_enter_match_many: function(){ self.open_dialog(); }
291 290
      }
292
    }, options);
291
    }, $real.data('part-picker-data'), options);
293 292
    this.$real              = $real;
294 293
    this.real_id            = $real.attr('id');
295 294
    this.last_real          = $real.val();
296
    this.$dummy             = $('#' + this.real_id + '_name');
297
    this.$part_type         = $('#' + this.real_id + '_part_type');
298
    this.$classification_id = $('#' + this.real_id + '_classification_id');
299
    this.$unit              = $('#' + this.real_id + '_unit');
300
    this.$convertible_unit  = $('#' + this.real_id + '_convertible_unit');
295
    this.$dummy             = $($real.siblings()[0]);
301 296
    this.autocomplete_open  = false;
302 297
    this.state              = this.STATES.PICKED;
303 298
    this.last_dummy         = this.$dummy.val();
......
310 305
    CLASSES: {
311 306
      PICKED:       'partpicker-picked',
312 307
      UNDEFINED:    'partpicker-undefined',
313
      FAT_SET_ITEM: 'partpicker_fat_set_item',
314 308
    },
315 309
    ajax_data: function(term) {
316 310
      var data = {
317 311
        'filter.all:substr:multi::ilike': term,
318 312
        'filter.obsolete': 0,
319
        'filter.unit_obj.convertible_to': this.$convertible_unit && this.$convertible_unit.val() ? this.$convertible_unit.val() : '',
320 313
        current:  this.$real.val(),
321 314
      };
322 315

  
323
      if (this.$part_type && this.$part_type.val())
324
        data['filter.part_type'] = this.$part_type.val().split(',');
316
      if (this.o.part_type)
317
        data['filter.part_type'] = this.o.part_type.split(',');
325 318

  
326
      if (this.$classification_id && this.$classification_id.val())
327
        data['filter.classification_id'] = this.$classification_id.val().split(',');
319
      if (this.o.classification_id)
320
        data['filter.classification_id'] = this.o.classification_id.split(',');
328 321

  
329
      if (this.$unit && this.$unit.val())
330
        data['filter.unit'] = this.$unit.val().split(',');
322
      if (this.o.unit)
323
        data['filter.unit'] = this.o.unit.split(',');
324

  
325
      if (this.o.convertible_unit)
326
        data['filter.unit_obj.convertible_to'] = this.o.convertible_unit;
331 327

  
332 328
      return data;
333 329
    },

Auch abrufbar als: Unified diff