Convert Image::Graph and Poll over to use FormBuilder.

This commit is contained in:
Colin Kuskie 2010-11-29 09:37:28 -08:00
parent 0983362204
commit 5d4405f43d
5 changed files with 158 additions and 185 deletions

View file

@ -198,6 +198,7 @@ sub _generateGraph_noFormPost {
my $self = shift;
return WebGUI::Image::Graph->getPluginList($self->session) ? 1 : 0;
}
#-------------------------------------------------------------------
sub _hasVoted {
my $self = shift;
@ -281,19 +282,14 @@ override getEditForm => sub {
if (WebGUI::Image::Graph->getPluginList($self->session)) {
my $config = $self->getGraphConfig;
$fb->addTab(name => 'graph', label => $i18n->get('Graphing','Image_Graph'));
$fb->getTab('graph')->addField( "yesNo",
my $graphTab = $fb->addTab(name => 'graph', label => $i18n->get('Graphing','Image_Graph'));
$graphTab->addField( "yesNo",
name => 'generateGraph',
label => $i18n->get('generate graph'),
hoverHelp => $i18n->get('generate graph description'),
value => $self->generateGraph,
);
# TODO: Fix graphing plugins to use FormBuilder API
$fb->getTab('graph')->addField(
'ReadOnly',
value => WebGUI::Image::Graph->getGraphingTab($self->session, $config)
);
WebGUI::Image::Graph->getGraphingTab($graphTab, $config)
}
return $fb;

View file

@ -55,79 +55,75 @@ sub addDataset {
#-------------------------------------------------------------------
=head2 configurationForm ( )
=head2 configurationForm ( $tab )
Returns a hashref containing the form where the properties of your graph type
can be set. Your pluging should extend this method by append the form to the
hashref returned by the super method and returning the reference.
The key for this entry must be unique, so use the namespace of your plugin
without the WebGUI::Image part; the :: converted to and underscore and
everything in lowercase.
Adds form fields for this type of graph plugin to a WebGUI::FormBuilder::Tab object.
Your plugin should extend this method by first calling SUPER.
Check some of the plugins that come with WebGUI for examples.
=head3 $tab
A WebGUI::FormBuilder::Tab object to append the form fields to.
=cut
sub configurationForm {
my $self = shift;
my $tab = shift;
my $i18n = WebGUI::International->new($self->session, 'Image_Graph');
my $f = WebGUI::HTMLForm->new($self->session);
$f->trClass('Graph');
$f->integer(
-name => 'graph_imageWidth',
-value => $self->getImageWidth,
-label => $i18n->get('image width'),
-hoverHelp => $i18n->get('image width description'),
$tab->addField('integer',
name => 'graph_imageWidth',
value => $self->getImageWidth,
label => $i18n->get('image width'),
hoverHelp => $i18n->get('image width description'),
);
$f->integer(
-name => 'graph_imageHeight',
-value => $self->getImageHeight,
-label => $i18n->get('image height'),
-hoverHelp => $i18n->get('image height description'),
$tab->addField('integer',
name => 'graph_imageHeight',
value => $self->getImageHeight,
label => $i18n->get('image height'),
hoverHelp => $i18n->get('image height description'),
);
$f->color(
-name => 'graph_backgroundColor',
-value => $self->getBackgroundColor,
-label => $i18n->get('background color'),
-hoverHelp => $i18n->get('background color description'),
$tab->addField('color',
name => 'graph_backgroundColor',
value => $self->getBackgroundColor,
label => $i18n->get('background color'),
hoverHelp => $i18n->get('background color description'),
);
$f->selectBox(
-name => 'graph_paletteId',
-label => $i18n->get('palette'),
-hoverHelp => $i18n->get('palette description'),
-value => [ $self->getPalette->getId ],
-options=> $self->getPalette->getPaletteList,
$tab->addField('selectBox',
name => 'graph_paletteId',
label => $i18n->get('palette'),
hoverHelp => $i18n->get('palette description'),
value => [ $self->getPalette->getId ],
options=> $self->getPalette->getPaletteList,
);
$f->float(
-name => 'graph_labelOffset',
-value => $self->getLabelOffset,
-label => $i18n->get('label offset'),
-hoverHelp => $i18n->get('label offset description'),
$tab->addField('float',
name => 'graph_labelOffset',
value => $self->getLabelOffset,
label => $i18n->get('label offset'),
hoverHelp => $i18n->get('label offset description'),
);
$f->selectBox(
-name => 'graph_labelFontId',
-value => [ $self->getLabelFont->getId ],
-label => $i18n->get('label font'),
-hoverHelp => $i18n->get('label font description'),
-options=> WebGUI::Image::Font->getFontList($self->session),
$tab->addField('selectBox',
name => 'graph_labelFontId',
value => [ $self->getLabelFont->getId ],
label => $i18n->get('label font'),
hoverHelp => $i18n->get('label font description'),
options=> WebGUI::Image::Font->getFontList($self->session),
);
$f->color(
-name => 'graph_labelColor',
-value => $self->getLabelColor,
-label => $i18n->get('label color'),
-hoverHelp => $i18n->get('label color description'),
$tab->addField('color',
name => 'graph_labelColor',
value => $self->getLabelColor,
label => $i18n->get('label color'),
hoverHelp => $i18n->get('label color description'),
);
$f->integer(
-name => 'graph_labelFontSize',
-value => $self->getLabelFontSize,
-label => $i18n->get('label fontsize'),
-hoverHelp => $i18n->get('label fontsize description'),
$tab->addField('integer',
name => 'graph_labelFontSize',
value => $self->getLabelFontSize,
label => $i18n->get('label fontsize'),
hoverHelp => $i18n->get('label fontsize description'),
);
return {'graph' => $f->printRowsOnly};
}
#-------------------------------------------------------------------
@ -211,15 +207,16 @@ sub getConfiguration {
#-------------------------------------------------------------------
=head2 getGraphingTab ( session, [ config ] )
=head2 getGraphingTab ( tab, [ config ] )
Returns the contents of the graphing tab you can add to your asset.
This is a class method, and therefore you must pass the WebGUI session object.
This is a class method.
=head3 session
=head3 tab
An instanciated WebGUI session object.
An instanciated WebGUI::FormBuilder::Tab object. The session is taken
from this.
=head3 config
@ -228,10 +225,10 @@ Optionally you can pass a configuration hash to populate the form
=cut
sub getGraphingTab {
my (%configForms, $output);
my $class = shift;
my $session = shift;
my $config = shift;
my $class = shift;
my $tab = shift;
my $config = shift;
my $session = $tab->session;
my (@graphingPlugins, %graphingPlugins, @failedGraphingPlugins);
@ -240,15 +237,11 @@ sub getGraphingTab {
my $f = WebGUI::HTMLForm->new($session);
unless ($session->config->get("graphingPlugins")) {
$f->readOnly(
-value => $i18n->get('no graphing plugins in config'),
);
return $f->printRowsOnly;
$tab->addField('readOnly', { value => $i18n->get('no graphing plugins in config'), });
}
foreach (@{$session->config->get("graphingPlugins")}) {
my $plugin = WebGUI::Image::Graph->load($session, $_);
my $plugin = WebGUI::Image::Graph->load($session, $_);
if ($plugin) {
push(@graphingPlugins, $plugin);
$plugin->setConfiguration($config);
@ -259,20 +252,20 @@ my $plugin = WebGUI::Image::Graph->load($session, $_);
}
my $ns = $config->{graph_formNamespace};
# payment plugin
my %configForms;
if (%graphingPlugins) {
$session->style->setRawHeadTags(<<EOS
<script type="text/javascript">
function inNamespace (clas, namespace) {
var namespaceParts = namespace.split('_');
var s = '';
for (var i = 0; i < namespaceParts.length; i++) {
if (i > 0) {
s = s + '_';
}
s = s + namespaceParts[i];
if (s == clas) {
return true;
}
@ -280,10 +273,10 @@ my $plugin = WebGUI::Image::Graph->load($session, $_);
return false;
}
function getContainerTag (elem, tagname) {
var parent = elem.parentNode;
while (parent.tagName != tagname) {
parent = parent.parentNode;
}
@ -307,34 +300,33 @@ my $plugin = WebGUI::Image::Graph->load($session, $_);
</script>
EOS
);
$f->selectBox(
-name => 'graphingPlugin',
-options => \%graphingPlugins,
-label => $i18n->get('graph type'),
-hoverHelp => $i18n->get('graph type description'),
-id => 'graphTypeSelector',
-value => [ $config->{graph_formNamespace} ],
-extras => 'onchange="switchGraphingFormElements(this, this.value)"'
$tab->addField('selectBox',
name => 'graphingPlugin',
options => \%graphingPlugins,
label => $i18n->get('graph type'),
hoverHelp => $i18n->get('graph type description'),
id => 'graphTypeSelector',
value => [ $config->{graph_formNamespace} ],
extras => 'onchange="switchGraphingFormElements(this, this.value)"',
);
foreach my $currentPlugin (@graphingPlugins) {
%configForms = (%configForms, %{$currentPlugin->configurationForm});
$currentPlugin->configurationForm($tab);
}
} else {
$f->raw('<tr><td colspan="2" align="left">'.$i18n->get('no graphing plugins').'</td></tr>');
$tab->addField('readOnly', value => $i18n->get('no graphing plugins'), );
}
foreach (sort keys %configForms) {
$f->raw($configForms{$_});
}
$f->raw('<script type="text/javascript">'.
"switchGraphingFormElements(document.getElementById('graphTypeSelector'), '$ns');".
'</script>'
);
return $f->printRowsOnly;
$tab->addField('readOnly', value => <<EOJS );
<script type="text/javascript">
switchGraphingFormElements(document.getElementById('graphTypeSelector'), '$ns')
</script>
EOJS
}
#-------------------------------------------------------------------

View file

@ -331,85 +331,80 @@ documentation.
sub configurationForm {
my $self = shift;
my $tab = shift;
$self->SUPER::configurationForm($tab);
my $i18n = WebGUI::International->new($self->session, 'Image_Graph_Pie');
my $f = WebGUI::HTMLForm->new($self->session);
$f->trClass('Graph_Pie');
$f->float(
-name => 'pie_radius',
-value => $self->getRadius,
-label => $i18n->get('radius'),
-hoverHelp => $i18n->get('radius description'),
$tab->addField('float',
name => 'pie_radius',
value => $self->getRadius,
label => $i18n->get('radius'),
hoverHelp => $i18n->get('radius description'),
);
$f->float(
-name => 'pie_topHeight',
-value => $self->getTopHeight,
-label => $i18n->get('pie height'),
-hoverHelp => $i18n->get('pie height description'),
$tab->addField('float',
name => 'pie_topHeight',
value => $self->getTopHeight,
label => $i18n->get('pie height'),
hoverHelp => $i18n->get('pie height description'),
);
$f->float(
-name => 'pie_tiltAngle',
-value => $self->getTiltAngle,
-label => $i18n->get('tilt angle'),
-hoverHelp => $i18n->get('tilt angle description'),
$tab->addField('float',
name => 'pie_tiltAngle',
value => $self->getTiltAngle,
label => $i18n->get('tilt angle'),
hoverHelp => $i18n->get('tilt angle description'),
);
$f->float(
-name => 'pie_startAngle',
-value => $self->getStartAngle,
-label => $i18n->get('start angle'),
-hoverHelp => $i18n->get('start angle description'),
$tab->addField('float',
name => 'pie_startAngle',
value => $self->getStartAngle,
label => $i18n->get('start angle'),
hoverHelp => $i18n->get('start angle description'),
);
$f->selectBox(
-name => 'pie_pieMode',
-value => [ $self->getPieMode ],
-label => $i18n->get('pie mode'),
-hoverHelp => $i18n->get('pie mode description'),
-options => {
$tab->addField('selectBox',
name => 'pie_pieMode',
value => [ $self->getPieMode ],
label => $i18n->get('pie mode'),
hoverHelp => $i18n->get('pie mode description'),
options => {
normal => $i18n->get('normal'),
stepped => $i18n->get('stepped'),
},
);
$f->yesNo(
-name => 'pie_shadedSides',
-value => $self->hasShadedSides,
-label => $i18n->get('shade sides'),
-hoverHelp => $i18n->get('shade sides description'),
$tab->addField('yesNo',
name => 'pie_shadedSides',
value => $self->hasShadedSides,
label => $i18n->get('shade sides'),
hoverHelp => $i18n->get('shade sides description'),
);
$f->float(
-name => 'pie_stickLength',
-value => $self->getStickLength,
-label => $i18n->get('stick length'),
-hoverHelp => $i18n->get('stick length description'),
$tab->addField('float',
name => 'pie_stickLength',
value => $self->getStickLength,
label => $i18n->get('stick length'),
hoverHelp => $i18n->get('stick length description'),
);
$f->float(
-name => 'pie_stickOffset',
-value => $self->getStickOffset,
-label => $i18n->get('stick offset'),
-hoverHelp => $i18n->get('stick offset description'),
$tab->addField('float',
name => 'pie_stickOffset',
value => $self->getStickOffset,
label => $i18n->get('stick offset'),
hoverHelp => $i18n->get('stick offset description'),
);
$f->color(
-name => 'pie_stickColor',
-value => $self->getStickColor,
-label => $i18n->get('stick color'),
-hoverHelp => $i18n->get('stick color description'),
$tab->addField('color',
name => 'pie_stickColor',
value => $self->getStickColor,
label => $i18n->get('stick color'),
hoverHelp => $i18n->get('stick color description'),
);
$f->selectBox(
-name => 'pie_labelPosition',
-value => [ $self->getLabelPosition ],
-label => $i18n->get('label position'),
-hoverHelp => $i18n->get('label position description'),
-options=> {
$tab->addField('selectBox',
name => 'pie_labelPosition',
value => [ $self->getLabelPosition ],
label => $i18n->get('label position'),
hoverHelp => $i18n->get('label position description'),
options=> {
center => $i18n->get('center'),
top => $i18n->get('top'),
bottom => $i18n->get('bottom'),
},
);
my $configForms = $self->SUPER::configurationForm;
$configForms->{'graph_pie'} = $f->printRowsOnly;
return $configForms;
}
#-------------------------------------------------------------------

View file

@ -41,58 +41,56 @@ documentation.
=cut
sub configurationForm {
my ($configForms, $f);
my $self = shift;
my $tab = shift;
my $i18n = WebGUI::International->new($self->session, 'Image_Graph_XYGraph');
$configForms = $self->SUPER::configurationForm;
$self->SUPER::configurationForm($tab);
$f = WebGUI::HTMLForm->new($self->session);
$f->trClass('Graph_XYGraph');
$f->integer(
$tab->addField('integer',
name => 'xyGraph_chartWidth',
value => $self->getChartWidth,
label => $i18n->get('chart width'),
hoverHelp => $i18n->get('chart width description'),
);
$f->integer(
$tab->addField('integer',
name => 'xyGraph_chartHeight',
value => $self->getChartHeight,
label => $i18n->get('chart height'),
hoverHelp => $i18n->get('chart height description'),
);
$f->yesNo(
$tab->addField('yesNo',
name => 'xyGraph_drawLabels',
value => $self->showLabels,
label => $i18n->get('draw labels'),
hoverHelp => $i18n->get('draw labels description'),
);
$f->yesNo(
$tab->addField('yesNo',
name => 'xyGraph_drawAxis',
value => $self->showAxis,
label => $i18n->get('draw axis'),
hoverHelp => $i18n->get('draw axis description'),
);
$f->color(
$tab->addField('color',
name => 'xyGraph_axisColor',
value => $self->getAxisColor,
label => $i18n->get('axis color'),
hoverHelp => $i18n->get('axis color description'),
);
$f->yesNo(
$tab->addField('yesNo',
name => 'xyGraph_drawRulers',
value => $self->showRulers,
label => $i18n->get('draw rulers'),
hoverHelp => $i18n->get('draw rulers description'),
);
$f->color(
$tab->addField('color',
name => 'xyGraph_rulerColor',
value => $self->getRulerColor,
label => $i18n->get('ruler color'),
hoverHelp => $i18n->get('ruler color description'),
);
$f->selectBox(
$tab->addField('selectBox',
name => 'xyGraph_drawMode',
value => [ $self->getDrawMode ],
label => $i18n->get('draw mode'),
@ -103,15 +101,12 @@ sub configurationForm {
stacked => 'Stacked (cumulative',
},
);
$f->float(
$tab->addField('float',
name => 'xyGraph_yGranularity',
value => $self->getYGranularity,
label => $i18n->get('y granularity'),
hoverHelp => $i18n->get('y granularity description'),
);
$configForms->{'graph_xygraph'} = $f->printRowsOnly;
return $configForms;
}
#-------------------------------------------------------------------

View file

@ -47,28 +47,23 @@ more information.
sub configurationForm {
my $self = shift;
my $tab = shift;
my $i18n = WebGUI::International->new($self->session, 'Image_Graph_XYGraph_Bar');
my $configForms = $self->SUPER::configurationForm;
my $f = WebGUI::HTMLForm->new($self->session);
$f->trClass('Graph_XYGraph_Bar');
$f->float(
$self->SUPER::configurationForm($tab);
$tab->addField('float',
name => 'xyGraph_bar_barSpacing',
value => $self->getBarSpacing,
label => $i18n->get('bar spacing'),
hoverHelp => $i18n->get('bar spacing description'),
);
$f->float(
$tab->addField('float',
name => 'xyGraph_bar_groupSpacing',
value => $self->getGroupSpacing,
label => $i18n->get('group spacing'),
hoverHelp => $i18n->get('group spacing description'),
);
$configForms->{'graph_xygraph_bar'} = $f->printRowsOnly;
return $configForms;
}
#-------------------------------------------------------------------