Better integration of Fork into AssetHelpers, fork startup

This commit is contained in:
Paul Driver 2010-11-08 07:54:47 -06:00
parent bb8753cd2a
commit a4edea1e3c
12 changed files with 162 additions and 160 deletions

View file

@ -35,6 +35,23 @@ These subroutines are available from this package:
use Template;
use HTML::Entities;
use JSON;
use URI;
my $blank = <<'TEMPLATE';
<html>
<head>
<title>[% title %]</title>
[% FOREACH sheet IN stylesheets %]
<link rel='stylesheet' href='[% sheet %]'></link>
[% END %]
[% FOREACH script IN scripts %]
<script src='[% script %]'></script>
[% END %]
</head>
<div><a href='[% bookmark.url %]'>[% bookmark.label %]</a></div>
[% content %]
</html>
TEMPLATE
my $template = <<'TEMPLATE';
<div id='loading'>[% i18n('WebGUI', 'Loading...') %]</div>
@ -64,7 +81,7 @@ my $template = <<'TEMPLATE';
document.getElementById('ui').style.display = 'block';
},
finish : function() {
YAHOO.WebGUI.Fork.redirect(params.redirect);
YAHOO.WebGUI.Fork.redirect(params);
},
error : function (msg) {
alert(msg);
@ -87,40 +104,50 @@ sub handler { renderBar( shift, $template ) }
#-------------------------------------------------------------------
=head2 renderBar ( process, template )
=head2 renderBar ( process, template, extras )
Renders $template, passing a "params" variable to it that is JSON of a
statusUrl to poll and a page to redirect to and an i18n function. Includes
WebGUI.Fork.redirect, poll, and ProgressBar js and CSS (as well as all their
YUI dependancies), and puts the whole template inside an adminConsole rendered
based off some form parameters.
based off some form parameters. Extras is a hashref, optionally containing two
keys (css and js) which will be added to the page.
=cut
sub renderBar {
my ( $process, $template ) = @_;
my ( $process, $template, $extras ) = @_;
my $session = $process->session;
my $url = $session->url;
my $form = $session->form;
my $style = $session->style;
my $f = $session->form->paramsHashRef;
my $tt = Template->new;
my %vars = (
my $dialog = delete $f->{dialog};
my %params = (
statusUrl => $url->page( $process->contentPairs('Status') ),
);
if ($dialog) {
$params{message} = $f->{message};
}
else {
$params{redirect} = $f->{proceed};
}
my %vars = (
i18n => sub {
my ($namespace, $key) = @_;
return WebGUI::International->new($session, $namespace)->get($key);
},
params => JSON::encode_json( {
statusUrl => $url->page( $process->contentPairs('Status') ),
redirect => scalar $form->get('proceed'),
}
),
params => JSON::encode_json(\%params),
);
$tt->process( \$template, \%vars, \my $content ) or die $tt->error;
my $console = WebGUI::AdminConsole->new( $session, $form->get('icon') );
$style->setLink( $url->extras("Fork/ProgressBar.css"), { rel => 'stylesheet' } );
$style->setScript( $url->extras("$_.js") )
for ( (
my @sheets = (
$url->extras("Fork/ProgressBar.css"),
@{ $extras->{css} || []}
);
my @scripts = ( (
map { $url->extras("$_.js") } (
map {"yui/build/$_"}
qw(
yahoo/yahoo-min
@ -133,8 +160,39 @@ sub renderBar {
'Fork/ProgressBar',
'Fork/poll',
'Fork/redirect'
),
@{ $extras->{js} || []}
);
my $link = URI->new($url->page);
my $title = encode_entities( $f->{title} );
my $label =
WebGUI::International->new( $session, 'Fork_ProgressBar' )
->get('link to this page');
if ($dialog) {
$link->query_form($f);
my %vars = (
content => $content,
scripts => \@scripts,
stylesheets => \@sheets,
title => $title,
bookmark => {
url => $link,
label => $label,
}
);
return $console->render( $content, encode_entities( $form->get('title') ) );
$tt->process( \$blank, \%vars, \my $styled ) or die $tt->error;
return $styled;
}
else {
my $console = WebGUI::AdminConsole->new( $session, $f->{icon} );
my $style = $session->style;
$link->query_form($f);
$console->addSubmenuItem( $link->as_string, $label );
$style->setLink($_, { rel => 'stylesheet' }) for @sheets;
$style->setScript($_) for @scripts;
return $console->render( $content, $title );
}
} ## end sub renderBar
1;

View file

@ -114,7 +114,7 @@ my $template = <<'TEMPLATE';
document.getElementById('ui').style.display = 'block';
},
finish : function () {
YAHOO.WebGUI.Fork.redirect(params.redirect);
YAHOO.WebGUI.Fork.redirect(params);
},
error : function (msg) {
alert(msg)
@ -125,15 +125,6 @@ my $template = <<'TEMPLATE';
</script>
TEMPLATE
my $stylesheet = <<'STYLESHEET';
<style>
#tree li { color: black }
#tree li.focus { color: cyan }
#tree li.failure { color: red }
#tree li.success { color: green }
</style>
STYLESHEET
#-------------------------------------------------------------------
=head2 handler ( process )
@ -145,11 +136,12 @@ See WebGUI::Operation::Fork.
sub handler {
my $process = shift;
my $session = $process->session;
my $style = $session->style;
my $url = $session->url;
$style->setRawHeadTags($stylesheet);
$style->setScript($url->extras('underscore/underscore-min.js'));
WebGUI::Fork::ProgressBar::renderBar($process, $template);
WebGUI::Fork::ProgressBar::renderBar($process, $template, {
css => [ $url->extras('Fork/ProgressTree.css') ],
js => [ $url->extras('underscore/underscore-min.js') ],
}
);
}
1;