use SL::Controller::Helper::Paginated;
use SL::Controller::Helper::Filtered;
use SL::Locale::String qw(t8);
+use SL::JSON;
use Rose::Object::MakeMethods::Generic (
'scalar --get_set_init' => [ qw(parts) ],
__PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') });
__PACKAGE__->make_filtered(
- ONLY => [ qw(part_picker_search part_picker_result) ],
+ ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
LAUNDER_TO => 'filter',
);
__PACKAGE__->make_paginated(
- ONLY => [ qw(part_picker_search part_picker_result) ],
+ ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
);
__PACKAGE__->make_sorted(
- ONLY => [ qw(part_picker_search part_picker_result) ],
+ ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
DEFAULT_BY => 'partnumber',
DEFAULT_DIR => 1,
sub action_ajax_autocomplete {
my ($self, %params) = @_;
- my $limit = $::form->{limit} || 20;
- my $type = $::form->{type} || {};
- my $query = { ilike => "%$::form->{term}%" };
- my @filter;
- push @filter, SL::DB::Manager::Part->type_filter($type);
- push @filter, ($::form->{column})
- ? ($::form->{column} => $query)
- : (or => [ partnumber => $query, description => $query ]);
-
- $self->{parts} = SL::DB::Manager::Part->get_all(query => [ @filter ], limit => $limit);
- $self->{value} = $::form->{column} || 'description';
+ my $value = $::form->{column} || 'description';
# if someone types something, and hits enter, assume he entered the full name.
# if something matches, treat that as sole match
if ($::form->{prefer_exact}) {
- for my $part (@{ $self->{parts} }) {
- if ( lc $part->description eq lc $::form->{term}
- || lc $part->partnumber eq lc $::form->{term}) {
- $self->{parts} = [ $part ];
- last;
- }
- }
+ # TODO!
}
- $self->render('part/ajax_autocomplete', { layout => 0, type => 'json' });
+ my @hashes = map {
+ +{
+ value => $_->$value,
+ label => $_->long_description,
+ id => $_->id,
+ partnumber => $_->partnumber,
+ description => $_->description,
+ type => $_->type,
+ }
+ } @{ $self->parts };
+
+ $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
}
sub action_test_page {
var last_dummy = $dummy.val();
var open_dialog = function(){
open_jqm_window({
- url: 'controller.pl',
- data: {
- action: 'Part/part_picker_search',
+ url: 'controller.pl?action=Part/part_picker_search',
+ data: $.extend({
real_id: real_id,
- 'filter.all:substr::ilike': function(){ return $dummy.val() },
- 'filter.type': function(){ return $type.val() },
- 'column': function(){ return $column.val() },
- },
+ }, ajax_data($dummy.val())),
id: 'part_selection',
});
return true;
function ajax_data(term) {
return {
- term: term,
- type: function() { return $type.val() },
+ 'filter.all:substr::ilike': term,
+ 'filter.type': function() { return $type.val() },
+ 'filter.obsolete': 0,
column: function() { return $column.val()===undefined ? '' : $column.val() },
current: function() { return $real.val() },
- obsolete: 0,
}
}
function update_results () {
$.ajax({
url: 'controller.pl?action=Part/part_picker_result',
- data: {
- 'filter.all:substr::ilike': function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val },
- 'filter.type': $type.val(),
- 'column': $column.val(),
- 'real_id': $real.val,
- },
+ data: $.extend({
+ 'real_id': $real.val(),
+ }, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })),
success: function(data){ $('#part_picker_result').html(data) }
});
};
+++ /dev/null
-[%- USE HTML %][% USE JSON %][
-[%- FOREACH part = SELF.parts %]
-[%- ajax_autocomplete__label = part.partnumber _ " " _ part.description %]
- {
- "value": [% part.${SELF.value}.json %],
- "label": [% ajax_autocomplete__label.json %],
- "id": [% part.id.json %],
- "partnumber": [% part.partnumber.json %],
- "description": [% part.description.json %],
- "type": [% part.type.json %]
- }[% ',' UNLESS loop.last %]
-[%- END %]
-]