%# Hoare's Law of Large Problems: %# Inside every large problem is a small problem struggling to get out. <& /Edit/Elements/104Header, Buttons => [ Add => "?Queue=$Queue&Action-Add=1", Save => ($Scrip ? "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 => '../Scrip/' &>
% }
<& Top, Item => $Item, List => $List, Queue => $Queue &>
<& List, Delete => 1, List => $List, Begin => $Begin, Item => $Item, ARGS => \%ARGS &>

<%INIT> my $List = []; my $Item = $RT::Nothing; my $Scrips = RT::Scrips->new($session{'CurrentUser'}); my $QueueObj = RT::Queue->new($session{'CurrentUser'}); my @actions; if ($Queue) { $QueueObj->Load($Queue); } if ($QueueObj->id) { $Scrips->LimitToQueue($Queue); } else { $Scrips->LimitToGlobal(); } if ($Scrip) { $Item = RT::Scrip->new($session{'CurrentUser'}); $Item->Load( $Scrip ); } if ($Action eq 'Save' and $r->method eq 'POST') { if (my $key = $ARGS{ScripActionProcedure} and $ARGS{UserScripAction} < 0) { $ARGS{UserScripAction} = -$ARGS{UserScripAction}; $ARGS{CustomPrepareCode} = "1; # procedure $key"; $ARGS{CustomCommitCode} = << "." my \$ticket = \$self->TicketObj; \$ticket->FirstRequestor->call_sp('$key', [], \$ticket); . } $ARGS{ScripCondition} = $ARGS{UserScripCondition} if $ARGS{UserScripCondition}; $ARGS{ScripAction} = $ARGS{UserScripAction} if $ARGS{UserScripAction}; foreach my $key (qw( ScripAction ScripCondition Stage Template Description CustomPrepareCode CustomCommitCode CustomIsApplicableCode )) { my $method = "Set$key"; $Item->$method($ARGS{$key}) if exists $ARGS{$key}; } } elsif ($Action eq 'Add') { $Item = RT::Scrip->new($session{'CurrentUser'}); my ($val, $msg) = $Item->Create( Queue => $Queue, Description => loc('(new)'), ScripAction => 'Autoreply To Requestors', ScripCondition => 'On Create', Template => 'Blank', CustomPrepareCode => '', CustomCommitCode => '', CustomIsApplicableCode => '', ); Abort($msg) unless ($val); $Scrip = $Item->id; $Begin = -1; } elsif ($Action eq 'Delete') { foreach my $Id (@ListDelete) { my $item = RT::Scrip->new($session{'CurrentUser'}); $item->Load( $Id ); $item->Delete; } $Scrips->RedoSearch; $Item = $Scrips->First || $RT::Nothing; $Begin = $Scrip = 0; } else { undef $Action; } $m->redirect("?Queue=$Queue&Scrip=$Scrip&Begin=$Begin") if $Action; $List = $Scrips->ItemsArrayRef; $Begin = int($#$List / 8) * 8 if $Begin == -1; <%ARGS> $Begin => 0 $Scrip => undef $Queue => 0 $Action => '' @ListDelete => ()