import rt 3.4.4
[freeside.git] / rt / html / Search / Elements / BuildFormatString
index e5e131b..639e62c 100644 (file)
@@ -1,8 +1,8 @@
-%# {{{ BEGIN BPS TAGGED BLOCK
+%# BEGIN BPS TAGGED BLOCK {{{
 %# 
 %# COPYRIGHT:
 %#  
-%# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
+%# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
 %#                                          <jesse@bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
 %# works based on those contributions, and sublicense and distribute
 %# those contributions and any derivatives thereof.
 %# 
-%# }}} END BPS TAGGED BLOCK
+%# END BPS TAGGED BLOCK }}}
 <%args>
 $Format => undef
 %cfqueues => undef
+$Face => undef
+$Size => undef
+$Link => undef
+$Title => undef
+$AddCol => undef
+$RemoveCol => undef
+$ColUp => undef
+$ColDown => undef
+$SelectDisplayColumns => undef
+$CurrentDisplayColumns => undef
 </%args>
 <%init>
 
 unless ($Format) {         
     $Format = $RT::DefaultSearchResultFormat;
 }   
-    
-my @fields = (
-    "QueueName",           "OwnerName",
-    "id",                  "Status",
-    "Subject",             "ExtendedStatus",
-    "Priority",            "InitialPriority",
-    "FinalPriority",       "EffectiveId",
-    "Type",                "TimeWorked",
-    "TimeLeft",            "TimeEstimated",
-    "Requestors",          "Cc",
-    "AdminCc",             "StartsRelative",
-    "StartedRelative",     "CreatedRelative",
-    "LastUpdatedRelative", "ToldRelative",
-    "DueRelative",         "ResolvedRelative",
-    "Starts",              "Started",
-    "Created",             "CreatedBy",
-    "LastUpdated",         "LastUpdatedBy",
-    "Told",                "Due",
-    "Resolved",            "NEWLINE",
-    "RefersTo",                   "ReferredToBy",
-    "DependsOn",           "DependedOnBy",
-    "MemberOf",            "Members",
-    "Parents",             "Children",
-    "-",
+   
+
+# All the things we can display in the format string by default
+my @fields = qw(
+  id
+  Status
+  ExtendedStatus
+  Subject
+  QueueName
+  OwnerName
+  Priority
+  InitialPriority
+  FinalPriority
+  Type
+  TimeWorked
+  TimeLeft
+  TimeEstimated
+  CreatedBy
+  LastUpdatedBy
+  Requestors
+  Cc
+  AdminCc
+  Starts
+  StartsRelative
+  Started
+  StartedRelative
+  Created
+  CreatedRelative
+  LastUpdated
+  LastUpdatedRelative
+  Told
+  ToldRelative
+  Due
+  DueRelative
+  Resolved
+  ResolvedRelative
+  RefersTo
+  ReferredToBy
+  DependsOn
+  DependedOnBy
+  MemberOf
+  Members
+  Parents
+  Children
+  NEWLINE
 );
 
 my $CustomFields = RT::CustomFields->new( $session{'CurrentUser'});
-foreach (keys %cfqueues) {
-    my $id = $_;
+foreach my $id (keys %cfqueues) {
+    # What does this _do_? What are the keys to cfqueues
     $id =~ s/^.'*(.*).'*$/$1/;
     # Gotta load up the $queue object, since queues get stored by name now.
     my $queue = RT::Queue->new($session{'CurrentUser'});
@@ -117,8 +148,8 @@ foreach my $field (@format) {
     push @seen, \%column;
 }
 
-if ( $ARGS{"RemoveCol"} ) {
-    my $index  = $ARGS{'CurrentDisplayColumns'};
+if ( $RemoveCol ) {
+    my $index  = $CurrentDisplayColumns;
     my $column = $seen[$index];
     if ($index) {
         delete $seen[$index];
@@ -130,9 +161,9 @@ if ( $ARGS{"RemoveCol"} ) {
         }
     }
 }
-elsif ( $ARGS{"AddCol"} ) {
-    if ( defined $ARGS{'SelectDisplayColumns'} ) {
-       my $selected = $ARGS{'SelectDisplayColumns'};
+elsif ( $AddCol ) {
+    if ( defined $SelectDisplayColumns ) {
+       my $selected = $SelectDisplayColumns;
        my @columns;
        if (ref($selected) eq 'ARRAY') {
            @columns = @$selected;
@@ -141,74 +172,71 @@ elsif ( $ARGS{"AddCol"} ) {
        }
        foreach my $col (@columns) {
            my %column = ();
-           $column{Column} = $fields[ $col ];
-           
-           if ( $ARGS{Face} eq "Bold" ) {
-               $column{Prefix} .= "<B>";
-           }
-           if ( $ARGS{Face} eq "Italic" ) {
-               $column{Prefix} .= "<I>";
-           }
-           if ( $ARGS{Size} ) {
-               $column{Prefix} .= "<" . $ARGS{Size} . ">";
-           }
-           if ( $ARGS{Link} eq "Display" ) {
-               $column{Prefix} .= "<A HREF=\"".$RT::WebPath."/Ticket/Display.html?id=__id__\">";
-           }
-           elsif ( $ARGS{Link} eq "Take" ) {
-               $column{Prefix} .=
-                   "<A HREF=\"".$RT::WebPath."/Ticket/Display.html?Action=Take&id=__id__\">";
-           }
-    
-           my $suffix;
-           if ( $ARGS{'Link'} eq "Display" || $ARGS{'Link'} eq "Take" ) {
-               $column{Suffix} .= "</a>";
-           }
-           if ( $ARGS{Size} ) {
-               $column{Suffix} .= "</" . $ARGS{Size} . ">";
-           }
-           if ( $ARGS{Face} eq "Italic" ) {
-               $column{Suffix} .= "</I>";
-           }
-           if ( $ARGS{Face} eq "Bold" ) {
-               $column{Suffix} .= "</B>";
-           }
-           if ( $ARGS{Title} ) {
-               $column{Suffix} .= "/TITLE:" . $ARGS{Title};
-           }
-           push @seen, \%column;
-       }
+           $column{Column} = $col;
+
+    if ( $Face eq "Bold" ) {
+        $column{Prefix} .= "<B>";
+        $column{Suffix} .= "</B>";
+    }
+    if ( $Face eq "Italic" ) {
+        $column{Prefix} .= "<I>";
+        $column{Suffix} .= "</I>";
+    }
+    if ($Size) {
+        $column{Prefix} .= "<" . $m->interp->apply_escapes( $Size,  'h' ) . ">";
+        $column{Suffix} .= "</" . $m->interp->apply_escapes( $Size, 'h' ) . ">";
+    }
+    if ( $Link eq "Display" ) {
+        $column{Prefix} .=
+          "<A HREF=\"" . $RT::WebPath . "/Ticket/Display.html?id=__id__\">";
+        $column{Suffix} .= "</a>";
+    }
+    elsif ( $Link eq "Take" ) {
+        $column{Prefix} .= "<A HREF=\"" . $RT::WebPath
+          . "/Ticket/Display.html?Action=Take&id=__id__\">";
+        $column{Suffix} .= "</a>";
+    }
+
+    if ($Title) {
+        $column{Suffix} .= "/TITLE:" . $m->interp->apply_escapes( $Title, 'h' );
     }
+    push @seen, \%column;
+}
+}
 }
-elsif ( $ARGS{"ColUp"} ) {
-    my $index = $ARGS{'CurrentDisplayColumns'};
+elsif ( $ColUp ) {
+    my $index = $CurrentDisplayColumns;
     if ( defined $index && ( $index - 1 ) >= 0 ) {
         my $column = $seen[$index];
         $seen[$index]       = $seen[ $index - 1 ];
         $seen[ $index - 1 ] = $column;
-        $ARGS{CurrentDisplayColumns}     = $index - 1;
+        $CurrentDisplayColumns     = $index - 1;
     }
 }
-elsif ( $ARGS{"ColDown"} ) {
-    my $index = $ARGS{'CurrentDisplayColumns'};
+elsif ( $ColDown ) {
+    my $index = $CurrentDisplayColumns;
     if ( defined $index && ( $index + 1 ) < scalar @seen ) {
         my $column = $seen[$index];
         $seen[$index]       = $seen[ $index + 1 ];
         $seen[ $index + 1 ] = $column;
-        $ARGS{CurrentDisplayColumns}     = $index + 1;
+        $CurrentDisplayColumns     = $index + 1;
     }
 }
 
-$Format = "";
+
+my @format_string;
 foreach my $field (@seen) {
     next unless $field;
-    $Format .= ", \n" if $Format;
-    $Format .= "'";
-    $Format .= $field->{Prefix};
-    $Format .= "__" . $field->{Column} . "__" if ( $field->{Column} ne "<blank>" ) ;
-    $Format .= $field->{Suffix};
-    $Format .= "'";
+    my $row = "'" . $field->{Prefix};
+    $row .= "__" . $m->interp->apply_escapes( $field->{Column}, 'h' ) . "__"
+      unless ( $field->{Column} eq "<blank>" );
+    $row .= $field->{Suffix} . "'";
+    push( @format_string, $row );
 }
+
+$Format = join(",\n", @format_string);
+
+
 return($Format, \@fields, \@seen);
 
 </%init>