# 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: ExtURL.pm 3043 2008-03-31 14:00:38Z josh $

package BigMed::ExtURL;
use strict;
use utf8;
use Carp;
use base qw(BigMed::URL);


my @data_schema = (
    {   name  => 'link_to',
        type  => 'value_list',
        options => ['page', 'url'],
        labels  => {
            url => 'LINK_Link to url',
            page     => "LINK_Link to page",
        },
        default   => 'url',
    },
);

BigMed::ExtURL->register_minicontent(
    elements => \@data_schema,
    editor_fields => [
        { column => 'text', required => 1, },
        { column => 'url', required => 1  },
        { column => 'link_to' },
        { column => 'new_win' },
    ],
    preview => { html => \&preview_html },
);

sub preview_html {
    my ( $app, $obj, $roptions ) = @_;
    my $url  = $obj->url;
    my $text = $obj->text;
    my $html = $app->html_template(
        'wi_exturl_preview.tmpl',
        URL       => $url,
        TEXT      => $text,
        PUBSTATUS => $url,
    );
    my $window = $obj->new_win || 'default';
    $window =
        $window eq 'yes' ? $app->language('Yes')
      : $window eq 'no'  ? $app->language('No')
      : $app->language('BM_Default');
    my $link_to = $obj->link_to || 'url';
    return (
        PREVIEW_HTML => $html,
        STATUS_HTML => $app->language( 'LINK_Link to ' . $link_to ) . '; '
          . $app->language('url:new_win')
          . ": $window"
    );
}


1;


=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
