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');
var o = $.extend({
limit: 20,
delay: 50,
- }, options);
+ }, $real.data('project-picker-data'), options);
var STATES = {
PICKED: CLASSES.PICKED,
UNDEFINED: CLASSES.UNDEFINED
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;
}
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,