1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 %# CONTRIBUTION SUBMISSION POLICY:
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
45 %# END BPS TAGGED BLOCK }}}
46 <& /Elements/ListActions, actions => \@results &>
48 <FORM ACTION="<%$RT::WebPath%><% $m->request_comp->path |n %>" METHOD="POST" NAME="EditCustomFields">
49 <INPUT TYPE=HIDDEN NAME="id" VALUE="<% $Object->Id %>"/>
50 <INPUT TYPE=HIDDEN NAME="ObjectType" VALUE="<% $ObjectType %>"/>
51 <INPUT TYPE=HIDDEN NAME="SubType" VALUE="<% $SubType %>"/>
52 <INPUT TYPE=HIDDEN NAME="UpdateCFs" VALUE="1"/>
55 <h2><&|/l&>Global Custom Fields</&></h2>
56 <& PickCustomFields, CustomFields => \@GlobalCFs, ReadOnly => 1, id => $id, SubType => $SubType &>
58 <h2><&|/l&>Selected Custom Fields</&></h2>
59 <& PickCustomFields, CustomFields => [$ObjectCFs->CustomFields], id => $id, Checked => 1, SubType => $SubType &>
60 <h2><&|/l&>Unselected Custom Fields</&></h2>
61 <& PickCustomFields, CustomFields => \@UnassignedCFs, id => $id, SubType => $SubType &>
63 <& /Elements/Submit, CheckAll => 1, ClearAll => 1 &>
68 my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
70 my (@GlobalCFs, @UnassignedCFs);
73 if ($id and !$Object->CurrentUserHasRight('AssignCustomFields')) {
74 $m->out('<P><i>', loc('(No custom fields)'), '</i></P>');
78 my $lookup = $ObjectType;
79 $lookup .= "-$SubType" if $SubType;
81 $CustomFields->LimitToLookupType($lookup);
82 $CustomFields->OrderBy( FIELD => 'Name' );
85 my ($GlobalCFs, $ObjectCFs);
86 $ObjectCFs = RT::ObjectCustomFields->new($session{'CurrentUser'});
88 $ObjectCFs->LimitToObjectId($id);
89 $ObjectCFs->LimitToLookupType($lookup);
91 # {{{ deal with moving sortorder of custom fields
92 if ($CustomField and $Move) {
93 my $SourceObj = RT::ObjectCustomField->new($session{'CurrentUser'});
94 $SourceObj->LoadByCols( ObjectId => $id, CustomField => $CustomField );
97 my $target_order = $SourceObj->SortOrder + $Move;
98 while (my $ObjectCF = $ObjectCFs->Next) {
99 my $this_order = $ObjectCF->SortOrder;
101 # if we have an exact match, finish the loop now
102 ($TargetObj = $ObjectCF, last) if $this_order == $target_order;
104 # otherwise, we need to apropos toward the general direction
105 # ... first, check the sign is correct
106 next unless ($this_order - $SourceObj->SortOrder) * $Move > 0;
108 # ... next, see if we already have a candidate
110 # ... if yes, compare the delta and choose the smaller one
111 my $orig_delta = abs($TargetObj->SortOrder - $target_order);
112 my $this_delta = abs($this_order - $target_order);
113 next if $orig_delta < $this_delta;
116 $TargetObj = $ObjectCF;
120 # swap their sort order
121 my ($s, $t) = ($SourceObj->SortOrder, $TargetObj->SortOrder);
122 $TargetObj->SetSortOrder($s);
123 $SourceObj->SetSortOrder($t);
124 # because order changed, we must redo search for subsequent uses
127 $ObjectCFs->GotoFirstItem;
132 $GlobalCFs = RT::ObjectCustomFields->new($session{'CurrentUser'});
133 $GlobalCFs->LimitToObjectId(0);
134 $GlobalCFs->LimitToLookupType($lookup);
137 while (my $cf = $CustomFields->Next) {
140 if ($GlobalCFs and $GlobalCFs->HasEntryForCustomField($cf_id)) {
141 push @GlobalCFs, $cf;
146 # Go through and delete all the custom field relationships that this object
148 my $key = "Object-$id-CF-$cf_id";
150 if (!$ObjectCFs->HasEntryForCustomField($cf_id)) {
151 my ($val, $msg) = $cf->AddToObject($Object);
152 push (@results, $msg);
153 push @UnassignedCFs, $cf if !$val;
157 push @UnassignedCFs, $cf;
158 if ($ObjectCFs->HasEntryForCustomField($cf_id)) {
159 my ($val, $msg) = $cf->RemoveFromObject($Object);
160 push (@results, $msg);
161 pop @UnassignedCFs if !$val;
165 elsif (!$ObjectCFs->HasEntryForCustomField($cf_id)) {
166 push @UnassignedCFs, $cf;
173 $ObjectCFs = RT::ObjectCustomFields->new($session{'CurrentUser'});
175 $ObjectCFs->LimitToObjectId($id);
176 $ObjectCFs->LimitToLookupType($lookup);
183 $CustomField => undef
184 $FindDisabledCustomFields => undef