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>
37 <TD ROWSPAN="<% $CustomFields->Count %>">
39 % while (my $CustomFieldObj = $CustomFields->Next) {
40 <LI><A HREF="CustomField.html?Queue=<%$id%>&CustomField=<%$CustomFieldObj->id()%>"><b><%$CustomFieldObj->Name%></b></a> (<% $CustomFieldObj->FriendlyType %>)<br>
41 <%$CustomFieldObj->Description%>
48 % while (my $CustomFieldObj = $CustomFields->Next) {
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>
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>
69 <FORM METHOD=GET ACTION="CustomFields.html">
71 <INPUT TYPE="Hidden" NAME="id" VALUE="<%$id%>">
73 <input type="checkbox" name="FindDisabledCustomFields"> <&|/l&>Include disabled custom fields in listing.</&>
74 <input type=submit value="<&|/l&>Go!</&>">
79 my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
80 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
88 $CustomFields->LimitToQueue($id);
91 $CustomFields->LimitToGlobal();
94 if ($FindDisabledCustomFields) {
95 $caption = loc("All Custom Fields");
96 $CustomFields->{'find_disabled_rows'} = 1;
98 $caption = loc("Enabled Custom Fields");
101 # {{{ deal with moving sortorder of custom fields
102 if ($CustomField and $Move) {
103 my $SourceObj = RT::CustomField->new($session{'CurrentUser'});
104 $SourceObj->Load($CustomField) || Abort(loc('No CustomField'));
107 my $target_order = $SourceObj->SortOrder + $Move;
108 while (my $CustomFieldObj = $CustomFields->Next) {
109 my $this_order = $CustomFieldObj->SortOrder;
111 # if we have an exact match, finish the loop now
112 ($TargetObj = $CustomFieldObj, last) if $this_order == $target_order;
114 # otherwise, we need to apropos toward the general direction
115 # ... first, check the sign is correct
116 next unless ($this_order - $SourceObj->SortOrder) * $Move > 0;
118 # ... next, see if we already have a candidate
120 # ... if yes, compare the delta and choose the smaller one
121 my $orig_delta = abs($TargetObj->SortOrder - $target_order);
122 my $this_delta = abs($this_order - $target_order);
123 next if $orig_delta < $this_delta;
126 $TargetObj = $CustomFieldObj;
130 # swap their sort order
131 my ($s, $t) = ($SourceObj->SortOrder, $TargetObj->SortOrder);
132 $TargetObj->SetSortOrder($s);
133 $SourceObj->SetSortOrder($t);
134 # because order changed, we must redo search for subsequent uses
135 $CustomFields->RedoSearch;
138 $CustomFields->GotoFirstItem;
142 # {{{ now process the 'copy queue' action
144 if ($Source and $Source ne $id) {
145 my $SourceQueue = RT::Queue->new($session{'CurrentUser'});
146 $SourceQueue->Load($Source) || Abort(loc("Couldn't load queue"));
147 my $SourceCustomFields = RT::CustomFields->new($session{'CurrentUser'});
148 $SourceCustomFields->LimitToQueue($SourceQueue->id);
151 foreach my $CustomFieldObj ( @{$CustomFields->ItemsArrayRef} ) {
152 $CustomFieldObj->Delete;
156 while (my $SourceCustomFieldObj = $SourceCustomFields->Next) {
157 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
158 my ($val, $msg) = $CustomFieldObj->Create(
159 id => $SourceCustomFieldObj->id,
161 Name => $SourceCustomFieldObj->Name,
162 Type => $SourceCustomFieldObj->Type,
163 Description => $SourceCustomFieldObj->Description,
165 Abort(loc("Could not create CustomField") . ": $msg") unless ($val);
168 $CustomFieldObj->SetSortOrder($SourceCustomFieldObj->SortOrder);
171 my $values = $SourceCustomFieldObj->Values();
172 while (my $v = $values->Next) {
173 my ( $addval, $addmsg ) = $CustomFieldObj->AddValue(
175 Description => $v->Description,
176 SortOrder => $v->SortOrder
181 # because content changed, we must redo search for subsequent uses
182 $CustomFields->RedoSearch;
183 $CustomFields->GotoFirstItem;
187 # {{{ deal with deleting existing custom fields
188 foreach my $key (keys %ARGS) {
189 # {{{ if we're trying to delete the custom field
190 if ($key =~ /^DeleteCustomField-(\d+)/) {
192 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
193 $CustomFieldObj->Load($id);
194 my ($retval, $msg) = $CustomFieldObj->Delete;
196 push @actions, loc("Custom field deleted");
212 $CustomField => undef
213 $FindDisabledCustomFields => undef