1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 %# <jesse@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/copyleft/gpl.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 my @Objects = RT::SavedSearches->new( $session{CurrentUser} )->_PrivacyObjects;
59 push @Objects, RT::System->new($session{'CurrentUser'})
60 if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
61 Right => 'SuperUser');
62 $self->{SearchId} ||= 'new';
63 my $SearchParams = { map { $_ => $args->{$_} } @{$self->{SearchFields}} };
65 if ( my ( $container_object, $search_id ) = _parse_saved_search( $args->{'LoadSavedSearch'} ) ) {
66 my $search = $container_object->Attributes->WithId($search_id);
67 # We have a $search and now; import the others
68 $self->{SearchId} = $args->{'LoadSavedSearch'};
69 $self->{CurrentSearch}{Object} = $search;
70 $args->{$_} = $search->SubValue($_) for @{ $self->{SearchFields} };
73 # look for the current one in the available saved searches
74 if ($self->{SearchId} eq 'new') {
75 for my $obj (@Objects) {
76 for ( $m->comp( "/Search/Elements/SearchesForObject", Object => $obj ) ) {
77 my ( $desc, $search ) = @$_;
80 local $Data::Dumper::Sortkeys = 1;
81 if ( Dumper( $search->Content ) eq
82 Dumper( { %$SearchParams, SearchType => $self->{SearchType} } ) ) {
83 $self->{CurrentSearch}{Object} = $search;
84 $self->{SearchId} = $search->Id;
90 if ( $args->{Save} ) {
91 if ( my $search = $self->{CurrentSearch}{Object} ) {
93 $search->SetDescription( $args->{Description} );
94 push @actions, loc($self->{SearchType}).loc( ' [_1] renamed to [_2].', $self->{CurrentSearch}{Description}, $args->{Description} );
98 my $saved_search = RT::SavedSearch->new( $session{'CurrentUser'} );
99 my ( $ok, $search_msg ) = $saved_search->Save(
100 Privacy => $args->{'Owner'},
101 Name => $args->{'Description'},
102 Type => $self->{'SearchType'},
103 SearchParams => $SearchParams
106 $self->{CurrentSearch}{Object} = $saved_search->{Attribute};
107 push @actions, loc($self->{SearchType}).loc( ' [_1] saved.', $args->{Description} );
110 [ loc("Can't save [_1]", loc($self->{SearchType})) . ': ' . loc($search_msg), 0 ];
115 if ( $args->{Delete} && $self->{CurrentSearch}{Object} ) {
116 my ($ok, $msg) = $self->{CurrentSearch}{Object}->Delete;
117 push @actions, $ok ? loc($self->{SearchType}).loc( ' [_1] deleted.', $self->{CurrentSearch}{Object}->Description ) : $msg;
118 delete $self->{CurrentSearch}{Object};
119 delete $self->{SearchId};
123 $self->{CurrentSearch}{Description} = $self->{CurrentSearch}{Object}->Description
124 if $self->{CurrentSearch}{Object};
136 <form method="post" action="<% $Action %>" name="SaveSearch">
137 <& /Search/Elements/EditSearches, Name => 'Owner', SearchType => $self->{SearchType}, AllowCopy => 0,
138 CurrentSearch => $self->{CurrentSearch}, SearchId => $self->{SearchId}, Title => $Title &><br />
139 % for my $field (@{$self->{SearchFields}}) {
140 <input type="hidden" class="hidden" name="<%$field%>" value="<%$ARGS{$field} || ''%>" />
146 $Title => 'Saved searches'