bug fixes for widgets and exports. snippets were exported as index.html or the

like, and widget toolboxes weren't popping up in a widgetized view.
This commit is contained in:
Chris Nehren 2008-05-31 19:42:38 +00:00
parent f5ad94c95e
commit 5dfc9e3bfc
8 changed files with 774 additions and 142 deletions

View file

@ -2437,7 +2437,6 @@ true.
sub isValidRssItem { 1 }
#-------------------------------------------------------------------
=head2 www_widgetView ( )
Returns the view() method of the asset object suitable for widgetizing.
@ -2451,7 +2450,9 @@ sub www_widgetView {
return $session->privilege->noAccess() unless $self->canView;
my $templateId = $session->form->process('templateId');
my $templateId = $session->form->process('templateId');
my $width = $session->form->process('width');
my $height = $session->form->process('height');
if($templateId eq 'none') {
$self->prepareView;
@ -2459,8 +2460,7 @@ sub www_widgetView {
else {
$self->prepareWidgetView($templateId);
}
$self->_outputWidgetJs;
return $self->view;
return $self->outputWidgetMarkup($width, $height, $templateId);
}
#-------------------------------------------------------------------
@ -2479,22 +2479,117 @@ sub prepareWidgetView {
my $template = WebGUI::Asset::Template->new($self->session, $templateId);
my $session = $self->session;
my $extras = $session->config->get('extrasURL');
my $yahooDomJs = $extras . '/yui/build/yahoo-dom-event/yahoo-dom-event.js';
my $widgetJs = $extras . '/widgetLinkTargets.js';
$template->prepare;
$self->{_viewTemplate} = $template;
}
sub _outputWidgetJs {
#-------------------------------------------------------------------
=head2 outputWidgetMarkup ( width, height, templateId )
Output the markup required for the widget view. Includes markup to handle the
widget macro in the iframe holding the widgetized asset. This does the following:
=item retrieves the content for this asset using its L</view> method
=item processes macros in that content
=item serializes the processed content in JSON
=item writes the JSON to a storage location
=item refers the user to download this JSON
=item references the appropriate JS files for the templating engine and the widget macro
=item invokes the templating engine on this JSON
=head3 width
The width of the iframe. Required for making widget-in-widget function properly.
=head3 height
The height of the iframe. Required for making widget-in-widget function properly.
=head3 templateId
The templateId for this widgetized asset to use. Required for making
widget-in-widget function properly.
=cut
sub outputWidgetMarkup {
# get our parameters.
my $self = shift;
my $width = shift;
my $height = shift;
my $templateId = shift;
# construct / retrieve the values we'll use later.
my $assetId = $self->getId;
my $session = $self->session;
my $extras = $session->config->get('extrasURL');
my $conf = $session->config;
my $extras = $conf->get('extrasURL');
# the widgetized version of content that has the widget macro in it is
# executing in an iframe. this iframe doesn't have a style object.
# therefore, the macro won't be able to output the stylesheet and JS
# information it needs to do its work. because of this, we need to output
# that content manually. construct the filesystem paths for those files.
my $containerCss = $extras . '/yui/build/container/assets/container.css';
my $containerJs = $extras . '/yui/build/container/container-min.js';
my $yahooDomJs = $extras . '/yui/build/yahoo-dom-event/yahoo-dom-event.js';
my $widgetJs = $extras . '/widgetLinkTargets.js';
$session->output->print("<script type='text/javascript' src='" . $yahooDomJs . "'></script>");
$session->output->print("<script type='text/javascript' src='" . $widgetJs . "'></script>");
my $wgWidgetJs = $extras . '/wgwidget.js';
my $ttJs = $extras . '/tt.js';
# the templating engine requires its source data to be in json format.
# write this out to disk and then serve the URL to the user. in this case,
# we'll be serializing the content of the asset which is being widgetized.
my $storage = WebGUI::Storage->get($session, $assetId);
my $content = $self->view;
WebGUI::Macro::process($session, \$content);
my $jsonContent = objToJson( { "asset$assetId" => { content => $content } } );
$storage->addFileFromScalar("$assetId.js", "data = $jsonContent");
my $jsonUrl = $storage->getUrl("$assetId.js");
# WebGUI.widgetBox.initButton() needs the full URL of the asset being
# widgetized, and also the full URL of the JS file that does most of the
# work.
my $fullUrl = "http://" . $conf->get("sitename")->[0] . $self->getUrl;
my $wgWidgetPath = 'http://' . $conf->get('sitename')->[0] . $extras . '/wgwidget.js';
# finally, given all of the above, construct our output. WebGUI outputs
# fully valid XHTML 1.0 Strict, and there's no reason this should be any
# different.
my $output = <<OUTPUT;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="$containerCss" />
<script type="text/javascript" src="$jsonUrl"></script>
<script type="text/javascript" src="$ttJs"></script>
<script type='text/javascript' src='$yahooDomJs'></script>
<script type='text/javascript' src='$containerJs'></script>
<script type='text/javascript' src='$wgWidgetJs'></script>
<script type='text/javascript'>
function setupPage() {
WebGUI.widgetBox.doTemplate('widget$assetId'); WebGUI.widgetBox.retargetLinksAndForms();
WebGUI.widgetBox.initButton( { 'wgWidgetPath' : '$wgWidgetPath', 'fullUrl' : '$fullUrl', 'assetId' : '$assetId', 'width' : $width, 'height' : $height, 'templateId' : '$templateId' } );
}
YAHOO.util.Event.addListener(window, 'load', setupPage);
</script>
</head>
<body id="widget$assetId">
\${asset$assetId.content}
</body>
</html>
OUTPUT
return $output;
}
1;