#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Admin::JobQueue::Command::QueueAjax;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use RSApache::Command::XMLCommand;
use RSApache::Message;
use Common::Client::ClientList;

use lib '/app/tools/admin/lib';
use Admin::Permission::Form;
use Admin::Command;

# !!! The theory here is to use a command that does not redirect to login
# !!! if the session is invalid.
#
use base 'RSApache::Command::XMLCommand';

use lib '/app/tools/job/lib';
use Job::Queue;

use Data::Dumper;

use constant kTemplate => '/app/tools/admin/templates/jobqueue/getqueue.xsl';

sub cmd  { return "getqueue"; }
sub area { return "jobqueue"; }

sub execute {
    my ($self) = @_;

    # Give any inherited methods the first crack at this.
    # (This checks for login and basic access permissions).
    #
    my $response = $self->SUPER::execute();
    return $response if $response;

    my $maxJobAge = $self->getParam('age');

    # !!! We may revisit this in the future, but for now I am going to assume
    # !!! that we will just be rendering this as html.
    #
    $self->{xml}{JobQueue} = Job::Queue->new( maxAge => $maxJobAge );

    $self->{xml}{ClientList} = Common::Client::ClientList->new();
    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );

    return $response;
}

1;

