[Rt-commit] rt branch, 3.9-maybe_redirect, created. rt-3.9.7-922-gb4044e8

Ruslan Zakirov ruz at bestpractical.com
Fri Dec 17 16:49:20 EST 2010


The branch, 3.9-maybe_redirect has been created
        at  b4044e8b15e8ea8830bbf7240c4b005c836e82b7 (commit)

- Log -----------------------------------------------------------------
commit b4044e8b15e8ea8830bbf7240c4b005c836e82b7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Dec 18 00:46:25 2010 +0300

    add MaybeRedirectForResults sub instead of component
    
    * no ARGSRef, with one Anchor argument
    * not only id argument, but any using Arguments
    * Force argument - redirect even when there is no results

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index b7aa9f4..38d6314 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1090,7 +1090,38 @@ sub Abort {
     }
 }
 
+sub MaybeRedirectForResults {
+    my %args = (
+        Path      => undef,
+        Arguments => {},
+        Anchor    => undef,
+        Actions   => undef,
+        Force     => 0,
+        @_
+    );
+    my $has_actions = $args{'Actions'} && grep( defined, @{ $args{'Actions'} } );
+    return unless $has_actions || $args{'Force'};
+
+    my %arguments = %{ $args{'Arguments'} };
+
+    if ( $has_actions ) {
+        my $key = Digest::MD5::md5_hex( rand(1024) );
+        push @{ $session{"Actions"}{ $key } ||= [] }, @{ $args{'Actions'} };
+        $session{'i'}++;
+        $arguments{'results'} = $key;
+    }
+
+    $args{'Path'} =~ s!^/+!!;
+    my $url = RT->Config->Get('WebURL') . $args{Path};
 
+    if ( keys %arguments ) {
+        $url .= '?'. $m->comp( '/Elements/QueryString', %arguments );
+    }
+    if ( $args{'Anchor'} ) {
+        $url .= "#". $args{'Anchor'};
+    }
+    return RT::Interface::Web::Redirect($url);
+}
 
 =head2 CreateTicket ARGS
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list