# Copyright 2002-2008 Josh Clark and Global Moxie, LLC. This code cannot be 
# redistributed without permission from globalmoxie.com.  For more
# information, consult your Big Medium license.
#
# $Id: Pullquote.pm 3113 2008-06-16 16:23:25Z josh $

package BigMed::Pullquote;
use strict;
use utf8;
use Carp;

use base qw(BigMed::MiniContent);
use BigMed::Filter;


my @data_schema = (
    {   name  => 'page',
        type  => 'system_id',
        index => 1,
    },
    {   name  => 'text',
        type  => 'rich_text_brief',
        index => 1,
    },
    {   name    => 'position',
        type    => 'body_position',
        default => 'block:1',
    },
    {   name    => 'align',
        type    => 'raw_text',
        options => ['default', 'left', 'center', 'right'],
        default => 'default',
    },
    {   name    => 'size',
        type    => 'raw_text',
        options => ['big', 'small'],
        default => 'big',
    },
);

my @editor_fields = (
    {   column   => 'text',
        required => 1,
    },
    {   column    => 'position',
        required  => 1,
    },
    {   column    => 'align',
        prompt_as => 'alignment',
        required  => 1,
    },
    {   column    => 'size',
        prompt_as => 'big_small_text',
        required  => 1,
    },
);

BigMed::Pullquote->register_minicontent(
    source        => 'pullquote',
    label         => 'pullquote',
    elements      => \@data_schema,
    editor_fields => \@editor_fields,
    preview       => { html => \&preview_html },
    can_embed     => 1,
);

sub preview_html {
    my ( $app, $obj, $roptions ) = @_;
    my $text = BigMed::Filter->filter( $obj->text );
    my $safetext = $obj->sanitize_preview_html($app, $text);
    my $size = $text eq $safetext ? ( $obj->size || 'big' ) : 'small';
    my $main_html = $app->html_template(
        'wi_pullquote_preview.tmpl',
        PULLQUOTE => $safetext,
        SIZE      => $size,
    );
    my $text_pos    = $obj->text_position_lang( $obj->position );
    my $align       = $obj->text_align_lang( $obj->align );
    my $status_html =
      $app->language($align) . " " . $app->language($text_pos);
    ( PREVIEW_HTML => $main_html, STATUS_HTML => $status_html );
}

1;

=head1 NAME

BigMed::Pullquote - Big Medium pullquote object

=head1 DESCRIPTION

A BigMed::Pullquote object holds the text content of a single pullquote
element for a single page.

=head1 USAGE

BigMed::Pullquote is a subclass of BigMed::Data. In addition to the methods 
documented below, please see the BigMed::Data documentation for details about
topics including:

=over 4

=item Creating a new data object

=item Saving a data object

=item Finding and sorting saved data objects

=item Data access methods

=item Error handling

=back

=head1 METHODS

=head2 Data Access Methods

BigMed::Pullquote objects hold the following pieces of data. They can be
accessed and set using the standard data access methods described in the
BigMed::Data documentation. See the L<"Searching and Sorting"> section below
for details on the data columns available to search and sort BigMed::Site
objects.

=over 4

=item * id

The numeric ID of the pullquote object

=item * site

The numeric ID of the site to which the object belongs

=item * page

The numeric ID of the BigMed::Page object to which the pullquote belongs

=item * position

One of three values: 'above', 'below', 'bn'. 'above' places the pullquote
above the content. 'below' places the pullquote below the content.  'bn'
aligns the pullquote at the nth HTML block element (e.g., b1, b2, b3).

=item * priority

Positive integer indicating the order in which the pullquote should be displayed
relative to other pullquotes at the same position in the content.

=item * align

The alignment of the pullquote within the content. Must be one of three values:
'left', 'right', 'center'

=item * size

The size of the pullquote text: 'big' or 'small'

=item * mod_time

Timestamp for when the last time the object was saved.

=item * create_time

Timestamp for when the object was first created.

=back

=head3 Searching and Sorting

You can look up and sort records by any combination of the following fields.
See the C<fetch> and C<select> documentation in BigMed::Data for more info.

=over 4

=item * id

=item * mod_time

=item * site

=item * source_table

=item * source_id

=item * target_table

=item * target_id

=item * type

=back

=head1 SEE ALSO

=over 4

=item * BigMed::Data

=item * BigMed::Page

=back

=head1 AUTHOR & COPYRIGHTS

This module and all Big Medium modules are copyright Josh Clark
and Global Moxie. All rights reserved.

Use of this module and the Big Medium content
management system are governed by Global Moxie's software licenses
and may not be used outside of the terms and conditions outlined
there.

For more information, visit the Global Moxie website at
L<http://globalmoxie.com/>.

Big Medium and Global Moxie are service marks of Global Moxie
and Josh Clark. All rights reserved.

=cut


