fix additional instance of rt/rt problem, RT#9280
[freeside.git] / rt / share / html / Admin / Elements / EditCustomFields
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@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 <& /Elements/ListActions, actions => \@results &>
49
50 % my $path = $m->request_comp->path;
51 % $path =~ s(^/rt)(); #hacky, dunno why this happens
52 <form action="<%RT->Config->Get('WebPath')%><% $path |n %>" method="post" name="EditCustomFields">
53 <input type="hidden" class="hidden" name="id" value="<% $Object->Id || ''%>" />
54 <input type="hidden" class="hidden" name="ObjectType" value="<% $ObjectType %>" />
55 <input type="hidden" class="hidden" name="SubType" value="<% $SubType %>" />
56
57 <h2><&|/l&>Selected Custom Fields</&></h2>
58 <& /Elements/CollectionList,
59     %ARGS,
60     Collection    => $applied_cfs,
61     Rows          => 0,
62     Page          => 1,
63     Format        => $format,
64     DisplayFormat =>
65         $id
66             ? ("'__RemoveCheckBox.{$id}__',". $format .", '__MoveCF.{$id}__'")
67             : ("'__CheckBox.{RemoveCustomField}__',". $format .", '__MoveCF.{$id}__'"),
68     AllowSorting  => 0,
69     ShowEmpty     => 0,
70     PassArguments => [
71         qw(Page Order OrderBy),
72         qw(id ObjectType SubType),
73     ],
74 &>
75
76 <h2><&|/l&>Unselected Custom Fields</&></h2>
77 <& /Elements/CollectionList,
78     OrderBy       => 'Name',
79     Order         => 'ASC',
80     %ARGS,
81     Collection    => $not_applied_cfs,
82     Rows          => 50,
83     Format        => $format,
84     DisplayFormat => "'__CheckBox.{AddCustomField}__',". $format,
85     AllowSorting  => 1,
86     ShowEmpty     => 0,
87     PassArguments => [
88         qw(Page Order OrderBy),
89         qw(id ObjectType SubType),
90     ],
91 &>
92
93 <& /Elements/Submit, Name => 'UpdateCFs' &>
94 </form>
95
96
97 <%INIT>
98 my $id = $Object->Id || 0;
99 if ($id and !$Object->CurrentUserHasRight('AssignCustomFields')) {
100     $m->out('<p><i>', loc('(No custom fields)'), '</i></p>');
101     return;
102 }
103
104 my @results;
105
106 my $lookup = $ObjectType;
107 $lookup .= "-$SubType" if $SubType;
108
109 ## deal with moving sortorder of custom fields
110 if ( $MoveCustomFieldUp ) { {
111     my $record = RT::ObjectCustomField->new( $session{'CurrentUser'} );
112     $record->LoadByCols( ObjectId => $id, CustomField => $MoveCustomFieldUp );
113     unless ( $record->id ) {
114         push @results, loc("Custom field #[_1] is not applied to this object", $MoveCustomFieldUp);
115         last;
116     }
117
118     my ($status, $msg) = $record->MoveUp;
119     push @results, $msg;
120 } }
121 if ( $MoveCustomFieldDown ) { {
122     my $record = RT::ObjectCustomField->new( $session{'CurrentUser'} );
123     $record->LoadByCols( ObjectId => $id, CustomField => $MoveCustomFieldDown );
124     unless ( $record->id ) {
125         push @results, loc("Custom field #[_1] is not applied to this object", $MoveCustomFieldDown);
126         last;
127     }
128
129     my ($status, $msg) = $record->MoveDown;
130     push @results, $msg;
131 } }
132
133 if ( $UpdateCFs ) {
134     foreach my $cf_id ( @AddCustomField ) {
135         my $CF = RT::CustomField->new( $session{'CurrentUser'} );
136         $CF->Load( $cf_id );
137         unless ( $CF->id ) {
138             push @results, loc("Couldn't load CustomField #[_1]", $cf_id);
139             next;
140         }
141         my ($status, $msg) = $CF->AddToObject( $Object );
142         push @results, $msg;
143     }
144     foreach my $cf_id ( @RemoveCustomField ) {
145         my $CF = RT::CustomField->new( $session{'CurrentUser'} );
146         $CF->Load( $cf_id );
147         unless ( $CF->id ) {
148             push @results, loc("Couldn't load CustomField #[_1]", $cf_id);
149             next;
150         }
151         my ($status, $msg) = $CF->RemoveFromObject( $Object );
152         push @results, $msg;
153     }
154 }
155
156 my $applied_cfs = RT::CustomFields->new( $session{'CurrentUser'} );
157 $applied_cfs->LimitToLookupType($lookup);
158 $applied_cfs->LimitToGlobalOrObjectId($id);
159 $applied_cfs->ApplySortOrder;
160
161 my $not_applied_cfs = RT::CustomFields->new( $session{'CurrentUser'} );
162 $not_applied_cfs->LimitToLookupType($lookup);
163 $not_applied_cfs->LimitToNotApplied( $id ? ($id, 0) : (0) );
164
165 my $format = RT->Config->Get('AdminSearchResultFormat')->{'CustomFields'};
166
167 </%INIT>
168 <%ARGS>
169 $Object
170 $ObjectType
171 $SubType => ''
172
173 $UpdateCFs           => undef
174 @RemoveCustomField   => ()
175 @AddCustomField      => ()
176 $MoveCustomFieldUp   => undef
177 $MoveCustomFieldDown => undef
178 </%ARGS>