package WebGUI::Asset::Wobject::Carousel; $VERSION = "1.0.0"; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2008 Plain Black Corporation. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use strict; use JSON; use WebGUI::International; use Moose; use WebGUI::Definition::Asset; extends 'WebGUI::Asset::Wobject'; define assetName => [ 'assetName', 'Asset_Carousel' ]; define icon => 'Carousel.png'; define tableName => 'Carousel'; property templateId => ( fieldType => "template", default => 'CarouselTmpl0000000001', tab => "display", noFormPost => 0, namespace => "Carousel", hoverHelp => [ 'carousel template description', 'Asset_Carousel' ], label => [ 'carousel template label', 'Asset_Carousel' ], ); property slideWidth => ( fieldType => "integer", default => 0, tab => "display", hoverHelp => [ 'carousel slideWidth description', 'Asset_Carousel' ], label => [ 'carousel slideWidth label', 'Asset_Carousel' ], ); property slideHeight => ( fieldType => "integer", default => 0, tab => "display", hoverHelp => ['carousel slideHeight description', 'Asset_Carousel' ], label => ['carousel slideHeight label', 'Asset_Carousel' ], ); property items => ( noFormPost => 1, fieldType => 'text', ); property autoPlay => ( fieldType => 'yesNo', defaultValue => 0, tab => "properties", hoverHelp => ['carousel autoPlay description', 'Asset_Carousel' ], label => ['carousel autoPlay label', 'Asset_Carousel' ], ); property autoPlayInterval => ( fieldType => 'Integer', defaultValue => 4, tab => 'properties', hoverHelp => ['carousel autoPlayInterval description', 'Asset_Carousel'], label => ['carousel autoPlayInterval label', 'Asset_Carousel'], ); #------------------------------------------------------------------- =head2 getEditForm ( ) returns the tabform object that will be used in generating the edit page for New Wobjects. This method is optional if you set autoGenerateForms=1 in the definition. =cut override getEditForm => sub { my $self = shift; my $tabform = super(); my $i18n = WebGUI::International->new($self->session, "Asset_Carousel"); $self->session->style->setScript($self->session->url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type => 'text/javascript'}); $self->session->style->setScript($self->session->url->extras('yui/build/element/element-min.js'), {type => 'text/javascript'}); $self->session->style->setScript($self->session->url->extras('yui/build/tabview/tabview-min.js'), {type => 'text/javascript'}); $self->session->style->setScript($self->session->url->extras('yui/build/editor/editor-min.js'), {type => 'text/javascript'}); $self->session->style->setScript($self->session->url->extras('yui/build/json/json-min.js'), {type => 'text/javascript'}); $self->session->style->setLink($self->session->url->extras('yui/build/editor/assets/skins/sam/editor.css'), {type =>'text/css', rel=>'stylesheet'}); $self->session->style->setLink($self->session->url->extras('yui/build/tabview/assets/skins/sam/tabview.css'), {type =>'text/css', rel=>'stylesheet'}); $self->session->style->setScript($self->session->url->extras('wobject/Carousel/carousel.js'), {type => 'text/javascript'}); my $tableRowStart = '
'.$i18n->get("items description").'
' . ' ' . '
' . "
\n"; $tabform->getTab("properties")->addField('ReadOnly', value => $tableRowStart); if($self->items){ my @items = @{JSON->new->decode($self->items)->{items}}; foreach my $item (@items){ my $itemNr = $item->{sequenceNumber}; my $itemHTML = "
\n" ."\n" .$i18n->get("id label").'
'.$i18n->get("id description").'
: ' .'' ."
\n" ."\n" .'
\n"; $itemHTML .= " \n" ."
\n"; $tabform->getTab("properties")->addField('ReadOnly', value => $itemHTML); } } else{ my $itemHTML = "
\n" ."\n" .$i18n->get("id label").'
'.$i18n->get("id description").'
: ' .' ' ."
\n" ."\n" .'
\n"; $itemHTML .= "\n"; $tabform->getTab("properties")->addField('ReadOnly', value => $itemHTML); } $self->session->log->warn('richedit:' .$self->get('richEditor')); my $richEditId = $self->get('richEditor') || "PBrichedit000000000001"; my $richedit = WebGUI::Asset->newById( $self->session, $richEditId ); my $config = JSON->new->encode( $richedit->getConfig ); my $loadMcePlugins = $richedit->getLoadPlugins; my $items = $self->get('items') ? JSON->new->decode($self->get('items'))->{items} : []; $items = JSON->new->encode( $items ); my $i18nJson = JSON->new->encode( { "delete" => $i18n->get("delete") } ); $tabform->getTab('properties')->addField( "ReadOnly", name => 'editor', value => <<"ENDHTML");
ENDHTML return $tabform; }; #------------------------------------------------------------------- =head2 prepareView ( ) See WebGUI::Asset::prepareView() for details. =cut sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->newById($self->session, $self->templateId); if (!$template) { WebGUI::Error::ObjectNotFound::Template->throw( error => qq{Template not found}, templateId => $self->templateId, assetId => $self->getId, ); } $template->prepare; $self->{_viewTemplate} = $template; } #------------------------------------------------------------------- =head2 processEditForm ( ) Used to process properties from the form posted. =cut override processEditForm => sub { my $self = shift; my $form = $self->session->form; super(); my $items = JSON->new->decode( $form->get("items") ); $self->update({ items => JSON->new->encode({ items => $items }) }); return undef; }; #------------------------------------------------------------------- =head2 view ( ) method called by the www_view method. Returns a processed template to be displayed within the page style. =cut sub view { my $self = shift; my $session = $self->session; my (@item_loop); #This automatically creates template variables for all of your wobject's properties. my $var = $self->get; if($self->items){ $var->{item_loop} = JSON->new->decode($self->items)->{items}; } #This is an example of debugging code to help you diagnose problems. #WebGUI::ErrorHandler::warn($self->get("templateId")); return $self->processTemplate($var, undef, $self->{_viewTemplate}); } __PACKAGE__->meta->make_immutable; 1; #vim:ft=perl