Solstice::View::Remote - View of the XML response to AJAX calls.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::View::Remote - View of the XML response to AJAX calls.

generateParams()
addScriptParams($str)

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::View::Remote;

use strict;
use warnings;
use 5.006_000;

use base qw(Solstice::View);

use constant TRUE  => 1;
use constant FALSE => 0;

sub new {
    my $obj = shift;
    my $self = $obj->SUPER::new(@_);
    
    $self->_setTemplate('boilerplate/remote.xml');
    $self->_setTemplatePath('templates');

    return $self;
}

sub setActions {
    my $self = shift;
    $self->{'_actions'} = shift;
}

sub getActions {
    my $self = shift;
    return $self->{'_actions'};
}

sub generateParams {
    my $self = shift;

    for my $action ( @{$self->getActions()} ){
        $self->addParam('actions', {
            type     => $action->{'type'},
            content  => $action->{'content'},
            block_id => $action->{'block_id'} ? $action->{'block_id'} : undef,
        });
    
        next if $action->{'type'} eq 'action';

        # Inline javascript must be pulled out for execution
        $self->addScriptParams($action->{'content'});
    }

    # Accumulated onload events must be executed
    for my $event ( @{$self->getOnloadService()->getEvents()} ){
        $self->addParam('actions', {
            type    => 'action',
            content => $event.';',
        });
    }

    return TRUE;
}

sub addScriptParams {
    my $self = shift;
    my $string = shift;
    return unless $string;

    my $parser = HTML::Parser->new(
        report_tags   => [qw(script)],
        unbroken_text => TRUE,
        start_h       => [sub {
            my $s = shift;
            $s->handler(text => [], '@{dtext}');
        }, 'self'],
        end_h         => [sub {
            my $s = shift;
            $self->addParam('actions', {
                type    => 'action',
                content => $s->handler('text')->[0],
            });
            #warn join("", @{$s->handler('text')});
            $s->handler(text => undef);
        }, 'self'],
    );
    $parser->parse($string);
    $parser->eof();
    return;
}


1;