Revision 386 (by ahitrov, 2013/10/17 15:02:43) Section tree control (parent.pm) optimization.
jQuery 1.9.1, jQuery 1.8.3
jQuery-UI and ajax search (/ajax/document_search.html) for autocomplete
Inline control for pickup and autocomplete (future use control)
Minor improvements and bug fixes
<% $json %>
<%once>

    use JSON::XS;

</%once>
<%args>

	$class	=> undef
	$table	=> undef
	$min	=> 2
	$term	=> undef
	$show	=> 'name'
	$search_by	=> 'name'

</%args>
<%init>

    my @result;

    if ( ($table || $class) && $term && length( Encode::decode('utf-8', $term) ) >= $min ) {
	my $search_string = "%$term%";
	my %opts;
	if ( $class ) {
		$opts{class} = $class;
	} else {
		$opts{table} = $table;
	}
	$opts{$search_by} = $search_string;
	$opts{ilike} = 1;
	my $docs = $keeper->get_documents( %opts, return_mode => 'array_ref', light => 1, limit => 30 );
	if ( ref $docs eq 'ARRAY' && @$docs ) {
		@result = map { {id => $_->id, label => Encode::decode('utf-8', $_->$show), value => Encode::decode('utf-8', $_->$show)} } @$docs;
	}
    }

    my $json = encode_json \@result;

</%init>