Row 4.22 KB
Newer Older
1
%# BEGIN BPS TAGGED BLOCK {{{
2
%# 
3
4
%# COPYRIGHT:
%#  
Jesse Vincent's avatar
Jesse Vincent committed
5
%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6
%#                                          <jesse@bestpractical.com>
7
%# 
8
9
10
11
%# (Except where explicitly superseded by other copyright notices)
%# 
%# 
%# LICENSE:
12
13
14
15
16
17
18
19
20
21
22
%# 
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%# 
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%# 
23
24
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
Jesse Vincent's avatar
Jesse Vincent committed
25
26
27
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
%# http://www.gnu.org/copyleft/gpl.html.
28
29
%# 
%# 
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%# CONTRIBUTION SUBMISSION POLICY:
%# 
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%# 
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%# 
%# END BPS TAGGED BLOCK }}}
48
49
50
51
52
53
54
<%ARGS>
$i => undef
@Format => undef
$record => undef
$maxitems => undef
$Depth => undef
$Warning => undef
55
$ColumnMap => {}
56
$Class     => 'RT__Ticket'
57
</%ARGS>
58
<%init>
59
$m->out('<tr class="' . ( $Warning ? 'warnline' : $i % 2 ? 'oddline' : 'evenline' ) . '" >' . "\n" );
60
use HTML::Entities;
61
my $item;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
62
foreach my $column ( @Format ) {
63
    if ( defined $column->{title} && $column->{title} eq 'NEWLINE' ) {
64
65
66
67
68
        while ( $item < $maxitems ) {
            $m->out(qq{<td class="collection-as-table">&nbsp;</td>\n});
            $item++;
        }
        $item = 0;
69
        $m->out('</tr>' . "\n");
Jesse Vincent's avatar
Jesse Vincent committed
70
        $m->out('<tr class="'
71
              . ( $Warning ? 'warnline' : $i % 2 ? 'oddline' : 'evenline' )
72
              . '" >' . "\n" );
73
74
        next;
    }
75

76
    $item++;
77
    my $class = $column->{class}
Ruslan Zakirov's avatar
Ruslan Zakirov committed
78
79
        ? encode_entities($column->{class}, q{'"&<>})
        : 'collection-as-table';
80
    $m->out(qq{<td class="$class" });
81
    $m->out( 'align="' . $column->{align} . '"' ) if $column->{align};
Ruslan Zakirov's avatar
Ruslan Zakirov committed
82
    $m->out( 'style="' . $column->{style} . '"' ) if $column->{style};
83
    $m->out('>');
84

85
    foreach my $subcol ( @{ $column->{output} } ) {
Ruslan Zakirov's avatar
Ruslan Zakirov committed
86
87
88
89
        unless ( $subcol =~ /^__(.*?)__$/ ) {
            $m->out( $subcol );
            next;
        }
90

Ruslan Zakirov's avatar
Ruslan Zakirov committed
91
92
93
        my $col = $1;
        unless ( exists $ColumnMap->{ $col } ) {
            $ColumnMap->{ $col } = $m->comp(
Ruslan Zakirov's avatar
Ruslan Zakirov committed
94
95
96
97
                "/Elements/ColumnMap",
                Class => $Class,
                Name  => $col,
                Attr  => 'value'
Ruslan Zakirov's avatar
Ruslan Zakirov committed
98
99
            );
        }
100

Ruslan Zakirov's avatar
Ruslan Zakirov committed
101
102
        my $value = $ColumnMap->{ $col };
        my @out;
103

Ruslan Zakirov's avatar
Ruslan Zakirov committed
104
        if ( ref $value ) {
105

Ruslan Zakirov's avatar
Ruslan Zakirov committed
106
107
108
109
110
111
            # All HTML snippets are returned by the callback function
            # as scalar references.  Data fetched from the objects are
            # plain scalars, and needs to be escaped properly.
            @out = grep defined && length, map {
                ref($_) ? $$_ : $m->interp->apply_escapes( $_ => 'h' )
            } $value->( $record, $i );
112
        }
Ruslan Zakirov's avatar
Ruslan Zakirov committed
113
114
115
116
        elsif ( defined $value && length $value ) {

            # Simple value; just escape it.
            @out = $m->interp->apply_escapes( $value => 'h' );
117
        }
Ruslan Zakirov's avatar
Ruslan Zakirov committed
118
119
        s/\n/<br \/>/gs for @out;
        $m->out( @out ) if @out;
120
    }
121
    $m->out('</td>' . "\n");
122
}
Jesse Vincent's avatar
Jesse Vincent committed
123
$m->out('</tr>');
124
</%init>