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

@ -1,7 +1,7 @@
package WebGUI::Macro::Widget;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
# WebGUI is Copyright 2001-2007 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
@ -16,8 +16,8 @@ use strict;
sub process {
# get passed parameters
my $session = shift;
my $assetId = shift;
my $session = shift;
my $url = shift;
my $width = shift || 600;
my $height = shift || 400;
my $templateId = shift || 'none';
@ -27,94 +27,89 @@ sub process {
my $extras = $conf->get("extrasURL");
# add CSS and JS to the page
my $style = $session->style;
$style->setLink($extras."/yui/build/container/assets/container.css",{
my $style = $session->style;
$style->setLink($extras."/yui/build/container/assets/container.css",{
rel=>"stylesheet",
type=>"text/css",
}
);
$style->setScript($extras."/wgwidget.js",{
type=>"text/javascript"
}
);
$style->setScript($extras."/yui/build/yahoo-dom-event/yahoo-dom-event.js",{
type=>"text/javascript"
}
);
$style->setScript($extras."/yui/build/container/container-min.js",{
type=>"text/javascript"
}
);
# construct the absolute URL
my $asset = WebGUI::Asset->new($session, $assetId);
my $fullUrl = "http://" . $conf->get("sitename")->[0] . $asset->getUrl;
# construct path to wgwidget.js
my $wgWidgetPath = 'http://' . $conf->get('sitename')->[0] . $extras . '/wgwidget.js';
# and yahoo-dom-event.js
my $yahooDomJsPath = 'http://' . $conf->get('sitename')->[0] . $extras . '/yui/build/yahoo-dom-event/yahoo-dom-event.js';
my $imgSrc = $extras . '/gear.png';
# and the JS
$style->setScript($extras."/wgwidget.js",{
type=>"text/javascript"
}
);
$style->setScript($extras."/yui/build/yahoo-dom-event/yahoo-dom-event.js",{
type=>"text/javascript"
}
);
$style->setScript($extras."/yui/build/container/container-min.js",{
type=>"text/javascript"
}
);
my $output = <<"EOHTML";
<script>
# construct the absolute URL and get the asset ID
my $asset = WebGUI::Asset->newByUrl($session, $url);
my $assetId = $asset->getId;
var codeGeneratorButton;
# ... and the full URL. If there's an exportWidget scratch variable, we're
# exporting, and we need to use that URL.
my($fullUrl, $wgWidgetPath);
my $scratch = $session->scratch;
my $exportUrl = $scratch->get('exportUrl');
if($exportUrl) {
my $storage = WebGUI::Storage->get($session, $assetId);
$fullUrl = $exportUrl . $storage->getUrl("$assetId.html");
$wgWidgetPath = $exportUrl . $extras . '/wgwidget.js';
$scratch->delete('exportUrl');
my $content = $asset->view;
WebGUI::Macro::process($session, \$content);
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 $wgWidgetJs = $extras . '/wgwidget.js';
my $wgWidgetPath = $extras . '/wgwidget.js';
var handleButtonShow = function() {
codeGeneratorButton.show();
var tag = document.getElementById('jsWidgetCode');
tag.focus();
tag.select();
}
function initButton() {
var jsCode = "";
jsCode += "&lt;script type='text/javascript' src='$wgWidgetPath'&gt; &lt;/script&gt;";
jsCode += "&lt;script type='text/javascript'&gt;";
jsCode += "document.write(WebGUI.widgetBox.widget('$fullUrl', '$assetId', $width, $height, '$templateId')); &lt;/script&gt;";
// Instantiate the Dialog
codeGeneratorButton = new YAHOO.widget.SimpleDialog("codeGeneratorButton", {
width: "500px",
height: "200px",
fixedcenter: true,
visible: false,
draggable: true,
close: true,
text: "<textarea id='jsWidgetCode' rows='5' cols='50'>" + jsCode + "</textarea>",
icon: YAHOO.widget.SimpleDialog.ICON_INFO,
constraintoviewport: true,
modal: true,
zIndex: 9999,
buttons: [{text: "Dismiss", handler:dismissButton, isDefault: true}]
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='$yahooDomJs'></script>
<script type='text/javascript' src='$containerJs'></script>
<script type='text/javascript' src='$wgWidgetJs'></script>
<script type='text/javascript'>
function setupPage() {
WebGUI.widgetBox.retargetLinksAndForms();
WebGUI.widgetBox.initButton( { 'wgWidgetPath' : '$wgWidgetPath', 'fullUrl' : '$fullUrl', 'assetId' : '$assetId', 'width' : $width, 'height' : $height, 'templateId' : '$templateId' } );
}
);
codeGeneratorButton.setHeader("Widget code");
YAHOO.util.Event.addListener(window, 'load', setupPage);
</script>
</head>
<body id="widget$assetId">
$content
</body>
</html>
OUTPUT
$storage->addFileFromScalar("$assetId.html", $content);
}
else {
$fullUrl = "http://" . $conf->get("sitename")->[0] . $asset->getUrl;
$wgWidgetPath = 'http://' . $conf->get('sitename')->[0] . $extras . '/wgwidget.js';
}
// Render the Dialog
codeGeneratorButton.render(document.body);
YAHOO.util.Event.addListener("show", "click", handleButtonShow, codeGeneratorButton, true);
}
var dismissButton = function () {
this.hide();
}
YAHOO.util.Event.addListener(window, "load", initButton);
# get the gear icon
my $imgSrc = $extras . '/gear.png';
my $output = <<EOHTML;
<a href="#$assetId" id="show$assetId" name="show$assetId"><img src="$imgSrc" /></a>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, 'load', WebGUI.widgetBox.initButton, { 'wgWidgetPath' : '$wgWidgetPath', 'fullUrl' : '$fullUrl', 'assetId' : '$assetId', 'width' : $width, 'height' : $height, 'templateId' : '$templateId' } );
</script>
<!-- <button id="show">Get code for this content</button> -->
<a href="#" id="show"><img src="$imgSrc" /></a>
EOHTML
return $output;
return $output;
}
1;