%# Zounds! I was never so bethumped with words %# since I first called my brother's father dad. %# -- William Shakespeare, "King John" <& /Edit/Elements/104Header, Buttons => [ Add => "?Queue=$Queue&Action-Add=1", Save => ($CF ? "javascript:document.getElementById('mainform').submit()" : ''), Delete => 1, Copy => '', Search => '', ], Method => 'Post', &> % if ($Queue) { $m->print($m->content) } else {

<& /Edit/Elements/Tab, Text => 'Global' &>
<& /Edit/Elements/Tabs, Map => $ARGS{Map}, URL => '../CustomField/' &>
% } % my $InfoHTML = $m->scomp('Info', Begin => $Begin, CF => $CF, Item => $Item, Value => $Value, Action => $Action, Queue => $Queue, ARGS => \%ARGS);
<& Top, Item => $Item, List => $List &>
<& List, Delete => 1, List => $List, Begin => $Begin, Item => $Item, ARGS => \%ARGS &>
| % $m->print($InfoHTML);

<%INIT> my $List = []; my $Item = $RT::Nothing; my $SubItem = $RT::Nothing; my $CustomFields = RT::CustomFields->new($session{'CurrentUser'}); my $QueueObj = RT::Queue->new($session{'CurrentUser'}); $QueueObj->Load($Queue) if $Queue; if ($QueueObj->id) { $CustomFields->LimitToQueue($Queue); } else { $CustomFields->LimitToGlobal; } if ($CF) { $Item = RT::CustomField->new($session{'CurrentUser'}); $Item->Load( $CF ); } if ($Action eq 'Save' and $r->method eq 'POST') { $Item->SetType($ARGS{Type}) if exists $ARGS{Type}; $Item->SetName($ARGS{Name}) if exists $ARGS{Name}; $Item->SetDescription($ARGS{Description}) if exists $ARGS{Description}; foreach my $attr (qw(HTMLAttr Hints Pattern Default OnCreate OnUpdate)) { $Item->SetAttribute( $attr => $ARGS{$attr}) if exists $ARGS{$attr}; } } elsif ($Action eq 'Add') { $Item = RT::CustomField->new($session{'CurrentUser'}); my ($val, $msg) = $Item->Create( Queue => ($Queue || 0), Name => loc('(new)'), Type => 'FreeformSingle', Description => '', ); Abort(loc("Could not create CustomField", $msg)) unless ($val); $Item->SetSortOrder($Item->id); $CF = $Item->id; $Begin = -1; } elsif ($Action eq 'Delete') { foreach my $Id (@ListDelete) { my $item = RT::CustomField->new($session{'CurrentUser'}); $item->Load( $Id ); $item->Delete; } $CustomFields->RedoSearch; $Item = $CustomFields->First || $RT::Nothing; $Begin = $CF = 0; } elsif ($Action =~ /^(Up|Down)(Most)?$/) { my ($Direction, $Loop) = ($1, $2); foreach my $i (0..$CustomFields->Count) { $m->comp( '/Edit/Elements/MoveCustomField', Item => $Item, Direction => $Direction, CustomFields => $CustomFields, ) or last; last if !$Loop; } } elsif ($Action eq 'ValueAdd') { $Item->AddValue( Name => '(new)', Description => '', SortOrder => $Item->Values->Count + 1, ); $Value = $Item->Values->Last->id; } elsif ($Action eq 'ValueDelete' and $Value) { $Item->DeleteValue( $Value ); } elsif ($Action =~ /^Value/ and $Value) { $m->scomp( '/Edit/Elements/UpdateCustomFieldValue', Item => $Item, Action => $Action, Value => $Value, ValueName => $ValueName, ValueDescription => $ValueDescription, ); } else { undef $Action; } $m->redirect("?Queue=$Queue&CF=$CF&Begin=$Begin&Value=$Value") if $Action; $List = $CustomFields->ItemsArrayRef; $Begin = int($#$List / 16) * 16 if $Begin == -1; <%ARGS> $Begin => 0 $CF => undef $Value => undef $ValueName => undef $ValueDescription => undef $Queue => 0 $Action => '' @ListDelete => ()