%# BEGIN LICENSE BLOCK
%# 
%# Copyright (c) 1996-2002 Jesse Vincent <jesse@bestpractical.com>
%# 
%# (Except where explictly superceded by other copyright notices)
%# 
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org
%# 
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%# 
%# 
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%# 
%# 
%# END LICENSE BLOCK

% if( $ShowStatusesSelector ) {
%   foreach my $s ( $QueueObj->Lifecycle->Valid ) {
%       my $checked = (grep { $_ eq $s } @Statuses)? 'checked': '';
<input type="checkbox" name="Statuses" value="<% $s %>" <% $checked %> />&nbsp;<% $s %>
%   }
<& /Elements/Submit, Name => 'RefineStatus', Label => loc('Filter status') &>
% }

% if ( $Delete && $children->Count ) {
<i><% loc("Check box to unlink") %></i><br />
% }
<& /Elements/TicketList, 
   Collection     => $children,
   DisplayFormat  => ($Delete? "__CheckBox__, $Format": $Format),
   Format         => $Format,
   Rows           => $Rows,
   ShowHeader     => $ShowHeader,
   OrderBy        => $OrderBy,
   ShowNavigation => 0,
&>
% unless( $children->Count ) {
%   if ( $NoTicketsCaption ) {
        <i>(<% $NoTicketsCaption %>)</i>
%   } elsif ( $Queue ) {
        <i>(<% loc("no [_1]", $Queue) %>)</i>
%   } else {
        <i>(<% loc("no children") %>)</i>
%   }
% }
<br />

% if( $FullList && $Rows > 0 && $children->CountAll >= $Rows ) {
<a href="<% $FullList %>"><i><% loc("More... ([_1] total)", $children->CountAll) %></i></a><br />
% }

<%INIT>

my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
$QueueObj->Load( $Queue );
unless ( $QueueObj->id ) {
    RT->Logger->error("Couldn't load queue '$Queue'");
    return;
}

@Statuses = $QueueObj->Lifecycle->Valid('initial', 'active') unless @Statuses;

my $Type = RT::IR::TicketType( Queue => $Queue );

$Format ||= RT->Config->Get('RTIRSearchResultFormats')->{'Child' . $Type};

my $children = RT::Tickets->new( $session{'CurrentUser'} );
$children->FromSQL( RT::IR->Query(
    Queue    => $Queue,
    MemberOf => $Ticket,
    Status   => [@Statuses],
));

</%INIT>

<%ARGS>
$Format => undef
$Queue => undef
$Ticket => undef
$OrderBy => 'Due'
$Rows => 0

$Delete => 0
$FullList => undef
$NoTicketsCaption => undef,

@Statuses => ()

$ShowHeader => 0
$ShowStatusesSelector => 0
</%ARGS>
