^AssetProxy("flexmenu");
diff --git a/lib/WebGUI/Content/Setup.pm b/lib/WebGUI/Content/Setup.pm index 2b08c7628..f51cecbe9 100644 --- a/lib/WebGUI/Content/Setup.pm +++ b/lib/WebGUI/Content/Setup.pm @@ -45,56 +45,6 @@ These subroutines are available from this package: #------------------------------------------------------------------- -=head2 addAsset ( parent, properties ) - -A helper to add assets with less code. - -=head3 parent - -The parent asset to add to. - -=head3 properties - -A hash ref of properties to attach to the asset. One must be className. - -=cut - -sub addAsset { - my $parent = shift; - my $properties = shift; - $properties->{url} = $parent->get("url") . "/" . $properties->{title}; - $properties->{groupIdEdit} = $parent->get("groupIdEdit"); - $properties->{groupIdView} = $parent->get("groupIdView"); - $properties->{ownerUserId} = $parent->get("ownerUserId"); - $properties->{styleTemplateId} = $parent->get("styleTemplateId"); - $properties->{printableStyleTemplateId} = $parent->get("styleTemplateId"); - return $parent->addChild($properties); -} - -#------------------------------------------------------------------- - -=head2 addPage ( parent, title ) - -Adds a page to a parent page. - -=head3 parent - -A parent page asset. - -=head3 title - -The title of the new page. - -=cut - -sub addPage { - my $parent = shift; - my $title = shift; - return addAsset( $parent, { title => $title, className => "WebGUI::Asset::Wobject::Layout", displayTitle => 0 } ); -} - -#------------------------------------------------------------------- - =head2 handler ( session ) Handles a specialState: "init" @@ -111,537 +61,11 @@ sub handler { unless ( $session->setting->get("specialState") eq "init" ) { return undef; } - $session->http->setCacheControl("none"); - my $i18n = WebGUI::International->new( $session, "WebGUI" ); - my ( $output, $legend ) = ""; - if ( $form->process("step") eq "2" ) { - $legend = $i18n->get('company information'); - my $timezone = $form->timeZone("timeZone"); - my $language = $form->selectBox("language"); - - ##update Admin and Visitor users - my $u = WebGUI::User->new( $session, "3" ); - $u->username( $form->process( "username", "text", "Admin" ) ); - $u->profileField( "email", $form->email("email") ); - $u->profileField( "timeZone", $timezone ); - $u->profileField( "language", $language ); - $u->identifier( Digest::MD5::md5_base64( $form->process( "identifier", "password", "123qwe" ) ) ); - - $u = WebGUI::User->new( $session, "1" ); - $u->profileField( "timeZone", $timezone ); - $u->profileField( "language", $language ); - - ##update ProfileField defaults so new users the get the defaults, too - my $properties; - - my $zoneField = WebGUI::ProfileField->new( $session, 'timeZone' ); - $properties = $zoneField->get(); - $properties->{dataDefault} = $timezone; - $zoneField->set($properties); - - my $languageField = WebGUI::ProfileField->new( $session, 'language' ); - $properties = $languageField->get(); - $properties->{dataDefault} = $language; - $languageField->set($properties); - - my $f = WebGUI::HTMLForm->new( $session, action => $session->url->gateway() ); - $f->hidden( name => "step", value => "3" ); - $f->text( - name => "companyName", - value => $session->setting->get("companyName"), - label => $i18n->get(125), - hoverHelp => $i18n->get('125 description'), - ); - $f->email( - name => "companyEmail", - value => $session->setting->get("companyEmail"), - label => $i18n->get(126), - hoverHelp => $i18n->get('126 description'), - ); - $f->url( - name => "companyURL", - value => $session->setting->get("companyURL"), - label => $i18n->get(127), - hoverHelp => $i18n->get('127 description'), - ); - $f->submit; - $output .= $f->print; - } ## end if ( $form->process("step"...)) - elsif ( $session->form->process("step") eq "3" ) { - my $form = $session->form; - $session->setting->set( 'companyName', $form->text("companyName") ) if ( $form->get("companyName") ); - $session->setting->set( 'companyURL', $form->url("companyURL") ) if ( $form->get("companyURL") ); - $session->setting->set( 'companyEmail', $form->email("companyEmail") ) if ( $form->get("companyEmail") ); - $legend = $i18n->get( 'topicName', 'Activity_SendWebguiStats' ); - $output .= '
' . $i18n->get( 'why to send', 'Activity_SendWebguiStats' ) . '
-' . $i18n->get( 'would you participate', 'Activity_SendWebguiStats' ) . '
-' - . $i18n->get( 'disable', 'Activity_SendWebguiStats' ) - . ' - ' - . $i18n->get( 'enable', 'Activity_SendWebguiStats' ) - . '
- '; - } ## end elsif ( $session->form->process...) - elsif ( $session->form->process("step") eq "sitestarter" ) { - my $form = $session->form; - WebGUI::Operation::Statistics::www_enableSendWebguiStats($session) if ( $form->get("enableStats") ); - $legend = $i18n->get('site starter title'); - $output .= '' . $i18n->get('site starter body') . '
-' - . $i18n->get('no thanks') - . ' - ' . $i18n->get('yes please') . '
- '; - } - elsif ( $session->form->process("step") eq "4" ) { - my $f = WebGUI::HTMLForm->new( $session, action => $session->url->gateway() ); - $f->hidden( name => "step", value => "5", ); - $f->file( name => "logo", label => $i18n->get('logo') ); - $f->submit; - $legend = $i18n->get('upload logo'); - $output .= $f->print; - } - elsif ( $session->form->process("step") eq "5" ) { - my $storageId = $session->form->process( "logo", "image" ); - my $url = $session->url; - my $logoUrl = $url->extras("plainblack.gif"); - if ( defined $storageId ) { - my $storage = WebGUI::Storage->get( $session, $storageId ); - my $importNode = WebGUI::Asset->getImportNode($session); - my $logo = addAsset( - $importNode, { - title => $storage->getFiles->[0], - filename => $storage->getFiles->[0], - isHidden => 1, - storageId => $storageId, - className => "WebGUI::Asset::File::Image", - parameters => 'alt="' . $storage->getFiles->[0] . '"' - } - ); - $logoUrl = $logo->getStorageLocation->getUrl( $logo->get("filename") ); - } - my $style = $session->style; - $style->setLink( $url->extras('/yui/build/container/assets/skins/sam/container.css'), - { type => 'text/css', rel => "stylesheet" } ); - $style->setLink( $url->extras('/yui/build/colorpicker/assets/skins/sam/colorpicker.css'), - { type => 'text/css', rel => "stylesheet" } ); - $style->setScript( $url->extras('/yui/build/yahoo/yahoo-min.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/event/event-min.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/dom/dom-min.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/dragdrop/dragdrop-min.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/utilities/utilities.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/container/container-min.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/slider/slider-min.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras('/yui/build/colorpicker/colorpicker-min.js'), { type => 'text/javascript' } ); - $style->setLink( $url->extras('/colorpicker/colorpicker.css'), { type => 'text/css', rel => "stylesheet" } ); - $style->setScript( $url->extras('/colorpicker/colorpicker.js'), { type => 'text/javascript' } ); - $style->setScript( $url->extras("/styleDesigner/styleDesigner.js"), { type => "text/javascript" } ); - $style->setLink( $url->extras("/styleDesigner/styleDesigner.css"), - { rel => "stylesheet", type => "text/css" } ); - $legend = $i18n->get("style designer"); - $output .= ' - - '; - } ## end elsif ( $session->form->process...) - elsif ( $session->form->process("step") eq "6" ) { - my $importNode = WebGUI::Asset->getImportNode($session); - my $form = $session->form; - my $snippet = '/* auto generated by WebGUI ' . $WebGUI::VERSION . ' */ -.clearFloat { clear: both; } -body { background-color: ' . $form->get("pageBackgroundColor") . '; color: ' . $form->get("contentTextColor") . '} -a { color: ' . $form->get("linkColor") . ';} -a:visited { color: ' . $form->get("visitedLinkColor") . '; } -#editToggleContainer { padding: 1px; } -#utilityLinksContainer { float: right; padding: 1px; } -#pageUtilityContainer { font-size: 9pt; background-color: ' - . $form->get("utilityBackgroundColor") - . '; color: ' - . $form->get("utilityTextColor") . '; } -#pageHeaderContainer { background-color: ' - . $form->get("headerBackgroundColor") - . '; color: ' - . $form->get("headerTextColor") . '; } -#pageHeaderLogoContainer { float: left; padding: 5px; background-color: ' . $form->get("headerBackgroundColor") . ';} -#logo { border: 0px; max-width: 300px; } -#companyNameContainer { float: right; padding: 5px; font-size: 16pt; } -#pageBodyContainer { background-color: ' - . $form->get("contentBackgroundColor") - . '; color: ' - . $form->get("contentTextColor") . '; } -#mainNavigationContainer { min-height: 300px; padding: 5px; float: left; width: 180px; font-size: 10pt; background-color: ' - . $form->get("navigationBackgroundColor") . '; } -#mainNavigationContainer A, #mainNavigationContainer A:link { color: ' . $form->get("navigationTextColor") . '; } -#mainBodyContentContainer { padding: 5px; margin-left: 200px; font-family: serif, times new roman; font-size: 12pt; overflow: auto; } -#pageFooterContainer { text-align: center; background-color: ' - . $form->get("footerBackgroundColor") - . '; color: ' - . $form->get("footerTextColor") . '; } -#copyrightContainer { font-size: 8pt; } -#pageWidthContainer { width: 80%; margin-left: auto; margin-right: auto; font-family: sans-serif, helvetica, arial; border: 3px solid black; } -'; - my $css = addAsset( - $importNode, { - title => "my-style.css", - className => "WebGUI::Asset::Snippet", - snippet => $snippet, - isHidden => 1, - mimeType => "text/css", - } - ); - my $styleTemplate - = ' - - -
- ';
- $session->http->setMimeType("text/html");
- return $page;
-} ## end sub handler
+ # Dispatch to the setup wizard
+ my $wiz = WebGUI::Wizard::Setup->new( $session );
+ return $wiz->dispatch;
+}
1;
diff --git a/lib/WebGUI/Content/Wizard.pm b/lib/WebGUI/Content/Wizard.pm
index bca5cadbf..5c45aaa6a 100644
--- a/lib/WebGUI/Content/Wizard.pm
+++ b/lib/WebGUI/Content/Wizard.pm
@@ -1,6 +1,6 @@
package WebGUI::Content::Wizard;
-sub process {
+sub handler {
my ( $session ) = @_;
if ( $session->form->get('op') eq 'wizard' && $session->form->get('wizard_class') ) {
diff --git a/lib/WebGUI/Wizard.pm b/lib/WebGUI/Wizard.pm
index 09f8bf589..2e3d052b9 100644
--- a/lib/WebGUI/Wizard.pm
+++ b/lib/WebGUI/Wizard.pm
@@ -101,16 +101,20 @@ sub dispatch {
# See if we process a form
if ( my $step = $self->getCurrentStep ) {
+ $self->session->log->info( "Processing " . $step );
# First fold in the new form bits
$self->thaw;
my $processSub = $self->can( 'www_' . $step . 'Save' );
my $errorMessage = $processSub->($self);
if ($errorMessage) {
+ $self->session->log->info( "Error in " . $step );
my $formSub = $self->can( 'www_' . $step );
return $self->wrapStyle( $errorMessage . $formSub->($self) );
}
else {
my $step = $self->getNextStep;
+ $self->session->log->info( "Showing next step: " . $step );
+ $self->setCurrentStep( $step );
my $formSub = $self->can( 'www_' . $step );
my $output = $formSub->($self);
$self->freeze;
@@ -121,7 +125,10 @@ sub dispatch {
# Starting over
$self->{_params} = {};
$self->freeze;
- my $formSub = $self->can( 'www_' . $self->_get_steps->[0] );
+ my $step = $self->_get_steps->[0];
+ $self->setCurrentStep( $step );
+ $self->session->log->info( "Starting wizard: " . $step );
+ my $formSub = $self->can( 'www_' . $step );
my $output = $formSub->($self);
$self->freeze;
return $self->wrapStyle( $output );
@@ -180,36 +187,30 @@ Get the name of the current step.
sub getCurrentStep {
my ( $self ) = @_;
- return $self->{_step} || $self->session->form->get( 'wizard_step' );
+ if ( $self->{_step} ) {
+ return $self->{_step};
+ }
+ elsif ( $self->session->form->get('wizard_class') eq blessed($self) ) {
+ return $self->session->form->get('wizard_step');
+ }
+ return; # No step, so start at the beginning
}
#----------------------------------------------------------------------------
-=head2 getFormEnd ( )
+=head2 getForm ( [step] )
-Get the end of the form, including the tag
+Get a WebGUI::HTMLForm object for a given step, defaulting to the current step.
=cut
-sub getFormEnd {
- my ( $self ) = @_;
- return WebGUI::Form::formFooter;
-}
-
-#----------------------------------------------------------------------------
-
-=head2 getFormStart ( [step] )
-
-Get the start of a form for a given step, defaulting to the current step.
-
-=cut
-
-sub getFormStart {
+sub getForm {
my ( $self, $step ) = @_;
$step ||= $self->getCurrentStep;
- return WebGUI::Form::formHeader( $self->session, {
+ my $form = WebGUI::HTMLForm->new( $self->session,
action => '?op=wizard;wizard_class=' . blessed( $self ) . ';wizard_step=' . $step,
- } );
+ );
+ return $form;
}
#----------------------------------------------------------------------------
@@ -281,7 +282,7 @@ parameters.
sub thaw {
my ( $self ) = @_;
my $json = $self->session->scratch->get( $self->getCacheKey );
- return $self->{_params} = JSON->new->decode( $json );
+ return $self->{_params} = $json ? JSON->new->decode( $json ) : {};
}
#----------------------------------------------------------------------------
diff --git a/t/Content/Wizard.t b/t/Content/Wizard.t
index e8e994040..1b654810b 100644
--- a/t/Content/Wizard.t
+++ b/t/Content/Wizard.t
@@ -35,13 +35,13 @@ plan tests => 3; # Increment this number for each test you create
use_ok( 'WebGUI::Content::Wizard' );
-ok( !WebGUI::Content::Wizard::process( $session ), "Declines correctly" );
+ok( !WebGUI::Content::Wizard::handler( $session ), "Declines correctly" );
$session->request->setup_body( {
op => 'wizard',
wizard_class => 'WebGUI::Wizard::HelloWorld',
} );
-is( WebGUI::Content::Wizard::process( $session ), "Hello World!\n", "Accepts request and returns response" );
+is( WebGUI::Content::Wizard::handler( $session ), "Hello World!\n", "Accepts request and returns response" );
package WebGUI::Wizard::HelloWorld;
diff --git a/t/Wizard.t b/t/Wizard.t
index b4076bbab..ad534a1bf 100644
--- a/t/Wizard.t
+++ b/t/Wizard.t
@@ -51,16 +51,14 @@ is( $wizard->getCurrentStep, "one", "SetCurrentStep" );
#----------------------------------------------------------------------------
# Form Start and End
-my $o = $wizard->getFormStart;
-like( $o, qr/}, 'getFormEnd' );
+$html = $wizard->getForm( "two" )->print;
+like( $html, qr/wizard_step.+two/, 'getFormStart wizard_step override step' );
#----------------------------------------------------------------------------
# Steps
@@ -69,7 +67,13 @@ $wizard = WebGUI::Wizard::Test->new( $session );
$session->request->setup_body( {
wizard_step => "one",
} );
-is( $wizard->getCurrentStep, "one", "getCurrentStep from form" );
+is( $wizard->getCurrentStep, undef, "getCurrentStep requires correct wizard_class");
+
+$session->request->setup_body( {
+ wizard_class => 'WebGUI::Wizard::Test',
+ wizard_step => 'one',
+} );
+is( $wizard->getCurrentStep, 'one', 'getCurrent step from form' );
is( $wizard->getNextStep, "two", "getNextStep" );
is( $wizard->getNextStep( "three" ), "four", "getNextStep with arg" );