1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
58 $self->{SearchId} ||= $args->{'SavedChartSearchId'} || 'new';
60 my $SearchParams = { map { $_ => $args->{$_} } @{$self->{SearchFields}} };
62 if ( my ( $container_object, $search_id ) = _parse_saved_search(
63 $args->{'SavedSearchLoad'} || $args->{'SavedChartSearchId'} ) ) {
64 my $search = RT::Attribute->new( $session{'CurrentUser'} );
65 $search->Load($search_id);
66 # We have a $search and now; import the others
67 $self->{SearchId} = $args->{'SavedSearchLoad'} ||
68 $args->{'SavedChartSearchId'};
69 $self->{CurrentSearch}{Object} = $search;
70 if ( $args->{'SavedSearchLoad'} ) {
71 for ( @{ $self->{SearchFields} } ) {
72 $args->{$_} = $search->SubValue($_)
76 $args->{SavedChartSearchId} = $args->{'SavedSearchLoad'}
77 if $args->{'SavedSearchLoad'};
78 # saved search in /Search/Chart.html is different from /Search/Build.html
79 # the former is of type 'Chart', while the latter is of type 'Ticket'.
80 # After loading a saved search from the former after loading one from the
81 # latter, accessing /Search/Build.html will still show the old one, so we
82 # need to delete $session{CurrentSearchHash} to let it not show the old one.
83 # of course, the new one should not be shown there either because it's of
85 delete $session{'CurrentSearchHash'};
88 # look for the current one in the available saved searches
89 if ($self->{SearchId} eq 'new') {
90 my @Objects = RT::SavedSearch->new( $session{CurrentUser} )->ObjectsForLoading;
91 push @Objects, RT::System->new($session{'CurrentUser'})
92 if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
93 Right => 'SuperUser' );
94 for my $obj (@Objects) {
95 for ( $m->comp( "/Search/Elements/SearchesForObject", Object => $obj ) ) {
96 my ( $desc, $loc_desc, $search ) = @$_;
99 local $Data::Dumper::Sortkeys = 1;
100 if ( Dumper( $search->Content ) eq
101 Dumper( { %$SearchParams, SearchType => $self->{SearchType} } ) ) {
102 $self->{CurrentSearch}{Object} = $search;
103 $self->{SearchId} = $search->Id;
109 if ( $args->{SavedSearchSave} ) {
110 if ( my $search = $self->{CurrentSearch}{Object} ) {
112 $search->SetDescription( $args->{SavedSearchDescription} );
113 $search->SetSubValues(%$SearchParams);
114 push @actions, loc( '[_1] [_2] updated.', loc($self->{SearchType}), $args->{SavedSearchDescription} );
118 my $saved_search = RT::SavedSearch->new( $session{'CurrentUser'} );
119 my ( $ok, $search_msg ) = $saved_search->Save(
120 Privacy => $args->{'SavedSearchOwner'},
121 Name => $args->{'SavedSearchDescription'},
122 Type => $self->{'SearchType'},
123 SearchParams => $SearchParams
126 $self->{CurrentSearch}{Object} = $saved_search->{Attribute};
127 $self->{SearchId} = $args->{SavedChartSearchId} = 'RT::User-' .
128 $session{CurrentUser}->id . '-SavedSearch-' .
130 push @actions, loc( '[_1] [_2] saved.', loc($self->{SearchType}), $args->{SavedSearchDescription} );
133 [ loc("Can't save [_1]", loc($self->{SearchType})) . ': ' . loc($search_msg), 0 ];
138 if ( $args->{SavedSearchDelete} && $self->{CurrentSearch}{Object} ) {
139 my ($ok, $msg) = $self->{CurrentSearch}{Object}->Delete;
140 push @actions, $ok ? loc( '[_1] [_2] deleted.', loc($self->{SearchType}), $self->{CurrentSearch}{Object}->Description ) : $msg;
141 delete $self->{CurrentSearch}{Object};
142 delete $self->{SearchId};
143 delete $args->{SavedChartSearchId};
146 $self->{CurrentSearch}{Description} = $self->{CurrentSearch}{Object}->Description
147 if $self->{CurrentSearch}{Object};
159 <form method="post" action="<% $Action %>" name="SaveSearch">
160 <& /Search/Elements/EditSearches,
161 Id => $self->{SearchId} || 'new',
162 Type => $self->{SearchType},
163 CurrentSearch => $self->{CurrentSearch},
166 $self->{CurrentSearch}{Object} ?
167 ( Object => $self->{CurrentSearch}{Object},
168 Description => $self->{CurrentSearch}{Object}->Description, ) : (),
171 foreach my $field ( @{$self->{SearchFields}} ) {
172 if ( ref($ARGS{$field}) && ref($ARGS{$field}) ne 'ARRAY' ) {
173 $RT::Logger->error("Couldn't store '$field'. it's reference to ". ref($ARGS{$field}) );
176 foreach my $value ( grep defined, ref($ARGS{$field})? @{ $ARGS{$field} } : $ARGS{$field} ) {
178 <input type="hidden" class="hidden" name="<% $field %>" value="<% $value %>" />
181 <input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $self->{SearchId} || 'new' %>" />
186 $Title => loc('Saved searches')