rt 4.2.15
[freeside.git] / rt / share / html / Search / Results.tsv
index 977b1ea..3551258 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -54,56 +54,8 @@ $PreserveNewLines => 0
 </%ARGS>
 <%INIT>
 
-$r->content_type('text/tab-separated-values');
 $r->header_out('Content-Disposition' => 'attachment;filename="Results.tsv"');
 
-my $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $Format);
-
-my @Format = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $DisplayFormat);
-
-my @columns;
-
-my $should_loc = { map { $_ => 1 } qw(Status) };
-
-my $col_entry = sub {
-    my $col = shift;
-    # in tsv output, "#" is often a comment character but we use it for "id"
-    delete $col->{title}
-        if $col->{title} and $col->{title} =~ /^\s*#\s*$/;
-    return {
-        header => Encode::encode_utf8(loc($col->{title} || $col->{attribute})),
-        map    => $m->comp(
-            "/Elements/ColumnMap",
-            Name  => $col->{attribute},
-            Attr  => 'value'
-        ),
-        should_loc => $should_loc->{$col->{attribute}},
-    }
-};
-
-if ($PreserveNewLines) {
-    my $col = [];
-    push @columns, $col;
-    for (@Format) {
-        if ($_->{title} eq 'NEWLINE') {
-            $col = [];
-            push @columns, $col;
-        }
-        else {
-            push @$col, $col_entry->($_);
-        }
-    }
-}
-else {
-    push @columns, [map { $_->{attribute}
-                          ? $col_entry->($_)
-                          : () } @Format];
-}
-
-for (@columns) {
-    $m->out(join("\t", map { $_->{header} } @$_)."\n");
-}
-
 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
 $Tickets->FromSQL( $Query );
 if ( $OrderBy =~ /\|/ ) {
@@ -119,19 +71,5 @@ else {
     $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
 }
 
-my $ii = 0;
-while (my $row = $Tickets->Next) {
-    for my $col (@columns) {
-        $m->out(join("\t", map {
-            my $val = ProcessColumnMapValue($_->{map}, Arguments => [$row, $ii++], Escape => 0);
-            $val = loc($val) if $_->{should_loc};
-            # remove tabs from all field values, they screw up the tsv
-            $val = '' unless defined $val;
-            $val =~ s/(?:\n|\r)//g; $val =~ s{\t}{    }g;
-            Encode::encode_utf8($val);
-        } @$col)."\n");
-    }
-}
-$m->abort();
-
+$m->comp( "/Elements/TSVExport", Collection => $Tickets, Format => $Format, PreserveNewLines => $PreserveNewLines );
 </%INIT>