ShowCustomFields 4.14 KB
Newer Older
1
%# BEGIN BPS TAGGED BLOCK {{{
Audrey Tang's avatar
Audrey Tang committed
2
%# 
3
%# COPYRIGHT:
Jesse Vincent's avatar
Jesse Vincent committed
4
%# 
5
%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6
%#                                          <jesse@bestpractical.com>
Audrey Tang's avatar
Audrey Tang committed
7
%# 
8
9
10
11
%# (Except where explicitly superseded by other copyright notices)
%# 
%# 
%# LICENSE:
Audrey Tang's avatar
Audrey Tang committed
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
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
Ruslan Zakirov's avatar
Ruslan Zakirov committed
27
%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28
29
30
31
32
33
34
35
36
%# 
%# 
%# 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.)
Audrey Tang's avatar
Audrey Tang committed
37
%# 
38
39
40
41
42
43
44
45
%# 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.
Audrey Tang's avatar
Audrey Tang committed
46
%# 
47
%# END BPS TAGGED BLOCK }}}
48
% if ($Table) {
Audrey Tang's avatar
Audrey Tang committed
49
<table>
50
% }
51
52
53
% while ( my $CustomField = $CustomFields->Next ) {
% my $Values = $Object->CustomFieldValues( $CustomField->Id );
% my $count = $Values->Count;
54
  <tr id="CF-<%$CustomField->id%>-ShowRow">
Ruslan Zakirov's avatar
indent    
Ruslan Zakirov committed
55
    <td class="label"><% $CustomField->Name %>:</td>
Audrey Tang's avatar
Audrey Tang committed
56
    <td class="value">
57
58
59
60
61
% unless ( $count ) {
<i><&|/l&>(no value)</&></i>
% } elsif ( $count == 1 ) {
%   $print_value->( $CustomField, $Values->First );
% } else {
62
<ul>
63
% while ( my $Value = $Values->Next ) {
64
65
66
<li>
% $print_value->( $CustomField, $Value );
</li>
Audrey Tang's avatar
Audrey Tang committed
67
% }
68
</ul>
69
% }
Audrey Tang's avatar
Audrey Tang committed
70
71
72
    </td>
  </tr>
% }
73
% if ($Table) {
Audrey Tang's avatar
Audrey Tang committed
74
</table>
75
% }
Audrey Tang's avatar
Audrey Tang committed
76
<%INIT>
77
78
79
80
81
$m->callback(
    CallbackName => 'MassageCustomFields',
    Object => $Object,
    CustomFields => $CustomFields,
);
Jesse Vincent's avatar
Jesse Vincent committed
82

83
84
my $print_value = sub {
    my ($cf, $value) = @_;
85
86
87
88
    my $linked = $value->LinkValueTo;
    if ( defined $linked && length $linked ) {
        my $linked = $m->interp->apply_escapes( $linked, 'h' );
        $m->out('<a href="'. $linked .'" target="_new">');
Ruslan Zakirov's avatar
Ruslan Zakirov committed
89
    }
90
    my $comp = "ShowCustomField". $cf->Type;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
91
92
93
94
95
    $m->callback(
        CallbackName => 'ShowComponentName',
        Name         => \$comp,
        CustomField  => $cf,
        Object       => $Object,
Ruslan Zakirov's avatar
Ruslan Zakirov committed
96
    );
97
98
99
    if ( $m->comp_exists( $comp ) ) {
        $m->comp( $comp, Object => $value );
    } else {
100
        $m->out( $m->interp->apply_escapes( $value->Content, 'h' ) );
101
    }
102
    $m->out('</a>') if defined $linked && length $linked;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
103
104
105
106

    # This section automatically populates a div with the "IncludeContentForValue" for this custom
    # field if it's been defined
    if ( $cf->IncludeContentForValue ) {
Ruslan Zakirov's avatar
Ruslan Zakirov committed
107
       my $vid = $value->id;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
108
109
110
111
112
113
       $m->out(   '<div class="object_cf_value_include" id="object_cf_value_'. $vid .'">' );
       $m->print( loc("See also:") );
       $m->out(   '<a href="'. $value->IncludeContentForValue .'">' );
       $m->print( $value->IncludeContentForValue );
       $m->out(   qq{</a></div>\n} );
       $m->out(   qq{<script><!--\nahah('} );
Ruslan Zakirov's avatar
Ruslan Zakirov committed
114
115
       $m->print( $value->IncludeContentForValue );
       $m->out(   qq{', 'object_cf_value_$vid');\n--></script>\n} );
Ruslan Zakirov's avatar
Ruslan Zakirov committed
116
    }
117
118
};

Audrey Tang's avatar
Audrey Tang committed
119
120
121
</%INIT>
<%ARGS>
$Object => undef
122
$CustomFields => $Object->CustomFields
123
$Table => 1
Audrey Tang's avatar
Audrey Tang committed
124
</%ARGS>