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

use lib '/app/tools/common/lib';
use Common::Assert;
use lib '/app/tools/bookpub/lib';
use BookPub::DB::Item::Book;
use BookPub::Catalog::Book;

use base 'Common::FormObject::List::NumericPaged::WithAlphaIndex';

use constant kDefaultPageSize  => 30;
use constant kDefaultNavSpread => 9;

sub _itemName { return 'Book'; }

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

    # Rather than have a zillion different BookList subclasses that differ in
    # how their _collection_ is constructed, we'll require that these lists are
    # constructed by passing in a DB::ItemCollection reference.
    #
    # Indeed, it makes sense to me to force _all_ FormObject::List classes to work this way,
    # but for now we'll try it out here.
    #
    assert( $args{collection}, "You _must_ provide a DB::ItemCollection of 'Book' objects" );
    $self->{_collection}    = $args{collection};
    $self->{_imprintID}     = $args{imprintID};
    $self->{_contributorID} = $args{contributorID};

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

sub _getAlphaIndex {
    my ( $self, $pageSize ) = @_;
    assert($pageSize);
    return BookPub::DB::Item::Book->GetTitleAlphaIndex($pageSize);
}

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

    return $self->{_collection};

    #    my $collection = BookPub::DB::Item::Book->GetAllSortedByTitle();
    #    return $collection;

}

sub _getObj {
    my ( $self, $dbItem ) = @_;
    assert($dbItem);

    return BookPub::Catalog::Book->new( dbItem => $dbItem, readOnly => 1 );
}

1;
