#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::Catalog::EditBookForm;

use strict;
use warnings;
use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tools/bookpub/lib';
use BookPub::Catalog::Book::Extended;
use BookPub::Catalog::AudienceCodeList;
use BookPub::Catalog::ContributorRoleList::ForBook;

use base 'Common::FormObject';

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

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

    my $book;
    if ( $args{bookID} ) {
        $book = BookPub::Catalog::Book::Extended->new( bookID => $args{bookID} );
    } else {
        $book = BookPub::Catalog::Book::Extended->new();
    }
    $self->{Book}                = $book;
    $self->{AudienceCodeList}    = BookPub::Catalog::AudienceCodeList->new();
    $self->{ContributorRoleList} = BookPub::Catalog::ContributorRoleList::ForBook->new();

    return $self;
}

sub _propertyIsEditable {
    my ( $self, $propertyName ) = @_;

    # The Product (and contained objects) can be edited.

    return 1 if ( $propertyName eq 'Book' );
    return 0;
}

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

    return $self->{Book}->validate(%args);
}

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

    $self->{Book}->save();
}

###
1;    #
###
