1 %# {{{ BEGIN BPS TAGGED BLOCK
5 %# This software is Copyright (c) 1996-2004 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 => \@actions &>
53 % if ($CustomFields->Count == 0 ) {
54 <P><i><&|/l&>(No custom fields)</&></i></P>
56 <TABLE cellspacing=0 cellpadding=2>
58 % while (my $CustomFieldObj = $CustomFields->Next) {
61 % if ($CustomFieldObj->Name) {
62 <A HREF="CustomField.html?Queue=<%$id%>&CustomField=<%$CustomFieldObj->id()%>"><b><%$CustomFieldObj->Name%></b></a><br>
64 <A HREF="CustomField.html?Queue=<%$id%>&CustomField=<%$CustomFieldObj->id()%>"><i>(<%loc("no name")%>)</i></a><br>
66 <%$CustomFieldObj->Description%>
69 <i><% $CustomFieldObj->FriendlyType %></i>
71 % # show 'move up' unless it's the first item
74 <a href="CustomFields.html?id=<%$id%>&CustomField=<%$CustomFieldObj->id%>&Move=-1"><&|/l&>Move up</&></a>
76 <TD valign="TOP" ALIGN=RIGHT>
79 % # show 'move down' unless it's the last item
80 % if (!$CustomFields->IsLast) {
81 % $m->print(' | ') if $count > 1;
82 <a href="CustomFields.html?id=<%$id%>&CustomField=<%$CustomFieldObj->id%>&Move=1"><&|/l&>Move down</&></a>
90 <FORM METHOD=GET ACTION="CustomFields.html">
92 <INPUT TYPE="Hidden" NAME="id" VALUE="<%$id%>">
94 <input type="checkbox" name="FindDisabledCustomFields"> <&|/l&>Include disabled custom fields in listing.</&>
95 <input type=submit value="<&|/l&>Go!</&>">
100 my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
101 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
105 $QueueObj->Load($id);
109 $CustomFields->LimitToQueue($id);
112 $CustomFields->LimitToGlobal();
115 if ($FindDisabledCustomFields) {
116 $caption = loc("All Custom Fields");
117 $CustomFields->{'find_disabled_rows'} = 1;
119 $caption = loc("Enabled Custom Fields");
122 # {{{ deal with moving sortorder of custom fields
123 if ($CustomField and $Move) {
124 my $SourceObj = RT::CustomField->new($session{'CurrentUser'});
125 $SourceObj->Load($CustomField) || Abort(loc('No CustomField'));
128 my $target_order = $SourceObj->SortOrder + $Move;
129 while (my $CustomFieldObj = $CustomFields->Next) {
130 my $this_order = $CustomFieldObj->SortOrder;
132 # if we have an exact match, finish the loop now
133 ($TargetObj = $CustomFieldObj, last) if $this_order == $target_order;
135 # otherwise, we need to apropos toward the general direction
136 # ... first, check the sign is correct
137 next unless ($this_order - $SourceObj->SortOrder) * $Move > 0;
139 # ... next, see if we already have a candidate
141 # ... if yes, compare the delta and choose the smaller one
142 my $orig_delta = abs($TargetObj->SortOrder - $target_order);
143 my $this_delta = abs($this_order - $target_order);
144 next if $orig_delta < $this_delta;
147 $TargetObj = $CustomFieldObj;
151 # swap their sort order
152 my ($s, $t) = ($SourceObj->SortOrder, $TargetObj->SortOrder);
153 $TargetObj->SetSortOrder($s);
154 $SourceObj->SetSortOrder($t);
155 # because order changed, we must redo search for subsequent uses
156 $CustomFields->RedoSearch;
159 $CustomFields->GotoFirstItem;
163 # {{{ now process the 'copy queue' action
165 if ($Source and $Source ne $id) {
166 my $SourceQueue = RT::Queue->new($session{'CurrentUser'});
167 $SourceQueue->Load($Source) || Abort(loc("Couldn't load queue"));
168 my $SourceCustomFields = RT::CustomFields->new($session{'CurrentUser'});
169 $SourceCustomFields->LimitToQueue($SourceQueue->id);
172 foreach my $CustomFieldObj ( @{$CustomFields->ItemsArrayRef} ) {
173 $CustomFieldObj->Delete;
177 while (my $SourceCustomFieldObj = $SourceCustomFields->Next) {
178 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
179 my ($val, $msg) = $CustomFieldObj->Create(
180 id => $SourceCustomFieldObj->id,
182 Name => $SourceCustomFieldObj->Name,
183 Type => $SourceCustomFieldObj->Type,
184 Description => $SourceCustomFieldObj->Description,
186 Abort(loc("Could not create CustomField") . ": $msg") unless ($val);
189 $CustomFieldObj->SetSortOrder($SourceCustomFieldObj->SortOrder);
192 my $values = $SourceCustomFieldObj->Values();
193 while (my $v = $values->Next) {
194 my ( $addval, $addmsg ) = $CustomFieldObj->AddValue(
196 Description => $v->Description,
197 SortOrder => $v->SortOrder
202 # because content changed, we must redo search for subsequent uses
203 $CustomFields->RedoSearch;
204 $CustomFields->GotoFirstItem;
208 # {{{ deal with deleting existing custom fields
209 foreach my $key (keys %ARGS) {
210 # {{{ if we're trying to delete the custom field
211 if ($key =~ /^DeleteCustomField-(\d+)/) {
213 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
214 $CustomFieldObj->Load($id);
215 my ($retval, $msg) = $CustomFieldObj->Delete;
217 push @actions, loc("Custom field deleted");
233 $CustomField => undef
234 $FindDisabledCustomFields => undef