1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
5%# This software is Copyright (c) 1996-2021 Best Practical Solutions, LLC
6%#                                          <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
13%# This work is made available to you under the terms of Version 2 of
14%# the GNU General Public License. A copy of that license should have
15%# been provided with this software, but in any event can be snarfed
16%# from www.gnu.org.
17%#
18%# This work is distributed in the hope that it will be useful, but
19%# WITHOUT ANY WARRANTY; without even the implied warranty of
20%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21%# General Public License for more details.
22%#
23%# You should have received a copy of the GNU General Public License
24%# along with this program; if not, write to the Free Software
25%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26%# 02110-1301 or visit their web page on the internet at
27%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
32%# (The following paragraph is not intended to limit the rights granted
33%# to you to modify and distribute this software under the terms of
34%# the GNU General Public License and is only of importance to you if
35%# you choose to contribute your changes and enhancements to the
36%# community by submitting them to Best Practical Solutions, LLC.)
37%#
38%# By intentionally submitting any modifications, corrections or
39%# derivatives to this work, or any other work intended for use with
40%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41%# you are the copyright holder for those contributions and you grant
42%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43%# royalty-free, perpetual, license to use, copy, create derivative
44%# works based on those contributions, and sublicense and distribute
45%# those contributions and any derivatives thereof.
46%#
47%# END BPS TAGGED BLOCK }}}
48% $m->callback( CallbackName => 'BeforeCustomFields', Object => $Object,
49%               Grouping => $Grouping, ARGSRef => \%ARGS, CustomFields => $CustomFields);
50
51%# only show the wrapper if there are editable custom fields, so we can
52%# suppress the empty titlebox. we do this in such a way that we still call the
53%# BeforeCustomFields and AfterCustomFields callbacks (rather than returning
54%# from the INIT block) to maintain compatibility with old behavior
55
56% if (@CustomFields) {
57
58% if ( $WRAP ) {
59<<% $WRAP %> class="edit-custom-fields">
60% }
61% for my $CustomField (@CustomFields) {
62% my $Type = $CustomField->Type || 'Unknown';
63% my @classes = (
64%   'edit-custom-field',
65%   "cftype-$Type",
66% );
67% $m->callback( CallbackName => 'ModifyFieldClasses', CustomField => $CustomField,
68%               Object => $Object, Classes => \@classes, Grouping => $Grouping );
69  <<% $FIELD %> class="<% join(' ', @classes) %>">
70    <<% $CELL %> class="cflabel">
71      <span class="name"><% $CustomField->Name %>:</span><br />
72      <span class="type"><% $CustomField->EntryHint // '' %></span>
73    </<% $CELL %>>
74    <<% $CELL %> class="entry">
75% my $default = $m->notes('Field-' . $CustomField->Id);
76% $default ||= $ARGS{"CustomField-". $CustomField->Id };
77      <& /Elements/EditCustomField,
78          %ARGS,
79          CustomField => $CustomField,
80          Default => $default,
81          Object => $Object,
82      &>
83%  if (my $msg = $m->notes('InvalidField-' . $CustomField->Id)) {
84        <br />
85        <span class="cfinvalidfield"><% $msg %></span>
86%  } elsif ($ShowHints and $CustomField->FriendlyPattern) {
87        <br>
88        <span class="cfhints">
89          <&|/l, $CustomField->FriendlyPattern &>Input must match [_1]</&>
90        </span>
91%  }
92    </<% $CELL %>>
93% $m->callback( CallbackName => 'AfterCustomFieldValue', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );
94  </<% $FIELD %>>
95% }
96
97% if ( $WRAP ) {
98</<% $WRAP %>>
99% }
100
101% }
102
103% $m->callback( CallbackName => 'AfterCustomFields', Object => $Object,
104%               Grouping => $Grouping, ARGSRef => \%ARGS );
105<%INIT>
106$CustomFields ||= $Object->CustomFields;
107$CustomFields->{include_set_initial} = 1 if $ForCreation;
108
109$CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
110
111$m->callback( %ARGS, CallbackName => 'MassageCustomFields', CustomFields => $CustomFields,
112                  Object => $Object, ShowHintsRef => \$ShowHints, InTableRef => \$InTable );
113
114$CustomFields->GotoFirstItem;
115my @CustomFields;
116while ( my $CustomField = $CustomFields->Next ) {
117    next unless $CustomField->CurrentUserHasRight('ModifyCustomField')
118             || ($ForCreation && $CustomField->CurrentUserHasRight('SetInitialCustomField'));
119
120    push @CustomFields, $CustomField;
121}
122
123$AsTable ||= $InTable;
124my $FIELD = $AsTable ? 'tr' : 'div';
125my $CELL  = $AsTable ? 'td' : 'div';
126my $WRAP  = '';
127if ( $AsTable ) {
128    $WRAP = 'table' unless $InTable;
129} else {
130    $WRAP = 'div';
131}
132
133</%INIT>
134<%ARGS>
135$Object
136$CustomFields => undef
137$Grouping     => undef
138$AsTable => 1
139$InTable => 0
140$ShowHints => 1
141$ForCreation => 0
142</%ARGS>
143