[Rt-commit] r2618 - in rtfm/branches/2.1-TESTING/html/RTFM/Article:
. Elements
tla at bestpractical.com
tla at bestpractical.com
Tue Apr 12 21:53:06 EDT 2005
Author: tla
Date: Tue Apr 12 21:53:05 2005
New Revision: 2618
Modified:
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches
rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
Log:
Can now save, delete, and update searches.
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches Tue Apr 12 21:53:05 2005
@@ -44,9 +44,9 @@
%#
%# END BPS TAGGED BLOCK }}}
<select name="<%$Name%>">
-% foreach my $privacy (keys %privacies) {
+% foreach my $privacy (reverse sort keys %privacies) {
% my $searches = RT::SavedSearches->new($session{'CurrentUser'});
-% $searches->Limit($privacy, 'Article');
+% $searches->LimitToPrivacy($privacy, 'Article');
% next unless $searches->Count;
% if ($privacy =~ /^RT::User/) {
<option value=""><&|/l&>My saved searches</&></option>
@@ -54,7 +54,8 @@
<option value=""><&|/l, $privacies{$privacy}->Name&>[_1]'s saved searches</&></option>
% }
% while (my $search = $searches->Next) {
-<option value="<%$privacy%>-SavedSearch-<%$search->Id%>"> -<%$search->Name||loc('Unnamed search')%></option>
+% my $optionval = "$privacy-SavedSearch-". $search->Id;
+<option value="<%$optionval%>"<% $optionval eq $Default ? 'selected' : '' %>> - <%$search->Name||loc('Unnamed search')%></option>
% }
% }
</select>
@@ -69,4 +70,5 @@
<%args>
$Name => undef
+$Default => undef
</%args>
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy Tue Apr 12 21:53:05 2005
@@ -44,9 +44,9 @@
%#
%# END BPS TAGGED BLOCK }}}
<select name="<%$Name%>">
-<option value="RT::User-<% $user->Id %>">My searches</option>
+<option value="RT::User-<% $user->Id %>" <% $Default eq 'RT::User-'.$user->Id ? 'selected' : '' %>>My searches</option>
% while (my $group = $groups->Next) {
-<option value="RT::Group-<% $group->Id %>"><% $group->Name %>'s searches</option>
+<option value="RT::Group-<% $group->Id %>" <% $Default eq 'RT::Group-'.$group->Id ? 'selected' : '' %>><% $group->Name %>'s searches</option>
% }
</select>
<%INIT>
@@ -56,4 +56,5 @@
</%INIT>
<%ARGS>
$Name => 'GroupField'
+$Default => undef
</%ARGS>
\ No newline at end of file
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches Tue Apr 12 21:53:05 2005
@@ -50,15 +50,22 @@
% if ($session{'CurrentUser'}->HasRight( Right => 'CreateSavedSearch',
% Object=> $RT::System )) {
<&|/l&>Save the current search:</&><br>
-<&|/l&>Name:</&> <input name="NewSearchName" value="<%$Description%>">
-<&|/l&>Privacy:</&> <& SelectSearchPrivacy, Name => 'SearchPrivacy' &><br>
+<&|/l&>Name:</&> <input name="NewSearchName" value="<%$Name%>">
+<&|/l&>Privacy:</&> <& SelectSearchPrivacy, Name => 'SearchPrivacy',
+ Default => $Privacy &><br>
+% if ($CurrentSearch && $CurrentSearch ne 'new') {
+<input value="<%loc('Update')%>" name="Update" type="submit">
+<input value="<%loc('Save new')%>" name="Save" type="submit">
+<input value="<%loc('Delete')%>" name="Delete" type="submit">
+% } else {
<input value="<%loc('Save')%>" name="Save" type="submit">
+% }
<hr>
% } # if HasRight 'CreateSavedSearch'
<&|/l&>Load saved search:</&><br>
-<& SelectSavedSearches, Name => 'LoadSavedSearch' &>
-<input value="<%loc('Load')%>" type="submit">
+<& SelectSavedSearches, Name => 'LoadSavedSearch', Default => $CurrentSearch &>
+<input value="<%loc('Load')%>" name="Load" type="submit">
<& /Elements/TitleBoxEnd &>
<%INIT>
@@ -71,5 +78,6 @@
<%ARGS>
$CurrentSearch => undef
-$Description => undef
+$Name => undef
+$Privacy => undef
</%ARGS>
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html Tue Apr 12 21:53:05 2005
@@ -22,21 +22,22 @@
<form action="Search.html" method="GET">
<& Elements/ShowSavedSearches, CurrentSearch => $CurrentSearch,
- Description => ($search ? $search->Name : undef) &>
+ Name => ($search ? $search->Name : undef),
+ Privacy => ($search ? $search->Privacy : undef) &>
<& Elements/ShowSearchCriteria, dates => \%dates, RefersTo => $RefersTo, customfields => $customfields, ReferredToBy => $ReferredToBy, %ARGS &>
<%init>
use RT::SavedSearch;
my @results;
my $articles = RT::FM::ArticleCollection->new( $session{'CurrentUser'} );
-
# {{{ Saved search logic
my $search;
-# The keys that are not saved and loaded with named searches. These
-# need to be treated specially.
-my @metakeys = qw/NewSearchName CurrentSearch SearchPrivacy Save Load/;
+# The keys in %ARGS that are not saved and loaded with named searches.
+# These need to be treated specially.
+my @metakeys = qw/NewSearchName CurrentSearch SearchPrivacy Save Load
+ Update Delete/;
if ($CurrentSearch =~ /^(.*-\d+)-SavedSearch-(\d+)$/) {
$search = RT::SavedSearch->new($session{'CurrentUser'});
@@ -45,66 +46,95 @@
# Have we been asked to load a search?
-if ( $ARGS{'LoadSavedSearch'} =~ /^(.*-\d+)-SavedSearch-(\d+)$/ ) {
- my $privacy = $1;
- my $search_id = $3;
-
- $search = RT::SavedSearch->new($session{'CurrentUser'});
- $search->Load($privacy, $search_id);
- if ($search->Id) {
- my $searchargs = $search->GetParameter('args');
- # Clean out ARGS and fill it in with the saved args from the
- # loaded search.
- foreach my $key (@metakeys) {
- $searchargs->{$key} = $ARGS{$key};
+if ($ARGS{'Load'}) {
+ if ($ARGS{'LoadSavedSearch'} =~ /^(.*-\d+)-SavedSearch-(\d+)$/ ) {
+ my $privacy = $1;
+ my $search_id = $2;
+
+ $search = RT::SavedSearch->new($session{'CurrentUser'});
+ my ($ret, $msg) = $search->Load($privacy, $search_id);
+ if ($ret) {
+ my $searchargs = $search->GetParameter('args');
+ # Clean out ARGS and fill it in with the saved args from the
+ # loaded search.
+ foreach my $key (@metakeys) {
+ $searchargs->{$key} = $ARGS{$key};
+ }
+ %ARGS = %{$searchargs};
+ $CurrentSearch = "$privacy-SavedSearch-$search_id";
+ } else {
+ push(@results, loc("Error: could not load saved search [_1]: [_2]",
+ $ARGS{'LoadSavedSearch'}, $msg));
}
- %ARGS = %{$searchargs};
- $CurrentSearch = "$privacy-SavedSearch-$search_id";
} else {
- push(@results, "Error: could not load saved search "
- . $ARGS{'LoadSavedSearch'});
+ push(@results, loc("Invalid [_1] argument", 'LoadSavedSearch'));
}
}
-# ...or have we been asked to save a search?
+# ...or have we been asked to save, update, or delete a search?
-if ( $ARGS{'Save'} ) {
+if ($ARGS{'Save'}) {
my %searchargs = %ARGS;
foreach my $key (@metakeys) {
delete $searchargs{$key};
}
- # Is it a new search, or have we asked for a different name than the
- # current search has? If not, just update the current search.
- if ($CurrentSearch ne 'new'
- && $search->Name eq $ARGS{'NewSearchName'}
- && $search->Privacy eq $ARGS{'SearchPrivacy'}) {
- # There is a search loaded; we just want to update it.
- $search->Save(undef, 'Article', undef, ('args' => \%searchargs));
+ $search = RT::SavedSearch->new($session{'CurrentUser'});
+ unless ($ARGS{'SearchPrivacy'} =~ /^(.*)-(\d+)$/) {
+ # This shouldn't really happen, but hey.
+ push(@results, loc("WARNING: Saving search to user-level privacy"));
+ $ARGS{'SearchPrivacy'} = 'RT::User-'.$session{'CurrentUser'}->Id;
+ }
+ my ($ret, $msg) = $search->Save(Privacy => $ARGS{'SearchPrivacy'},
+ Type => 'Article',
+ Name => $ARGS{'NewSearchName'},
+ SearchParams => {'args' => \%searchargs});
+ if ($ret) {
+ $CurrentSearch = $ARGS{'SearchPrivacy'} . "-SavedSearch-" .
+ $search->Id;
+ push(@results, loc("Created search [_1]", $search->Name));
} else {
- # This is a new search.
- $search = RT::SavedSearch->new($session{'CurrentUser'});
- if ($ARGS{'SearchPrivacy'} =~ /^(.*)-(\d+)$/) {
- $search->Save($ARGS{'SearchPrivacy'}, 'Article',
- $ARGS{'NewSearchName'}, ('args' => \%searchargs));
- $CurrentSearch = $ARGS{'SearchPrivacy'} . "-SavedSearch-" .
- $search->Id;
- push(@results, "Updated search " . $search->Name);
- } else {
- # No search privacy chosen? Warn and default to current user.
- # Really this should never happen.
- push(@results, "WARNING: Saving search to user-level privacy");
- $search->Save('RT::User-'.$session{'CurrentUser'}->Id, 'Article',
- $ARGS{'NewSearchName'}, ('args' => \%searchargs));
- $CurrentSearch = "RT::User-" . $session{'CurrentUser'}->Id .
- "-SavedSearch-" . $search->Id;
- push(@results, "Created search" . $search->Name);
+ push(@results, loc("Could not create search: [_1]", $msg));
+ }
+} elsif ($ARGS{'Update'}) {
+ my %searchargs = %ARGS;
+ foreach my $key (@metakeys) {
+ delete $searchargs{$key};
+ }
+
+ # We already have a search loaded, because CurrentSearch is set,
+ # or else we would not have gotten here.
+ my ($ret, $msg) = $search->Update(\%searchargs);
+ if ($ret) {
+ push(@results, loc("Search [_1] updated", $search->Name));
+ } else {
+ push(@results, loc("Error: search [_1] not updated: [_2]",
+ $search->Name, $msg));
+ }
+} elsif ($ARGS{'Delete'}) {
+ # Keep track of this, as we are about to delete the search.
+ my $searchname = $search->Name;
+ my ($ret, $msg) = $search->Delete;
+ if ($ret) {
+ $ARGS{'CurrentSearch'} = undef;
+ push(@results, loc("Deleted search [_1]", $searchname));
+ # Get rid of all the state.
+ foreach my $key (keys %ARGS) {
+ delete $ARGS{$key};
}
+ $CurrentSearch = 'new';
+ $search = undef;
+ $RefersTo = undef;
+ $ReferredToBy = undef;
+ } else {
+ push(@results, loc("Could not delete search [_1]: [_2]",
+ $searchname, $msg));
}
}
# }}}
+
# Don't want to search for a null class when there is no class specced
my $customfields = RT::CustomFields->new( $session{'CurrentUser'} );
$customfields->LimitToLookupType(RT::FM::Article->new($session{'CurrentUser'})->CustomFieldLookupType);
More information about the Rt-commit
mailing list