import rt 3.8.10
[freeside.git] / rt / html / Elements / ShowSearch
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %# 
29 %# 
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %# 
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %# 
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %# 
47 %# END BPS TAGGED BLOCK }}}
48 <&|/Widgets/TitleBox,
49     title => loc($search->Description, $ProcessedSearchArg->{'Rows'}),
50     title_href => $query_link_url.$QueryString,
51     titleright => $customize ? loc('Edit') : '',
52     titleright_href => $customize &>
53 <& $query_display_component, %$ProcessedSearchArg, ShowNavigation => 0 &>
54 </&>
55 <%init>
56 my $search;
57 my $user = $session{'CurrentUser'}->UserObj;
58 my $SearchArg;
59 my $customize;
60 my $query_display_component = '/Elements/TicketList';
61 my $query_link_url = 'Search/Results.html';
62
63 if ($SavedSearch) {
64     my ( $container_object, $search_id ) = _parse_saved_search($SavedSearch);
65     $search = $container_object->Attributes->WithId($search_id);
66     unless ( $search->Id && ref( $SearchArg = $search->Content ) eq 'HASH' ) {
67         $m->out("Saved Search $SavedSearch not found");
68         return;
69     }
70     $SearchArg->{'SearchType'} ||= 'Ticket';
71     if ( $SearchArg->{SearchType} ne 'Ticket' ) {
72
73         # XXX: dispatch to different handler here
74         $query_display_component
75             = '/Search/Elements/' . $SearchArg->{SearchType};
76         $query_link_url = "Search/$SearchArg->{SearchType}.html";
77     } else {
78         $customize = $RT::WebPath . '/Search/Build.html?'
79             . $m->comp( '/Elements/QueryString',
80             LoadSavedSearch => $SavedSearch );
81     }
82 } else {
83     ($search) = RT::System->new( $session{'CurrentUser'} ) ->Attributes->Named( 'Search - ' . $Name );
84     unless ( $search && $search->Id ) {
85         my (@custom_searches) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named('SavedSearch');
86         foreach my $custom (@custom_searches) {
87             if ($custom->Description eq $Name) { $search = $custom; last }
88         }
89         unless ($search && $search->id) {
90             $m->out("Predefined search $Name not found");
91             return;
92         }
93     }
94
95     $SearchArg = $user->Preferences( $search, $search->Content );
96     $customize = $RT::WebPath . '/Prefs/Search.html?'
97         . $m->comp( '/Elements/QueryString',
98         name => ref($search) . '-' . $search->Id );
99 }
100
101 # ProcessedSearchArg is a search with overridings, but for link we use
102 # orginal search's poperties
103 my $ProcessedSearchArg = $SearchArg;
104 $ProcessedSearchArg = { %$SearchArg, %Override } if keys %Override;
105
106 $m->comp(
107     '/Elements/Callback', %ARGS,
108     _CallbackName  => 'ModifySearch',
109     OriginalSearch => $SearchArg,
110     Search         => $ProcessedSearchArg,
111 );
112
113 foreach ( $SearchArg, $ProcessedSearchArg ) {
114     $_->{'Format'} =~ s/__WebPath__/$RT::WebPath/g;
115     $_->{'Format'} =~ s/__loc\(["']?(\w+)["']?\)__/loc("$1")/ge;
116 }
117
118 my $QueryString = '?' . $m->comp( '/Elements/QueryString', %$SearchArg );
119
120 </%init>
121 <%ARGS>
122 $Name        => undef
123 $SavedSearch => undef
124 %Override    => ()
125 </%ARGS>