#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Label::Form;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Assert;
use Common::Log;

use lib '/app/tools/rps/lib';
use RPS::ArtistContract::ArtistContractList;
use RPS::Label::LabelWithUsers;
use RPS::Label::UserList;
use RPS::CountryList;
use RPS::StateList;
use RPS::RoyaltyRun::RoyaltyRunStatusList;

use Common::FormObject;
use base 'Common::FormObject';

sub _init {
    my ( $self, %args ) = @_;

    $self->SUPER::_init(%args);

    if ( $args{labelID} ) {

        # !!! The 'LabelWithUsers' class contains all the user data, which we don't need.
        # !!! All we really need is an array that contains the user ids.
        # !!! Might need to re-wrte that class to work in that fashion.
        #
        $self->{Label} = RPS::Label::LabelWithUsers->new( labelID => $args{labelID} );
    } else {
        $self->{Label} = RPS::Label::LabelWithUsers->new();
    }

    # Extending this to allow the list of Label Users to be manipulated.
    # What we need to produce here is a list of all label users, and a list of
    # those users that are already attached to this Label.
    #
    # !!! This interface is very similar to the new Labels interface on the User/Edit page.
    #
    $self->{UserList} = RPS::Label::UserList->new( all => 1 );

    $self->{RoyaltyRunStatus} = new RPS::RoyaltyRun::RoyaltyRunStatusList( label => 1 );
    return $self;
}

# The form won't bother sending any UserID cgi parameters if the select list is empty.
# This means that if you try and delete all the existing users from a label, nothing happens.
# So this override is essentially a hack to force the user id list to be blank when we're
# reading in cgi parameters.
#
sub assignCGIParams {
    my ( $self, $baseName, $cgiParams ) = @_;

    $self->{Label}->UserID( [] );
    return $self->SUPER::assignCGIParams( $baseName, $cgiParams );
}

#sub _propertyIsEditable
#{
#    my ($self, $propertyName) = @_;
#
#    if ($propertyName eq 'Label')
#    {
#        return 1;
#    }
#
#    return 0;
#}

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

    Common::Log::Print( "In save, label= ", $self->{Label} );
    $self->{Label}->save();
}

#sub validate
#{
#    my ($self) = @_;
#
#    return $self->{Label}->validate();
#}

sub labelID {
    my ($self) = @_;
    return $self->{Label}->LabelID();
}

###
1;    #
###
