diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index b01d63664..d906b292c 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,8 @@ 7.4.0 + - api: Form Controls and Workflow Activities may now include web based helper + subroutines directly in their files. See + WebGUI::Operation::FormHelpers::www_formHelper and + WebGUI::Operation::Workflow::www_activityHelper for details. - rfe: snippets should have titles too! - Added a mechanism for using external folders for custom code. See sbin/preload.custom.example for details. diff --git a/lib/WebGUI/Form/Asset.pm b/lib/WebGUI/Form/Asset.pm index 7fd2b04a8..7188897b5 100644 --- a/lib/WebGUI/Form/Asset.pm +++ b/lib/WebGUI/Form/Asset.pm @@ -99,7 +99,7 @@ Renders an asset selector. sub toHtml { my $self = shift; my $asset = WebGUI::Asset->newByDynamicClass($self->session, $self->get("value")) || WebGUI::Asset->getRoot($self->session); - my $url = $asset->getUrl("op=formAssetTree;formId=".$self->get('id')); + my $url = $asset->getUrl("op=formHelper;sub=assetTree;class=Asset;formId=".$self->get('id')); $url .= ";classLimiter=".$self->get("class") if ($self->get("class")); return WebGUI::Form::Hidden->new($self->session, name=>$self->get("name"), @@ -119,5 +119,81 @@ sub toHtml { )->toHtml; } +#------------------------------------------------------------------- + +=head2 www_assetTree ( session ) + +Returns a list of the all the current Asset's children as form. The children can be filtered via the +form variable C. A crumb trail is provided for navigation. + +=cut + +sub www_assetTree { + my $session = shift; + $session->http->setCacheControl("none"); + my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); + my @crumb; + my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1}); + foreach my $ancestor (@{$ancestors}) { + my $url = $ancestor->getUrl("op=formHelper;sub=assetTree;class=Asset;formId=".$session->form->process("formId")); + $url .= ";classLimiter=".$session->form->process("classLimiter","className") if ($session->form->process("classLimiter","className")); + push(@crumb,''.$ancestor->get("menuTitle").''); + } + my $output = ' + + + + +
+
'.join(" > ", @crumb)."

\n"; + my $children = $base->getLineage(["children","self"],{returnObjects=>1}); + my $i18n = WebGUI::International->new($session); + my $limit = $session->form->process("classLimiter","className"); + foreach my $child (@{$children}) { + next unless $child->canView; + if ($limit eq "" || $child->get("className") =~ /^$limit/) { + $output .= 'getId.'\';window.opener.document.getElementById(\''. + $session->form->process("formId").'_display\').value=\''.$child->get("title").'\';window.close();">['.$i18n->get("select").'] '; + } else { + $output .= '['.$i18n->get("select").'] '; + } + my $url = $child->getUrl("op=formHelper;sub=assetTree;class=Asset;formId=".$session->form->process("formId")); + $url .= ";classLimiter=".$session->form->process("classLimiter","className") if ($session->form->process("classLimiter","className")); + $output .= ''.$child->get("menuTitle").''."
\n"; + } + $output .= '
'; + $session->style->useEmptyStyle("1"); + return $output; +} + + 1; diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index 07e6c1719..f063f7a4c 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -65,6 +65,10 @@ Flag that tells the User Profile system that this is a valid form element in a U A url that will get a filename appended to it and then links to delete the files will be generated automatically. +=head4 size + +Though not all browsers support it, this will attempt to set the size (or width) of the browse for file field. + =cut sub definition { @@ -88,6 +92,9 @@ sub definition { deleteFileUrl=>{ defaultValue=>undef }, + size=>{ + defaultValue=>40 + }, dbDataType => { defaultValue => "VARCHAR(22) BINARY", }, @@ -210,8 +217,8 @@ sub toHtml { $uploadControl .= 'fileIcons["'.$ext.'"] = "'.$self->session->url->extras('fileIcons/'.$file).'";'."\n"; } } - $uploadControl .= sprintf q!var uploader = new FileUploadControl("%s", fileIcons, "%s","%d"); uploader.addRow(); ! - , $self->get("name")."_file", $i18n->get("removeLabel"), $maxFiles; + $uploadControl .= sprintf q!var uploader = new FileUploadControl("%s", fileIcons, "%s","%d", "%s"); uploader.addRow(); ! + , $self->get("name")."_file", $i18n->get("removeLabel"), $maxFiles, $self->get("size"); $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml()."
"; } else { $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->get("name"), -value => $self->get("value")})->toHtml()."
"; diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm index 6c50a5cdb..7a558bc57 100644 --- a/lib/WebGUI/Form/HTMLArea.pm +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -16,7 +16,9 @@ package WebGUI::Form::HTMLArea; use strict; use base 'WebGUI::Form::Textarea'; +use WebGUI::Asset::File::Image; use WebGUI::Asset::RichEdit; +use WebGUI::Asset::Wobject::Folder; use WebGUI::HTML; use WebGUI::International; @@ -145,6 +147,406 @@ sub toHtml { } +#------------------------------------------------------------------- + +=head2 www_pageTree ( session ) + +Asset picker for the rich editor. + +=cut + +sub www_pageTree { + my $session = shift; + $session->http->setCacheControl("none"); + $session->style->setRawHeadTags(q| + |); + $session->style->setScript($session->url->extras('tinymce2/jscripts/tiny_mce/tiny_mce_popup.js'),{type=>"text/javascript"}); + my $i18n = WebGUI::International->new($session); + my $f = WebGUI::HTMLForm->new($session,-action=>"#"); + $f->text( + -name=>"url", + -label=>$i18n->get(104), + -hoverHelp=>$i18n->get('104 description'), + ); + my %options = (); + tie %options, 'Tie::IxHash'; + %options = ("_self"=>$i18n->get('link in same window'), + "_blank"=>$i18n->get('link in new window')); + $f->selectBox( + -name=>"target", + -label=>$i18n->get('target'), + -hoverHelp=>$i18n->get('target description'), + -options=>\%options + ); + $f->button( + -name=>"button", + -value=>$i18n->get('done'), + -extras=>'onclick="createLink()"' + ); + my $output = '
'.$i18n->get('insert a link').''.$f->print.'
'.<<"JS" + +JS + .'
'.$i18n->get('pages').' '; + $output .= '
'; + my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); + my @crumb; + my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1}); + foreach my $ancestor (@{$ancestors}) { + push(@crumb,''.$ancestor->get("menuTitle").''); + } + $output .= '
'.join(" > ", @crumb)."

\n"; + my $children = $base->getLineage(["children"],{returnObjects=>1}); + foreach my $child (@{$children}) { + next unless $child->canView; + $output .= '['.$i18n->get("select").'] +'.$child->get("menuTitle").''."
\n"; + } + $output .= '
'; + return $session->style->process($output, 'PBtmpl0000000000000137'); +} + +#------------------------------------------------------------------- + +=head2 www_imageTree ( session ) + +Similar to www_pageTree, except it is limited to only display assets of class WebGUI::Asset::File::Image. +Each link display a thumbnail of the image via www_viewThumbnail. + +=cut + +sub www_imageTree { + my $session = shift; + $session->http->setCacheControl("none"); + $session->style->setRawHeadTags(q| |); + my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getMedia($session); + my @crumb; + my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1}); + my $media; + my @output; + push(@output, '
'); + my $i18n = WebGUI::International->new($session, 'Operation_FormHelpers'); + foreach my $ancestor (@{$ancestors}) { + push(@crumb,''.$ancestor->get("menuTitle").''); + # check if we are in (a subdirectory of) Media + if ($ancestor->get('assetId') eq 'PBasset000000000000003') { + $media = $ancestor; + } + } + if ($media) { + # if in (a subdirectory of) Media, give user the ability to create folders or upload images + push(@output, '

[ '.$i18n->get('Create new folder').' ]   [ '.$i18n->get('Upload new image').' ]

'); + } else { + $media = WebGUI::Asset->getMedia($session); + # if not in Media, provide a direct link to it + push(@output, '

[ '.$media->get('title').' ]

'); + } + push(@output, '
'.join(" > ", @crumb)."

\n"); + my $children = $base->getLineage(["children"],{returnObjects=>1}); + foreach my $child (@{$children}) { + next unless $child->canView; + if ($child->get("className") =~ /^WebGUI::Asset::File::Image/) { + push(@output, '['.$i18n->get("select","WebGUI").'] '); + } else { + push(@output, ' ['.$i18n->get("select","WebGUI")."] "); + } + push(@output, ''.$child->get("menuTitle").''."
\n"); + } + push(@output, '
'); + return $session->style->process(join('', @output), 'PBtmpl0000000000000137'); +} + +#------------------------------------------------------------------- + +=head2 www_viewThumbnail ( session ) + +Displays a thumbnail of an Image Asset in the Image manager for the Rich Editor. The current +URL in the session object is used to determine which Image is used. + +=cut + +sub www_viewThumbnail { + my $session = shift; + $session->http->setCacheControl("none"); + my $image = WebGUI::Asset->newByUrl($session); + my $i18n = WebGUI::International->new($session); + my $output; + if ($image->get("className") =~ /WebGUI::Asset::File::Image/) { + $output = '
'; + $output .= ''.$i18n->get('preview').''; + $output .= '
'; + $output .= $image->get("filename"); + $output .= '
'; + $output .= '\n"; + } else { + $output = '
'.$i18n->get('image manager').'
'; + } + return $session->style->process($output, 'PBtmpl0000000000000137'); +} + +#------------------------------------------------------------------- + +=head2 www_addFolder ( session ) + +Returns a form to add a folder using the rich editor. The purpose of this feature is to provide a very simple way for end-users to create a folder from within the rich editor, in stead of having to leave the rich editor and use the asset manager. A very minimal set of options is supplied, all other options should be derived from the current asset. + +=cut + +sub www_addFolder { + my $session = shift; + $session->http->setCacheControl("none"); + my $i18n = WebGUI::International->new($session, 'Operation_FormHelpers'); + my $f = WebGUI::HTMLForm->new($session); + $f->hidden( + name => 'op', + value => 'formHelper', + ); + $f->hidden( + name => 'class', + value => 'HTMLArea', + ); + $f->hidden( + name => 'sub', + value => 'addFolderSave', + ); + $f->text( + label => $i18n->get('Folder name'), + name => 'filename', + size => 15, + ); + $f->submit( + value => $i18n->get('Create'), + ); + $f->button( + value => $i18n->get('Cancel'), + extras => 'onclick="history.go(-1);"', + ); + my $html = '

'.$i18n->get('Create new folder').'

'.$f->print; + return $session->style->process($html, 'PBtmpl0000000000000137'); +} + +#------------------------------------------------------------------- + +=head2 www_addFolderSave ( session ) + +Creates a directory under the current asset. The filename should be specified in the form. The Edit and View rights from the current asset are used if not specified in the form. All other properties are copied from the current asset. + +=cut + +sub www_addFolderSave { + my $session = shift; + $session->http->setCacheControl("none"); + # get base url + my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); + # check if user can edit the current asset + return $session->privilege->insufficient('bare') unless $base->canEdit; + + my $filename = $session->form->process('filename') || 'untitled'; + $base->addChild({ + # Asset properties + title => $filename, + menuTitle => $filename, + url => $base->getUrl.'/'.$filename, + groupIdEdit => $session->form->process('groupIdEdit') || $base->get('groupIdEdit'), + groupIdView => $session->form->process('groupIdView') || $base->get('groupIdView'), + ownerUserId => $session->user->userId, + startDate => $base->get('startDate'), + endDate => $base->get('endDate'), + encryptPage => $base->get('encryptPage'), + isHidden => 1, + newWindow => 0, + + # Asset/Wobject properties + displayTitle => 1, + cacheTimeout => $base->get('cacheTimeout'), + cacheTimeoutVisitor => $base->get('cacheTimeoutVisitor'), + styleTemplateId => $base->get('styleTemplateId'), + printableStyleTemplateId => $base->get('printableStyleTemplateId'), + + # Asset/Wobject/Folder properties + templateId => 'PBtmpl0000000000000078', + + # Other properties + #assetId => 'new', + className => 'WebGUI::Asset::Wobject::Folder', + #filename => $filename, + }); + $session->http->setRedirect($base->getUrl('op=formHelper;class=HTMLForm;sub=imageTree')); + return ""; +} + +#------------------------------------------------------------------- + +=head2 www_addImage ( session ) + +Returns a form to add an image using the rich editor. The purpose of this feature is to provide a very simple way for end-users to upload new images from within the rich editor, in stead of having to leave the rich editor and use the asset manager. A very minimal set of options is supplied, all other options should be derived from the current asset. + +=cut + +sub www_addImage { + my $session = shift; + $session->http->setCacheControl("none"); + my $i18n = WebGUI::International->new($session, 'Operation_FormHelpers'); + my $f = WebGUI::HTMLForm->new($session); + $f->hidden( + name => 'op', + value => 'formHelper', + ); + $f->hidden( + name => 'class', + value => 'HTMLArea', + ); + $f->hidden( + name => 'sub', + value => 'addImageSave', + ); + $f->image( + label => $i18n->get('File'), + name => 'filename', + size => 10, + ); + $f->submit( + value => $i18n->get('Upload'), + ); + $f->button( + value => $i18n->get('Cancel'), + extras => 'onclick="history.go(-1);"', + ); + my $html = '

'.$i18n->get('Upload new image').'

'.$f->print; + return $session->style->process($html, 'PBtmpl0000000000000137'); +} + +#------------------------------------------------------------------- + +=head2 www_addImageSave ( session ) + +Creates an Image asset under the current asset. The filename should be specified in the form. The Edit and View rights from the current asset are used if not specified in the form. All other properties are copied from the current asset. + +=cut + +sub www_addImageSave { + my $session = shift; + $session->http->setCacheControl("none"); + # get base asset + my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); + + # check if user can edit the current asset + return $session->privilege->insufficient('bare') unless $base->canEdit; + + #my $imageId = WebGUI::Form::Image->create($session); + my $imageId = WebGUI::Form::Image->new($session,{name => 'filename'})->getValueFromPost; + my $imageObj = WebGUI::Storage::Image->get($session, $imageId); + ##This is a hack. It should use the WebGUI::Form::File API to insulate + ##us from future form name changes. + my $filename = $imageObj->getFiles->[0]; + if ($filename) { + $base->addChild({ + assetId => 'new', + className => 'WebGUI::Asset::File::Image', + storageId => $imageObj->getId, + filename => $filename, + title => $filename, + menuTitle => $filename, + templateId => 'PBtmpl0000000000000088', + url => $base->get("url").'/'.$filename, + groupIdEdit => $session->form->process('groupIdEdit') || $base->get('groupIdEdit'), + groupIdView => $session->form->process('groupIdView') || $base->get('groupIdView'), + ownerUserId => $session->var->get('userId'), + isHidden => 1, + }); + } + $session->http->setRedirect($base->getUrl('op=formHelper;class=HTMLArea;sub=imageTree')); + $imageObj->delete; + return ""; +} + 1; - diff --git a/lib/WebGUI/Form/Image.pm b/lib/WebGUI/Form/Image.pm index f1bcea1c3..d899b4489 100644 --- a/lib/WebGUI/Form/Image.pm +++ b/lib/WebGUI/Form/Image.pm @@ -194,8 +194,8 @@ sub toHtml { $uploadControl .= 'fileIcons["'.$ext.'"] = "'.$self->session->url->extras('fileIcons/'.$file).'";'."\n"; } } - $uploadControl .= sprintf q!var uploader = new FileUploadControl("%s", fileIcons, "%s","%d"); uploader.addRow(); !, - $self->get("name")."_file", $i18n->get("removeLabel"), $maxNewFiles; + $uploadControl .= sprintf q!var uploader = new FileUploadControl("%s", fileIcons, "%s","%d", "%s"); uploader.addRow(); !, + $self->get("name")."_file", $i18n->get("removeLabel"), $maxNewFiles, $self->get("size"); $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml()."
"; } else { $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->get("name"), -value => $self->get("value")})->toHtml()."
"; diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index a89f37b72..8beab3806 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -109,6 +109,7 @@ sub getOperations { 'editCommerceSettings' => 'WebGUI::Operation::Commerce', 'editCommerceSettingsSave' => 'WebGUI::Operation::Commerce', 'listTransactions' => 'WebGUI::Operation::Commerce', + 'salesTaxTable' => 'WebGUI::Operation::Commerce', 'selectPaymentGateway' => 'WebGUI::Operation::Commerce', 'selectPaymentGatewaySave' => 'WebGUI::Operation::Commerce', 'selectShippingMethod' => 'WebGUI::Operation::Commerce', @@ -130,6 +131,7 @@ sub getOperations { 'listDatabaseLinks' => 'WebGUI::Operation::DatabaseLink', 'formAssetTree' => 'WebGUI::Operation::FormHelpers', + 'formHelper' => 'WebGUI::Operation::FormHelpers', 'richEditAddFolder' => 'WebGUI::Operation::FormHelpers', 'richEditAddFolderSave' => 'WebGUI::Operation::FormHelpers', 'richEditAddImage' => 'WebGUI::Operation::FormHelpers', @@ -137,7 +139,6 @@ sub getOperations { 'richEditImageTree' => 'WebGUI::Operation::FormHelpers', 'richEditPageTree' => 'WebGUI::Operation::FormHelpers', 'richEditViewThumbnail' => 'WebGUI::Operation::FormHelpers', - 'salesTaxTable' => 'WebGUI::Operation::FormHelpers', 'addGroupsToGroupSave' => 'WebGUI::Operation::Group', 'addUsersToGroupSave' => 'WebGUI::Operation::Group', diff --git a/lib/WebGUI/Operation/Commerce.pm b/lib/WebGUI/Operation/Commerce.pm index 84dcd6618..45003153a 100644 --- a/lib/WebGUI/Operation/Commerce.pm +++ b/lib/WebGUI/Operation/Commerce.pm @@ -716,7 +716,7 @@ sub www_editCommerceSettings { $tabform->getTab('salesTax')->raw(''); $session->style->setScript($session->url->extras('/js/at/AjaxRequest.js'), {type=>"text/javascript"}); $session->style->setScript($session->url->extras('/operations/salesTaxAjax.js'), {type=>"text/javascript"}); - my $stateForm = WebGUI::Operation::FormHelpers::www_salesTaxTable($session); + my $stateForm = www_salesTaxTable($session); $tabform->getTab('salesTax')->raw('
'.$stateForm.'
'); $tabform->getTab('salesTax')->raw(''); # Check which payment plugins will compile, and load them. @@ -995,6 +995,111 @@ sub www_listTransactions { return _submenu($session,$output, 'list transactions') } +#------------------------------------------------------------------- + +=head2 www_salesTaxTable ( $session ) + +Create the AJAX form for displaying, adding and deleting sales tax information. + +=cut + +sub www_salesTaxTable { + my $session = shift; + + my $returnTableOnly = 0; + + if ($session->form->process('addDelete') eq 'add') { + my $state = $session->form->process('addStateId', 'selectBox'); + my $taxRate = $session->form->process('taxRate', 'float'); + my $commerceSalesTaxId = $session->id->generate(); + if ( $state and $taxRate ) { + $session->db->write('insert into commerceSalesTax (commerceSalesTaxId,regionIdentifier,salesTax) VALUES (?,?,?)', [$commerceSalesTaxId, $state, $taxRate]); + } + $returnTableOnly = 1; + } + elsif ($session->form->process('addDelete') eq 'delete') { + my $commerceSalesTaxId = $session->form->process('entryId'); + $session->db->write('delete from commerceSalesTax where commerceSalesTaxId=?',[$commerceSalesTaxId]); + $returnTableOnly = 1; + } + + my $existingData = $session->db->buildArrayRefOfHashRefs('select * from commerceSalesTax order by regionIdentifier'); + + ##To build the form, we need two pieces + + ##1: The table contains all information from the database + my @existingStates = map { $_->{regionIdentifier} } @{ $existingData }; + my %existingStates = map { $_ => 1 } @existingStates; + + ##2: The list contains all states except for those in the table; + my $stateObj = Locale::US->new(); + my @stateNames = $stateObj->all_state_names; + my @newStates = sort grep {! exists $existingStates{$_} } @stateNames; + + my %orderedStates; + tie %orderedStates, 'Tie::IxHash'; + my $i18n = WebGUI::International->new($session); + %orderedStates = map { $_ => $_ } 'Select State', @newStates; + $orderedStates{'Select State'} = $i18n->get('Select State'); + + my $statesField = WebGUI::Form::selectBox($session, + -name => 'stateChooser', + -options => \%orderedStates, + -default => 'Select State', + ); + + my $taxField = WebGUI::Form::float($session, + -name => 'taxRate', + -value => '', + -size => 6, + ); + my $addButton = WebGUI::Form::button($session, + -name=>"addTaxInfo", + -value=>"Add Tax Information", + -extras=>q!align="right" onclick="addState()"!, + ); + + ##build the table to display all existing sales tax + + my $tableRows = ''; + my $deleteIcon = $session->config->get('extrasURL').'/toolbar/bullet/delete.gif'; + foreach my $sRow ( @{$existingData} ) { + $tableRows .= sprintf <{commerceSalesTaxId}, $sRow->{regionIdentifier}, $sRow->{salesTax}; + + +%s +%6.4f%% + +EOTR + } + my $stateForm = sprintf < + + +%s %% tax for +%s +%s + + + +EOSF + +my $stateTable = sprintf < + +%s + + +EOST + $stateTable = '' unless $tableRows; + return $stateForm.$stateTable; +} + + + + + + #------------------------------------------------------------------- =head2 www_selectPaymentGateway ( $session ) diff --git a/lib/WebGUI/Operation/FormHelpers.pm b/lib/WebGUI/Operation/FormHelpers.pm index ede5aaa06..df44ff0bb 100644 --- a/lib/WebGUI/Operation/FormHelpers.pm +++ b/lib/WebGUI/Operation/FormHelpers.pm @@ -29,10 +29,49 @@ Operational support for various things relating to forms and rich editors. =cut + +#------------------------------------------------------------------- + +=head2 www_formHelper ( session ) + +Calls a form helper. In the URL you must pass the form class name, the subroutine to call and any other +parameters you wish the form helper to use. Here's an example: + +/page?op=formHelper;class=File;sub=assetTree;param1=XXX + +=cut + +sub www_formHelper { + my $session = shift; + my $form = $session->form; + my $class = "WebGUI::Form::".$form->get("class"); + my $sub = $form->get("sub"); + return "ERROR" unless (defined $sub && defined $class); + my $load = "use ".$class; + eval($load); + if ($@) { + $session->errorHandler->error("Couldn't load form helper class $class because $@"); + return "ERROR"; + } + my $output = ""; + my $command = $class.'::www_'.$sub; + no strict; + my $output = eval { &$command($session) }; + use strict; + if ($@) { + $session->errorHandler->error("Couldn't execute form helper subroutine $sub because $@"); + return "ERROR"; + } + return $output; +} + + #------------------------------------------------------------------- =head2 www_formAssetTree ( session ) +B This function is depricated and will be removed in a future release. + Returns a list of the all the current Asset's children as form. The children can be filtered via the form variable C. A crumb trail is provided for navigation. @@ -108,6 +147,8 @@ sub www_formAssetTree { =head2 www_richEditPageTree ( session ) +B This function is depricated and will be removed in a future release. + Asset picker for the rich editor. =cut @@ -209,6 +250,8 @@ JS =head2 www_richEditImageTree ( session ) +B This function is depricated and will be removed in a future release. + Similar to www_formAssetTree, except it is limited to only display assets of class WebGUI::Asset::File::Image. Each link display a thumbnail of the image via www_richEditViewThumbnail. @@ -290,6 +333,8 @@ sub www_richEditImageTree { =head2 www_richEditViewThumbnail ( session ) +B This function is depricated and will be removed in a future release. + Displays a thumbnail of an Image Asset in the Image manager for the Rich Editor. The current URL in the session object is used to determine which Image is used. @@ -331,6 +376,8 @@ sub www_richEditViewThumbnail { =head2 www_richEditAddFolder ( session ) +B This function is depricated and will be removed in a future release. + Returns a form to add a folder using the rich editor. The purpose of this feature is to provide a very simple way for end-users to create a folder from within the rich editor, in stead of having to leave the rich editor and use the asset manager. A very minimal set of options is supplied, all other options should be derived from the current asset. =cut @@ -363,6 +410,8 @@ sub www_richEditAddFolder { =head2 www_richEditAddFolderSave ( session ) +B This function is depricated and will be removed in a future release. + Creates a directory under the current asset. The filename should be specified in the form. The Edit and View rights from the current asset are used if not specified in the form. All other properties are copied from the current asset. =cut @@ -413,6 +462,8 @@ sub www_richEditAddFolderSave { =head2 www_richEditAddImage ( session ) +B This function is depricated and will be removed in a future release. + Returns a form to add an image using the rich editor. The purpose of this feature is to provide a very simple way for end-users to upload new images from within the rich editor, in stead of having to leave the rich editor and use the asset manager. A very minimal set of options is supplied, all other options should be derived from the current asset. =cut @@ -446,6 +497,8 @@ sub www_richEditAddImage { =head2 www_richEditAddImageSave ( session ) +B This function is depricated and will be removed in a future release. + Creates an Image asset under the current asset. The filename should be specified in the form. The Edit and View rights from the current asset are used if not specified in the form. All other properties are copied from the current asset. =cut @@ -487,106 +540,6 @@ sub www_richEditAddImageSave { return ""; } -#------------------------------------------------------------------- - -=head2 www_setupSalesTaxForm ( $session ) - -Create the AJAX form for displaying, adding and deleting sales tax information. - -=cut - -sub www_salesTaxTable { - my $session = shift; - - my $returnTableOnly = 0; - - if ($session->form->process('addDelete') eq 'add') { - my $state = $session->form->process('addStateId', 'selectBox'); - my $taxRate = $session->form->process('taxRate', 'float'); - my $commerceSalesTaxId = $session->id->generate(); - if ( $state and $taxRate ) { - $session->db->write('insert into commerceSalesTax (commerceSalesTaxId,regionIdentifier,salesTax) VALUES (?,?,?)', [$commerceSalesTaxId, $state, $taxRate]); - } - $returnTableOnly = 1; - } - elsif ($session->form->process('addDelete') eq 'delete') { - my $commerceSalesTaxId = $session->form->process('entryId'); - $session->db->write('delete from commerceSalesTax where commerceSalesTaxId=?',[$commerceSalesTaxId]); - $returnTableOnly = 1; - } - - my $existingData = $session->db->buildArrayRefOfHashRefs('select * from commerceSalesTax order by regionIdentifier'); - - ##To build the form, we need two pieces - - ##1: The table contains all information from the database - my @existingStates = map { $_->{regionIdentifier} } @{ $existingData }; - my %existingStates = map { $_ => 1 } @existingStates; - - ##2: The list contains all states except for those in the table; - my $stateObj = Locale::US->new(); - my @stateNames = $stateObj->all_state_names; - my @newStates = sort grep {! exists $existingStates{$_} } @stateNames; - - my %orderedStates; - tie %orderedStates, 'Tie::IxHash'; - my $i18n = WebGUI::International->new($session); - %orderedStates = map { $_ => $_ } 'Select State', @newStates; - $orderedStates{'Select State'} = $i18n->get('Select State'); - - my $statesField = WebGUI::Form::selectBox($session, - -name => 'stateChooser', - -options => \%orderedStates, - -default => 'Select State', - ); - - my $taxField = WebGUI::Form::float($session, - -name => 'taxRate', - -value => '', - -size => 6, - ); - my $addButton = WebGUI::Form::button($session, - -name=>"addTaxInfo", - -value=>"Add Tax Information", - -extras=>q!align="right" onclick="addState()"!, - ); - - ##build the table to display all existing sales tax - - my $tableRows = ''; - my $deleteIcon = $session->config->get('extrasURL').'/toolbar/bullet/delete.gif'; - foreach my $sRow ( @{$existingData} ) { - $tableRows .= sprintf <{commerceSalesTaxId}, $sRow->{regionIdentifier}, $sRow->{salesTax}; - - -%s -%6.4f%% - -EOTR - } - my $stateForm = sprintf < - - -%s %% tax for -%s -%s - - - -EOSF - -my $stateTable = sprintf < - -%s - - -EOST - $stateTable = '' unless $tableRows; - return $stateForm.$stateTable; -} - 1; diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index b6c0a4429..771734f66 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -32,6 +32,42 @@ Operation handler for managing workflows. =cut +#------------------------------------------------------------------- + +=head2 www_activityHelper ( session ) + +Calls an activity helper. In the URL you must pass the activity class name, the subroutine to call and any other +parameters you wish the activity helper to use. Here's an example: + +/page?op=activityHelper;class=MyActivity;sub=doTheBigThing;param1=makeItGo + +=cut + +sub www_activityHelper { + my $session = shift; + my $form = $session->form; + my $class = "WebGUI::Workflow::Activity::".$form->get("class"); + my $sub = $form->get("sub"); + return "ERROR" unless (defined $sub && defined $class); + my $load = "use ".$class; + eval($load); + if ($@) { + $session->errorHandler->error("Couldn't load activity helper class $class because $@"); + return "ERROR"; + } + my $output = ""; + my $command = $class.'::www_'.$sub; + no strict; + my $output = eval { &$command($session) }; + use strict; + if ($@) { + $session->errorHandler->error("Couldn't execute activity helper subroutine $sub because $@"); + return "ERROR"; + } + return $output; +} + + #------------------------------------------------------------------- =head2 www_addWorkflow ( )