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

use lib '/app/tools/rps/lib';
use RPS::Alert;
use RPS::Command;
use RPS::Dashboard::Form;
use RPS::Dashboard::Command::Show;
use base 'RPS::Command';

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

sub cmd  { return 'delete_alert'; }
sub area { return 'dashboard'; }

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

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

    my $alertObj = RPS::Alert->GetCurrentAlert();

    # No matter what happens, we redirect back to the Show command.
    # Only the message will change.
    my $message;
    if ( $alertObj && $alertObj->delete() ) {

        # 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 {
        my $message = RPS::Message->new( type => "error", code => Common::FormObject::kErrFormSubmit );
    }

    my $command = RPS::Dashboard::Command::Show->new( msg => $message->toString() );
    return RSApache::Response::Redirect->new( $command->getRedirect() );
}

1;
