RT mobile UI, #11630
[freeside.git] / rt / share / html / m / tickets / search
1 <%args>
2 $page => 1
3 $order_by => 'id'
4 $order => 'desc'
5 $name => undef
6 </%args>
7 <%init>
8 use RT::Search::Googleish;
9 my $query = $ARGS{'query'};
10 if ($ARGS{'q'}) {
11     my $tickets = RT::Tickets->new( $session{'CurrentUser'} );
12     my %args = (
13         Argument   => $ARGS{q},
14         TicketsObj => $tickets,
15     );
16     my $search = RT::Search::Googleish->new(%args);
17     $query = $search->QueryToSQL();
18
19 }
20
21 elsif ($ARGS{'name'}) {
22 my $search_arg;
23
24 my $search;
25
26     if ($name)  {
27         ($search) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named( 'Search - ' . $name );
28         unless ( $search && $search->Id ) {
29             my (@custom_searches) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named('SavedSearch');
30             foreach my $custom (@custom_searches) {
31                 if ( $custom->Description eq $name ) { $search = $custom; last }
32             }
33             unless ( $search && $search->id ) {
34                 $m->out("Predefined search $name not found");
35                 return;
36             }
37         }
38
39         $search_arg = $session{'CurrentUser'}->UserObj->Preferences( $search, $search->Content );
40     }
41
42     foreach ($search_arg) {
43         if ( $_->{'Query'} =~ /__Bookmarks__/ ) {
44             $_->{'Rows'} = 999;
45
46             # DEPRECATED: will be here for a while up to 3.10/4.0
47             my $bookmarks = $session{'CurrentUser'}->UserObj->FirstAttribute('Bookmarks');
48             $bookmarks = $bookmarks->Content if $bookmarks;
49             $bookmarks ||= {};
50             my $query = join( " OR ", map " id = '$_' ", grep $bookmarks->{$_}, keys %$bookmarks ) || 'id=0';
51             $_->{'Query'} =~ s/__Bookmarks__/( $query )/g;
52         }
53     }
54
55     $query    = $search_arg->{Query};
56     $order_by = $search_arg->{OrderBy};
57     $order    = $search_arg->{Order};
58
59 }
60
61
62 $m->comp('../_elements/ticket_list', query => $query, page => $page, order_by => $order_by, order => $order);
63 $m->abort();
64 </%init>