Solstice::View::FormInput::TextArea - A view of an html <textarea> element


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::View::FormInput::TextArea - A view of an html <textarea> element

SYNOPSIS

Top

    use Solstice::View::FormInput::TextArea;

    my $content = 'A string containing <i>content</i>.';

    my $view = Solstice::View::FormInput::TextArea->new($content);
    $view->setName('mytextbox');
    $view->setWidth('90%');  # a percentage or an integer representing pixels
    $view->setHeight(450);   # a percentage or an integer representing pixels
    $view->setIsResizable(1);

DESCRIPTION

Top

Superclass

Solstice::View::FormInput (Solstice::View::FormInput)

Export

No symbols exported.

Methods

setWidth($int)
getWidth()
setHeight($int)
getHeight()
setIsResizable($bool)
getIsResizable()
setFocusEditor($bool)
getFocusEditor()
setConfigPath($str)
getConfigPath()
setSkinPath($str)
getSkinPath()
setPluginsPath($str)
getPluginsPath()
setToolbarSet($str)
getToolbarSet()
generateParams()
generateRTESwitchParams()

Generate params for buttons to allow switching between plain text and RTE text areas. This is used by subclasses that support a RTE.

isRichTextEnabled()

Determines if user is seeing plaintext or rte editor, depending on an application-level preference.

Modules Used

Solstice::View.

AUTHOR

Top

Solstice Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 63 $

SEE ALSO

Top

perl.

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::View::FormInput::TextArea;

# $Id: TextArea.pm 63 2006-06-19 22:51:42Z jlaney $

use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::View::FormInput);

use Solstice::NamespaceService;
use Solstice::PreferenceService;
use Solstice::StringLibrary qw(unrender);

use constant TRUE  => 1;
use constant FALSE => 0;
use constant WIDTH  => '100%';
use constant HEIGHT => '250';

our $template = 'form_input/textarea.html';

our ($VERSION) = ('$Revision: 63 $' =~ /^\$Revision:\s*([\d.]*)/);

sub new {
    my $class = shift;
    my $self = $class->SUPER::new(@_);

    $self->_setTemplatePath('templates');

    return $self;
}

sub setWidth {
    my $self = shift;
    $self->{'_width'} = shift;
}

sub getWidth {
    my $self = shift;
    return $self->{'_width'};
}

sub setHeight {
    my $self = shift;
    $self->{'_height'} = shift;
}

sub getHeight {
    my $self = shift;
    return $self->{'_height'};
}

sub setIsResizable {
    my $self = shift;
    $self->{'_is_resizable'} = shift;
}

sub getIsResizable {
    my $self = shift;
    return $self->{'_is_resizable'};
}

sub setFocusEditor {
    my $self = shift;
    $self->{'_focus_editor'} = shift;
}

sub getFocusEditor {
    my $self = shift;
    return $self->{'_focus_editor'};
}

sub setConfigPath {
    my $self = shift;
    $self->{'_config_path'} = shift;
}

sub getConfigPath {
    my $self = shift;
    return $self->{'_config_path'};
}

sub setSkinPath {
    my $self = shift;
    $self->{'_skin_path'} = shift;
}

sub getSkinPath {
    my $self = shift;
    return $self->{'_skin_path'};
}

sub setPluginsPath {
    my $self = shift;
    $self->{'_plugins_path'} = shift;
}

sub getPluginsPath {
    my $self = shift;
    return $self->{'_plugins_path'};
}

sub setToolbarSet {
    my $self = shift;
    $self->{'_toolbar_set'} = shift;
}

sub getToolbarSet {
    my $self = shift;
    return $self->{'_toolbar_set'};
}

sub generateParams {
    my $self = shift;

    my $width  = $self->getWidth()  || WIDTH;
    my $height = $self->getHeight() || HEIGHT;
    
    $self->setParam('name', $self->getName());    
    $self->setParam('height', ($height =~ /^\d+%$/) ? $height : $height.'px');    
    $self->setParam('width', ($width =~ /^\d+%$/) ? $width : $width.'px');
    $self->setParam('content', unrender($self->getModel()));

    $self->getIncludeService()->addIncludedFile({
        file => 'javascript/textarea.js',
        type => 'text/javascript',
    });

    return TRUE;
}

sub generateRTESwitchParams {
    my $self = shift;

    # Don't set any params if config doesn't allow switching
    return TRUE unless $self->getConfigService()->get('allow_rte_switching');

    my $button_service = $self->getButtonService();

    # Scroll to the correct textarea
    my $current_target = $button_service->getAttribute('scroll_textarea') || '';
    my $scroll_target  = $self->getName().'_container';
    if ($current_target eq $scroll_target) {
        $self->getOnloadService()->setScrollTarget($scroll_target);
    }

    my $use_rte = $self->isRichTextEnabled();

    my $rte_switch = $button_service->makeButton({
        lang_key         => $use_rte ? 'turn_off_rte' : 'turn_on_rte',
        action           => '__set_preference__',
        attributes       => {
            scroll_textarea => $scroll_target,
        },
        preference_key   => 'use_plaintext',
        preference_value => $use_rte ? TRUE : FALSE,
        client_action    => 'window.onbeforeunload = null; true;',
    });

    $self->setParam('using_plaintext', $use_rte ? FALSE : TRUE);
    $self->setParam('rte_switch', $rte_switch->getTextLink());

    return TRUE;
}

sub isRichTextEnabled {
    my $self = shift;

    return TRUE unless $self->getConfigService()->get('allow_rte_switching');

    my $preference_service = Solstice::PreferenceService->new();
    my $ns_service = Solstice::NamespaceService->new();
    $preference_service->setNamespace($ns_service->getAppNamespace());

    return $preference_service->getPreference('use_plaintext') ? FALSE : TRUE;
}


1;

__END__