3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 %# (Except where explictly superceded by other copyright notices)
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 %# General Public License for more details.
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
24 <& /Elements/ListActions, actions => \@actions &>
31 % if ($CustomFields->Count == 0 ) {
32 <P><i><&|/l&>(No custom fields)</&></i></P>
34 <TABLE cellspacing=0 cellpadding=2>
36 % while (my $CustomFieldObj = $CustomFields->Next) {
39 % if ($CustomFieldObj->Name) {
40 <A HREF="CustomField.html?Queue=<%$id%>&CustomField=<%$CustomFieldObj->id()%>"><b><%$CustomFieldObj->Name%></b></a><br>
42 <A HREF="CustomField.html?Queue=<%$id%>&CustomField=<%$CustomFieldObj->id()%>"><i>(<%loc("no name")%>)</i></a><br>
44 <%$CustomFieldObj->Description%>
47 <i><% $CustomFieldObj->FriendlyType %></i>
49 % # show 'move up' unless it's the first item
52 <a href="CustomFields.html?id=<%$id%>&CustomField=<%$CustomFieldObj->id%>&Move=-1"><&|/l&>Move up</&></a>
54 <TD valign="TOP" ALIGN=RIGHT>
57 % # show 'move down' unless it's the last item
58 % if (!$CustomFields->IsLast) {
59 % $m->print(' | ') if $count > 1;
60 <a href="CustomFields.html?id=<%$id%>&CustomField=<%$CustomFieldObj->id%>&Move=1"><&|/l&>Move down</&></a>
68 <FORM METHOD=GET ACTION="CustomFields.html">
70 <INPUT TYPE="Hidden" NAME="id" VALUE="<%$id%>">
72 <input type="checkbox" name="FindDisabledCustomFields"> <&|/l&>Include disabled custom fields in listing.</&>
73 <input type=submit value="<&|/l&>Go!</&>">
78 my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
79 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
87 $CustomFields->LimitToQueue($id);
90 $CustomFields->LimitToGlobal();
93 if ($FindDisabledCustomFields) {
94 $caption = loc("All Custom Fields");
95 $CustomFields->{'find_disabled_rows'} = 1;
97 $caption = loc("Enabled Custom Fields");
100 # {{{ deal with moving sortorder of custom fields
101 if ($CustomField and $Move) {
102 my $SourceObj = RT::CustomField->new($session{'CurrentUser'});
103 $SourceObj->Load($CustomField) || Abort(loc('No CustomField'));
106 my $target_order = $SourceObj->SortOrder + $Move;
107 while (my $CustomFieldObj = $CustomFields->Next) {
108 my $this_order = $CustomFieldObj->SortOrder;
110 # if we have an exact match, finish the loop now
111 ($TargetObj = $CustomFieldObj, last) if $this_order == $target_order;
113 # otherwise, we need to apropos toward the general direction
114 # ... first, check the sign is correct
115 next unless ($this_order - $SourceObj->SortOrder) * $Move > 0;
117 # ... next, see if we already have a candidate
119 # ... if yes, compare the delta and choose the smaller one
120 my $orig_delta = abs($TargetObj->SortOrder - $target_order);
121 my $this_delta = abs($this_order - $target_order);
122 next if $orig_delta < $this_delta;
125 $TargetObj = $CustomFieldObj;
129 # swap their sort order
130 my ($s, $t) = ($SourceObj->SortOrder, $TargetObj->SortOrder);
131 $TargetObj->SetSortOrder($s);
132 $SourceObj->SetSortOrder($t);
133 # because order changed, we must redo search for subsequent uses
134 $CustomFields->RedoSearch;
137 $CustomFields->GotoFirstItem;
141 # {{{ now process the 'copy queue' action
143 if ($Source and $Source ne $id) {
144 my $SourceQueue = RT::Queue->new($session{'CurrentUser'});
145 $SourceQueue->Load($Source) || Abort(loc("Couldn't load queue"));
146 my $SourceCustomFields = RT::CustomFields->new($session{'CurrentUser'});
147 $SourceCustomFields->LimitToQueue($SourceQueue->id);
150 foreach my $CustomFieldObj ( @{$CustomFields->ItemsArrayRef} ) {
151 $CustomFieldObj->Delete;
155 while (my $SourceCustomFieldObj = $SourceCustomFields->Next) {
156 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
157 my ($val, $msg) = $CustomFieldObj->Create(
158 id => $SourceCustomFieldObj->id,
160 Name => $SourceCustomFieldObj->Name,
161 Type => $SourceCustomFieldObj->Type,
162 Description => $SourceCustomFieldObj->Description,
164 Abort(loc("Could not create CustomField") . ": $msg") unless ($val);
167 $CustomFieldObj->SetSortOrder($SourceCustomFieldObj->SortOrder);
170 my $values = $SourceCustomFieldObj->Values();
171 while (my $v = $values->Next) {
172 my ( $addval, $addmsg ) = $CustomFieldObj->AddValue(
174 Description => $v->Description,
175 SortOrder => $v->SortOrder
180 # because content changed, we must redo search for subsequent uses
181 $CustomFields->RedoSearch;
182 $CustomFields->GotoFirstItem;
186 # {{{ deal with deleting existing custom fields
187 foreach my $key (keys %ARGS) {
188 # {{{ if we're trying to delete the custom field
189 if ($key =~ /^DeleteCustomField-(\d+)/) {
191 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
192 $CustomFieldObj->Load($id);
193 my ($retval, $msg) = $CustomFieldObj->Delete;
195 push @actions, loc("Custom field deleted");
211 $CustomField => undef
212 $FindDisabledCustomFields => undef