Fix empty file when exporting from simple search
authorEmmanuel Lacour <elacour@easter-eggs.com>
Mon, 12 Oct 2015 15:45:15 +0000 (17:45 +0200)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Mon, 12 Oct 2015 15:45:15 +0000 (17:45 +0200)
To fix this big part of upstream Elements/Tabs code has been taken to
manage the different way we can get query string/args.

html/Callbacks/Results-ODS/Elements/Tabs/Privileged

index 793d2d1..f734452 100644 (file)
@@ -2,8 +2,8 @@
 %# 
 %# COPYRIGHT:
 %# 
-%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
-%#                                          <jesse@bestpractical.com>
+%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
+%#                                          <sales@bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
 %# 
@@ -56,26 +56,81 @@ my $query_string = sub {
 };
 
 
-if (            
-     (           
-            $request_path =~ m{^/Search/}
-         && $request_path !~ m{^/Search/Simple\.html}
-     )       
-     || (   $request_path =~ m{^/Search/Simple\.html}
-         && $DECODED_ARGS->{'q'} )
-   ) {
-    
+if (
+    (
+           $request_path =~ m{^/(?:Ticket|Search)/}
+        && $request_path !~ m{^/Search/Simple\.html}
+    )
+    || (   $request_path =~ m{^/Search/Simple\.html}
+        && $DECODED_ARGS->{'q'} )
+  )
+{
+
+    my $search = Menu()->child('search')->child('tickets');
+    my $args = '';
     my $has_query = '';
     my $current_search = $session{"CurrentSearchHash"} || {};
+    my $search_id = $DECODED_ARGS->{'SavedSearchLoad'} || $DECODED_ARGS->{'SavedSearchId'} || $current_search->{'SearchId'} || '';
+    my $chart_id = $DECODED_ARGS->{'SavedChartSearchId'} || $current_search->{SavedChartSearchId};
+
     $has_query = 1 if ( $DECODED_ARGS->{'Query'} or $current_search->{'Query'} );
 
+    my %query_args;
+    my %fallback_query_args = (
+        SavedSearchId => ( $search_id eq 'new' ) ? undef : $search_id,
+        SavedChartSearchId => $chart_id,
+        (
+            map {
+                my $p = $_;
+                $p => $DECODED_ARGS->{$p} || $current_search->{$p}
+            } qw(Query Format OrderBy Order Page)
+        ),
+        RowsPerPage => (
+            defined $DECODED_ARGS->{'RowsPerPage'}
+            ? $DECODED_ARGS->{'RowsPerPage'}
+            : $current_search->{'RowsPerPage'}
+        ),
+    );
+
+    if ($DECODED_ARGS->{QueryString}) {
+        $args = '?' . $DECODED_ARGS->{QueryString};
+    }
+    else {
+        my %final_query_args = ();
+        # key => callback to avoid unnecessary work
+
+        for my $param (keys %fallback_query_args) {
+            $final_query_args{$param} = defined($DECODED_ARGS->{QueryArgs}->{$param})
+                                      ? $DECODED_ARGS->{QueryArgs}->{$param}
+                                      : $fallback_query_args{$param};
+        }
+
+        for my $field (qw(Order OrderBy)) {
+            if ( ref( $final_query_args{$field} ) eq 'ARRAY' ) {
+                $final_query_args{$field} = join( "|", @{ $final_query_args{$field} } );
+            } elsif (not defined $final_query_args{$field}) {
+                delete $final_query_args{$field};
+            }
+            else {
+                $final_query_args{$field} ||= '';
+            }
+        }
+
+        $args = '?' . $query_string->(%final_query_args);
+    }
+
+    my $current_search_menu;
+    if ( $request_path =~ m{^/Ticket} ) {
+        $current_search_menu = $search->child( 'current_search' );
+    } else {
+        $current_search_menu = PageMenu();
+    }
     if ( $has_query ) {
-        my $tabs = PageMenu;
-        my $feeds = $tabs->child('more'); 
-        
-        $feeds->child(
-            'ods' => title => loc('ODS'),
-            path => '/Search/Results.ods?' . $query_string->( %{ $m->request_args } )
+        my $more = $current_search_menu->child( 'more' );
+
+        $more->child(
+            'xls' => title => loc('ODS'),
+            path => '/Search/Results.ods?' . $args
         );
     }
 }