1 |
480 |
ahitrov |
<% $json %> |
2 |
|
|
<%once> |
3 |
|
|
|
4 |
|
|
use JSON::XS; |
5 |
|
|
|
6 |
|
|
</%once> |
7 |
|
|
<%args> |
8 |
|
|
|
9 |
|
|
$id => undef |
10 |
|
|
$class => undef |
11 |
|
|
$term => undef |
12 |
|
|
|
13 |
|
|
</%args> |
14 |
|
|
<%init> |
15 |
|
|
|
16 |
|
|
warn Dumper \%ARGS if $DEBUG; |
17 |
|
|
return if length( $ARGS{term} ) < 3; |
18 |
|
|
|
19 |
|
|
my @links = $keeper->get_links( |
20 |
|
|
class => 'tag::Cloud', |
21 |
|
|
dest_class => $class, |
22 |
|
|
dest_id => $id, |
23 |
|
|
); |
24 |
|
|
my %ex = map { $_->source_id => 1 } @links; |
25 |
|
|
my @ex = keys %ex; |
26 |
|
|
|
27 |
|
|
my @tags = $keeper->get_documents( |
28 |
|
|
@ex ? ( excludes => \@ex ) : (), |
29 |
|
|
class => 'tag::Tag', |
30 |
|
|
status => 1, |
31 |
|
|
name => '%'.$ARGS{term}.'%', |
32 |
|
|
ilike => 1, |
33 |
|
|
order_by => 'name', |
34 |
|
|
); |
35 |
|
|
return unless @tags; |
36 |
|
|
|
37 |
|
|
my @result = map { {id => $_->id, label => Encode::decode('utf-8', $_->name), value => Encode::decode('utf-8', $_->name)} } @tags; |
38 |
|
|
|
39 |
|
|
my $json = encode_json \@result; |
40 |
|
|
|
41 |
|
|
</%init> |