#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#---------------------------------------------------------------
package BookPub::Catalog::EditChapterForm;

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

use lib '/app/tools/bookpub/lib';
use BookPub::Catalog::Chapter::Extended;
use BookPub::Catalog::Book::FullDisplay;

use BookPub::Catalog::ImprintList;
use BookPub::Catalog::ContributorRoleList;
use BookPub::Catalog::AudienceCodeList;

use base 'Common::FormObject';

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

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

    my $chapterID = $args{chapterID};
    my $chapter;
    my $bookID;
    if ($chapterID) {
        $chapter = BookPub::Catalog::Chapter::Extended->new( chapterID => $chapterID );
        $bookID = $chapter->BookID();
    } else {
        $bookID  = $args{bookID};
        $chapter = BookPub::Catalog::Chapter::Extended->new();
        $chapter->BookID($bookID);
    }

    my $book = BookPub::Catalog::Book::FullDisplay->new( bookID => $bookID );

    $self->{Chapter} = $chapter;
    $self->{Book}    = $book;

    $self->{ImprintList}         = BookPub::Catalog::ImprintList->new();
    $self->{ContributorRoleList} = BookPub::Catalog::ContributorRoleList->new();

    $self->{AudienceCodeList} = BookPub::Catalog::AudienceCodeList->new();

    return $self;
}

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

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

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

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

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

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

###
1;    #
###
