summaryrefslogtreecommitdiff
path: root/rt/share/html/Elements/SavedSearches
blob: 96d589fc1eb9b1b58e7bf2e679dca2f5d3f506d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<& /Elements/ListActions, actions => \@results &>
<table width="100%"><tr>
% foreach my $type ('Ticket', 'Chart') {
<td width="50%">
<&|/Widgets/TitleBox, title => loc('Saved '.$titles{$type}) &>
%   foreach my $Object (@Objects) {
%     $SavedSearches = RT::SavedSearches->new($session{CurrentUser});
%     $SavedSearches->LimitToPrivacy(join('-',ref($Object),$Object->Id), $type);
%     my $title = $titles{$type};
%     if (ref $Object eq 'RT::User' && $Object->Id == $session{CurrentUser}->Id) {
%         $title = loc("My saved ".lc($title));
%     } else {
%         $title = loc("[_1]'s saved ".lc($title),$Object->Name);
%     }
%     $title = $m->interp->apply_escapes($title, 'h');
%
%     my $oid = join('-', ref($Object), $Object->Id, 'SavedSearch', '__id__');
%     my $resultpath = $paths{$type};
%     my @cols = (
%       qq{<a href="__WebPath__/$resultpath?__ResultsURL__">__Name__</a>/TITLE:$title},
%       '__Query__',
%       qq{<a href="__WebPath__/Search/Build.html?SavedSearchLoad=$oid">[Edit]</a>&nbsp;} . 
%       qq{<a href="$uri?Delete=$oid">[Delete]</a>/TITLE:},
%     );
%     my $format = join(',', map { "'$_'" } @cols);
<& /Elements/CollectionList,
    %ARGS,
    Class => 'RT::SavedSearch',
    Format => $format,
    Collection => $SavedSearches,
    PassArguments => [qw(Format Name id)],
&>
%   } #foreach $Object
</&>
</td>
% } #foreach $type
</tr></table>
<%init>
my @Objects;
my $SavedSearches = RT::SavedSearches->new($session{'CurrentUser'});
push @Objects, $SavedSearches->_PrivacyObjects;
push @Objects, RT::System->new( $session{'CurrentUser'} )
    if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
                                          Right => 'SuperUser' );

my $uri = '__WebPath__'.$m->request_path;

my @results;
if ( $Delete =~ /(.*)-SavedSearch-(\d+)/) {
  my ($privacy, $id) = ($1, $2);
  my $record = RT::SavedSearch->new($session{'CurrentUser'});
  $record->Load($privacy, $id);
  if ( $record->Id ) {
    my ($status, $msg) = $record->Delete;
    push @results, $msg;
  }
  else {
    push @results, "Saved search #$Delete not found";
  }
}

my %titles = ( 'Ticket' => 'Searches', 'Chart' => 'Charts' );
my %paths = ( 'Ticket' => 'Search/Results.html',
              'Chart' => 'Search/Chart.html',
);
</%init>
<%ARGS>
$user_attrs => undef
$Delete => undef
</%ARGS>