X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fhtml%2FSearch%2FElements%2FBuildFormatString;h=0526333038f375de09cd9e169afb1979cb74ae54;hb=24548f7cf666bac02335d0bc74f81251c7b4ab50;hp=e5e131b6c8070cffbb7ee62b31add69d8186e8d8;hpb=d39d52aac8f38ea9115628039f0df5aa3ac826de;p=freeside.git diff --git a/rt/html/Search/Elements/BuildFormatString b/rt/html/Search/Elements/BuildFormatString index e5e131b6c..052633303 100644 --- a/rt/html/Search/Elements/BuildFormatString +++ b/rt/html/Search/Elements/BuildFormatString @@ -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-2009 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -22,7 +22,9 @@ %# %# You should have received a copy of the GNU General Public License %# along with this program; if not, write to the Free Software -%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +%# 02110-1301 or visit their web page on the internet at +%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. %# %# %# CONTRIBUTION SUBMISSION POLICY: @@ -42,45 +44,76 @@ %# 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 <%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'}); @@ -90,11 +123,7 @@ foreach (keys %cfqueues) { $CustomFields->LimitToGlobal; while ( my $CustomField = $CustomFields->Next ) { - my $queuestr; - if ($CustomField->QueueObj && $CustomField->QueueObj->Id != 0) { - $queuestr = $CustomField->QueueObj->Name . "."; - } - push @fields, "CustomField." . $queuestr . "{" . $CustomField->Name . "}"; + push @fields, "CustomField.{" . $CustomField->Name . "}"; } my ( @seen); @@ -117,8 +146,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 +159,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 +170,74 @@ elsif ( $ARGS{"AddCol"} ) { } foreach my $col (@columns) { my %column = (); - $column{Column} = $fields[ $col ]; - - if ( $ARGS{Face} eq "Bold" ) { - $column{Prefix} .= ""; - } - if ( $ARGS{Face} eq "Italic" ) { - $column{Prefix} .= ""; - } - if ( $ARGS{Size} ) { - $column{Prefix} .= "<" . $ARGS{Size} . ">"; - } - if ( $ARGS{Link} eq "Display" ) { - $column{Prefix} .= ""; - } - elsif ( $ARGS{Link} eq "Take" ) { - $column{Prefix} .= - ""; - } - - my $suffix; - if ( $ARGS{'Link'} eq "Display" || $ARGS{'Link'} eq "Take" ) { - $column{Suffix} .= ""; - } - if ( $ARGS{Size} ) { - $column{Suffix} .= ""; - } - if ( $ARGS{Face} eq "Italic" ) { - $column{Suffix} .= ""; - } - if ( $ARGS{Face} eq "Bold" ) { - $column{Suffix} .= ""; - } - if ( $ARGS{Title} ) { - $column{Suffix} .= "/TITLE:" . $ARGS{Title}; - } - push @seen, \%column; - } + $column{Column} = $col; + + if ( $Face eq "Bold" ) { + $column{Prefix} .= ""; + $column{Suffix} .= ""; + } + if ( $Face eq "Italic" ) { + $column{Prefix} .= ""; + $column{Suffix} .= ""; } + if ($Size) { + $column{Prefix} .= "<" . $m->interp->apply_escapes( $Size, 'h' ) . ">"; + $column{Suffix} .= "interp->apply_escapes( $Size, 'h' ) . ">"; + } + if ( $Link eq "Display" ) { + $column{Prefix} .= + ""; + $column{Suffix} .= ""; + } + elsif ( $Link eq "Take" ) { + $column{Prefix} .= ""; + $column{Suffix} .= ""; + } + + 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 "" ) ; - $Format .= $field->{Suffix}; - $Format .= "'"; + my $row = "'"; + $row .= $field->{Prefix} if $field->{Prefix}; + $row .= "__" . ($field->{Column} =~ m/\(/ ? $field->{Column} # func, don't escape + : $m->interp->apply_escapes( $field->{Column}, 'h' )) . "__" + unless ( $field->{Column} eq "" ); + $row .= $field->{Suffix} if $field->{Suffix}; + $row .= "'"; + push( @format_string, $row ); } + +$Format = join(",\n", @format_string); + + return($Format, \@fields, \@seen);