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

use lib '/app/tools/rps/lib';
use RPS::Label::Form;
use RPS::Label::Command::List;
use RPS::Command;
use base 'RPS::Command';

use lib '/app/tools/common/lib';
use Common::FormObject;
use RSApache::Response::XML;
use RSApache::Response::XSLT;
use RSApache::Response::Redirect;

sub cmd  { return 'set_default'; }
sub area { return 'label'; }

use constant kTemplate => "/app/tools/rps/templates/label/index.xsl";

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

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

	my $labelID = $self->getParam('LabelID');
    my $labelObj = RPS::Label::Label->new(labelID => $labelID);

    my $message;
    if ($labelObj->makeDefault())
    {
        # We want to change views, so we want to redirect to the Show command now.
		#
		$message = RPS::Message->new(type => "success", code => Common::FormObject::kSuccessFormSubmit);
	}
	else
	{
		$message = RPS::Message->new(type => "error", code => Common::FormObject::kErrFormSubmit);
	}

    my %showParams = (
        msg => $message->toString(),
    );
    my $command = RPS::Label::Command::List->new(%showParams);
    return RSApache::Response::Redirect->new($command->getRedirect());
}


1;
