#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Catalog::Command::ShowContracts;
use strict;
use warnings;

use lib '/app/tools/rps/lib';
use RPS::Catalog::ContractForm;
use RPS::DB::Item::MechanicalRun;
use RPS::DB::Item::CAMechanicalRun;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use RSApache::Command::XMLCommand;
use RSApache::Response::JSON;

use base 'RSApache::Command::XMLCommand';

sub cmd  { return 'show_contracts'; }
sub area { return 'catalog'; }

use constant kTemplate => "/app/tools/rps/templates/catalog/ajax_contracts.xsl";

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

    my $response = $self->SUPER::execute();
    return $response if $response;

    my $albumID    = $self->getParam("AlbumID");
    my $simplified = $self->getParam("simplified") || 0;

    my $justCountFlag = $self->getParam('count');

    if ($justCountFlag) {
        my $count = RPS::Catalog::ContractForm::GetNumContracts($albumID);
        $response = RSApache::Response::JSON->new($count);
    } else {
        my $form = RPS::Catalog::ContractForm->new( albumID => $albumID, simplified => $simplified );
        $self->{xml}{Form} = $form;

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

    return $response;
}

1;
