From 8f7bb9d5dc2b961a2efc5f241dec43583f7ca21c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 13 Jan 2021 17:18:31 +0100 Subject: [PATCH] =?utf8?q?Projekt-Picker:=20Parameter=20f.=20aktiv/g=C3=BC?= =?utf8?q?ltig?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit und Filter-Daten via data an js übergeben --- SL/Presenter/Project.pm | 8 ++++++-- js/autocomplete_project.js | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/SL/Presenter/Project.pm b/SL/Presenter/Project.pm index 1be7a635a..af40c30cf 100644 --- a/SL/Presenter/Project.pm +++ b/SL/Presenter/Project.pm @@ -38,9 +38,13 @@ sub project_picker { my @classes = $params{class} ? ($params{class}) : (); push @classes, 'project_autocomplete'; + + my %data_params = map { $_ => delete $params{$_} } grep { defined $params{$_} } qw(customer_id active valid); + my $ret = - input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) . - join('', map { $params{$_} ? input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(customer_id)) . + input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id, + 'data-project-picker-data' => JSON::to_json(\%data_params), + ) . input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params); $::request->layout->add_javascripts('autocomplete_project.js'); diff --git a/js/autocomplete_project.js b/js/autocomplete_project.js index 7255ffd8a..aba682153 100644 --- a/js/autocomplete_project.js +++ b/js/autocomplete_project.js @@ -25,7 +25,7 @@ namespace('kivi', function(k){ var o = $.extend({ limit: 20, delay: 50, - }, options); + }, $real.data('project-picker-data'), options); var STATES = { PICKED: CLASSES.PICKED, UNDEFINED: CLASSES.UNDEFINED @@ -70,14 +70,29 @@ namespace('kivi', function(k){ function ajax_data(term) { var data = { 'filter.all:substr:multi::ilike': term, - 'filter.valid': 'valid', - 'filter.active': 'active', no_paginate: $('#no_paginate').prop('checked') ? 1 : 0, current: $real.val(), }; - if ($customer_id && $customer_id.val()) - data['filter.customer_id'] = $customer_id.val().split(','); + if (o.customer_id) + data['filter.customer_id'] = o.customer_id.split(','); + + if (o.active) { + if (o.active === 'active') data['filter.active'] = 'active'; + if (o.active === 'inactive') data['filter.active'] = 'inactive'; + // both => no filter + } else { + data['filter.active'] = 'active'; // default + } + + if (o.valid) { + if (o.valid === 'valid') data['filter.valid'] = 'valid'; + if (o.valid === 'invalid') data['filter.valid'] = 'invalid'; + // both => no filter + } else { + data['filter.valid'] = 'valid'; // default + } + return data; } @@ -245,7 +260,6 @@ namespace('kivi', function(k){ var pp = { real: function() { return $real }, dummy: function() { return $dummy }, - customer_id: function() { return $customer_id }, update_results: update_results, result_timer: result_timer, set_item: set_item, -- 2.20.1