#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Support::JobQueue::Command::SaveHostClasses;
use strict;
use warnings;

use Data::Dumper;

use lib '/app/tools/support/lib';
use Support::JobQueue::SkipRuleForm;
use Support::JobQueue::RunRuleForm;
use Support::JobQueue::HostClassForm;
use Support::JobQueue::Command::EditRules;

use base 'Support::Command::Submit';

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

use lib '/app/tools/job/lib';

sub cmd  { return 'host_class'; }
sub area { return 'job_queue'; }

use constant kTemplate => "/app/tools/support/templates/job_queue/editrules.xsl";

sub write_command { 1; }

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

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

    my $hostname = $self->getParam('host');
    my $form = Support::JobQueue::HostClassForm->new( hostname => $hostname );

    my $msg;
    if ( $form->assignCGIParams( 'HostClassForm', $self->getParams() ) && $form->validate() ) {
        $form->save();
        $msg = RSApache::Message->new( type => "success", code => Common::FormObject::kSuccessFormSubmit );
    } else {
        $msg = RSApache::Message->new( type => "error", code => Common::FormObject::kErrFormSubmit );
    }
    my %showParams = (
        msg  => $msg->toString(),
        host => $hostname,
    );

    my $command = Support::JobQueue::Command::EditRules->new(%showParams);
    return RSApache::Response::Redirect->new( $command->getRedirect() );
}

1;
