From 426a5bf3c8b6a5cd2509699ebace0d24e614f2b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 8 Feb 2017 16:04:42 +0100 Subject: [PATCH] =?utf8?q?kivi.Part.js:=20Daten=C3=BCbergabe=20Picker<->Pr?= =?utf8?q?esenter=20auf=20data=20umgestellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Ist in Summe kompakter und einfacher erweiterbar. --- SL/Presenter/Part.pm | 9 ++++----- js/kivi.Part.js | 26 +++++++++++--------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/SL/Presenter/Part.pm b/SL/Presenter/Part.pm index f84d706d5..e0f670c62 100644 --- a/SL/Presenter/Part.pm +++ b/SL/Presenter/Part.pm @@ -30,16 +30,15 @@ sub part_picker { my ($self, $name, $value, %params) = @_; $value = SL::DB::Manager::Part->find_by(id => $value) if $value && !ref $value; - my $id = delete($params{id}) || $self->name_to_id($name); - my $fat_set_item = delete $params{fat_set_item}; + my $id = $params{id} || $self->name_to_id($name); my @classes = $params{class} ? ($params{class}) : (); push @classes, 'part_autocomplete'; - push @classes, 'partpicker_fat_set_item' if $fat_set_item; my $ret = - $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) . - join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(part_type classification_id unit convertible_unit)) . + $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id, + 'data-part-picker-data' => JSON::to_json(\%params), + ) . $self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params); $::request->layout->add_javascripts('kivi.Part.js'); diff --git a/js/kivi.Part.js b/js/kivi.Part.js index cb55949c5..d7bbd2ffd 100644 --- a/js/kivi.Part.js +++ b/js/kivi.Part.js @@ -283,21 +283,16 @@ namespace('kivi.Part', function(ns) { this.o = $.extend({ limit: 20, delay: 50, - fat_set_item: $real.hasClass(this.CLASSES.FAT_SET_ITEM), action: { on_enter_match_none: function(){ }, on_enter_match_one: function(){ $('#update_button').click(); }, on_enter_match_many: function(){ self.open_dialog(); } } - }, options); + }, $real.data('part-picker-data'), options); this.$real = $real; this.real_id = $real.attr('id'); this.last_real = $real.val(); - this.$dummy = $('#' + this.real_id + '_name'); - this.$part_type = $('#' + this.real_id + '_part_type'); - this.$classification_id = $('#' + this.real_id + '_classification_id'); - this.$unit = $('#' + this.real_id + '_unit'); - this.$convertible_unit = $('#' + this.real_id + '_convertible_unit'); + this.$dummy = $($real.siblings()[0]); this.autocomplete_open = false; this.state = this.STATES.PICKED; this.last_dummy = this.$dummy.val(); @@ -310,24 +305,25 @@ namespace('kivi.Part', function(ns) { CLASSES: { PICKED: 'partpicker-picked', UNDEFINED: 'partpicker-undefined', - FAT_SET_ITEM: 'partpicker_fat_set_item', }, ajax_data: function(term) { var data = { 'filter.all:substr:multi::ilike': term, 'filter.obsolete': 0, - 'filter.unit_obj.convertible_to': this.$convertible_unit && this.$convertible_unit.val() ? this.$convertible_unit.val() : '', current: this.$real.val(), }; - if (this.$part_type && this.$part_type.val()) - data['filter.part_type'] = this.$part_type.val().split(','); + if (this.o.part_type) + data['filter.part_type'] = this.o.part_type.split(','); - if (this.$classification_id && this.$classification_id.val()) - data['filter.classification_id'] = this.$classification_id.val().split(','); + if (this.o.classification_id) + data['filter.classification_id'] = this.o.classification_id.split(','); - if (this.$unit && this.$unit.val()) - data['filter.unit'] = this.$unit.val().split(','); + if (this.o.unit) + data['filter.unit'] = this.o.unit.split(','); + + if (this.o.convertible_unit) + data['filter.unit_obj.convertible_to'] = this.o.convertible_unit; return data; }, -- 2.20.1