diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 8b96ca95b..185601b6e 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -61,6 +61,9 @@ files and images. - Added a privilege access handler to the uploads file system. - Added CDG Commerce iTransact payment plugin. + - Added an asset picker form control. + - Shortcuts can now proxy every type of asset, not just wobjects. + - Added a codearea form control. 6.2.11 diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index bcfdfa5ce..def330c85 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2232,6 +2232,7 @@ Moves self to trash, returns www_view() method of Parent if canEdit. Otherwise r sub www_delete { my $self = shift; return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless $self->canEdit; + return $self->getAdminConsole->render(WebGUI::Privilege::vitalComponent()) if (isIn($self->getId, $session{setting}{defaultPage}, $session{setting}{notFoundPage})); $self->trash; return $self->getParent->www_view; } diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 97b370f6e..4af103ade 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -17,12 +17,13 @@ package WebGUI::Form; use strict; use HTTP::BrowserDetect; use Tie::IxHash; +use WebGUI::Asset; +use WebGUI::Asset::Template; use WebGUI::DateTime; use WebGUI::International; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Style; -use WebGUI::Asset::Template; use WebGUI::URL; use WebGUI::Utility; @@ -38,9 +39,11 @@ Base forms package. Eliminates some of the normal code work that goes along with use WebGUI::Form; + $html = WebGUI::Form::asset({value=>$assetId}); $html = WebGUI::Form::button({value=>"Click me!", extras=>qq|onclick="alert('Aaaaggggghhh!!!')"|}); $html = WebGUI::Form::checkbox({name=>"whichOne", value=>"red"}); $html = WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days}); + $html = WebGUI::Form::codearea({name=>"stylesheet"}); $html = WebGUI::Form::combo({name=>"fruit",options=>\%fruit}); $html = WebGUI::Form::contentType({name=>"contentType"); $html = WebGUI::Form::databaseLink(); @@ -110,6 +113,58 @@ sub _fixTags { } +#------------------------------------------------------------------- + +=head2 asset ( hashref ) + +Returns an asset picker control. + +=head3 value + +The asset ID assigned to this control. + +=head3 name + +The name of this field. Defaults to "asset". + +=head3 defaultValue + +If no value is specified, use this value. + +=head3 class + +Limit options to a specific class type such as "WebGUI::Asset::Wobject::Article" + +=head3 extras + +Assign extra things like javascript events to this form element. + +=cut + + +sub asset { + my $params = shift; + my $value = $params->{value} || $params->{defaultValue}; + my $name = $params->{name} || "asset"; + my $asset = WebGUI::Asset->newByDynamicClass($value) || WebGUI::Asset->getRoot; + return hidden({ + name=>$name, + extras=>'id="'.$name.'" '.$params->{extras}, + value=>$asset->getId + }) + .text({ + name=>$name."_display", + extras=>'id="'.$name."_display".'" readonly="1"', + value=>$asset->get("title") + }) + .button({ + value=>"...", + extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree&classLimiter=".$params->{class}."&formId=".$name).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"' + }); + +} + + #------------------------------------------------------------------- =head2 button ( hashRef ) @@ -994,11 +1049,15 @@ The default value for this form element. This will be used if no value is specified. +=head3 extras + +Add extra things like ids and javascript event handlers. + =cut sub hidden { my $params = shift; - return ''."\n"; + return '{extras}.' />'."\n"; } diff --git a/lib/WebGUI/FormProcessor.pm b/lib/WebGUI/FormProcessor.pm index 92aa50895..3ab2d44f9 100644 --- a/lib/WebGUI/FormProcessor.pm +++ b/lib/WebGUI/FormProcessor.pm @@ -32,6 +32,7 @@ This package helps in the processing of the form variables that are returned fro use WebGUI::FormProcessor; $value = WebGUI::FormProcessor::process("favoriteColor","selectList","black"); + $value = WebGUI::FormProcessor::asset("assetId"); $value = WebGUI::FormProcessor::checkbox("whichOne"); $value = WebGUI::FormProcessor::checkList("dayOfWeek"); $value = WebGUI::FormProcessor::codearea("snippet"); @@ -74,6 +75,22 @@ sub _checkEmailAddy { #------------------------------------------------------------------- +=head2 asset ( name ) + +Returns an asset id. + +=head3 name + +The name of the form variable to retrieve. + +=cut + +sub asset { + return $session{form}{$_[0]}; +} + +#------------------------------------------------------------------- + =head2 checkbox ( name ) Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. @@ -386,7 +403,8 @@ The name of the form variable to retrieve. =cut sub interval { - return (WebGUI::DateTime::intervalToSeconds($session{form}{$_[0]."_interval"},$session{form}{$_[0]."_units"}) || 0); + my $val = WebGUI::DateTime::intervalToSeconds($session{form}{$_[0]."_interval"},$session{form}{$_[0]."_units"}) || 0; + return $val; } @@ -450,7 +468,6 @@ The default value for this variable. If the variable is undefined then the defau sub process { my ($name, $type, $default) = @_; my $value; - return undef unless (exists $session{form}{$name}); $type = "text" if ($type eq ""); $value = &$type($name); unless (defined $value) { diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index cb84a8285..1f33dcb13 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -38,6 +38,10 @@ Package that makes HTML forms typed data and significantly reduces the code need use WebGUI::HTMLForm; $f = WebGUI::HTMLForm->new; + $f-asset( + -value=>$assetId, + -label=>"Pick an Asset" + ); $f->button( -value=>"Click me!", -extras=>qq|onClick="alert('Aaaaaaaggggghh!!!!')"| @@ -52,6 +56,10 @@ Package that makes HTML forms typed data and significantly reduces the code need -options=>\%days, -label=>"Which day?" ); + $f->codearea( + -name=>"stylesheet", + -label=>"Stylesheet" + ); $f->combo( -name=>"fruit", -options=>\%fruit, @@ -220,6 +228,71 @@ sub _uiLevelChecksOut { } } +#------------------------------------------------------------------- + +=head2 asset ( name, label, value, class, extras, subtext, defaultValue, uiLevel ) + +Returns an asset picker control. + +=head3 name + +The name of this field. Defaults to "asset". + +=head3 label + +A label to display next to this field. + +=head3 value + +The asset ID to assign to this control. + +=head3 class + +Limit the assets picked to a specific class such as "WebGUI::Asset::File" + +=head3 extras + +Add extra attributes to the form element like javascript event handlers. + +=head3 subtext + +A small message to appear under the form element with additional instructions. + +=head3 defaultValue + +If value is not specified we'll use this instead. + +=head3 uiLevel + +What UI level is required to see this control. + +=cut + +sub asset { + my ($self, @p) = @_; + my ($name, $label, $value, $class, $extras, $subtext, $defaultValue, $uiLevel) = rearrange([qw(name label value class extras subtext defaultValue uiLevel)], @p); + my $output; + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::asset({ + "name"=>$name, + "value"=>$value, + "class"=>$class, + "extras"=>$extras, + "defaultValue"=>$defaultValue + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + "name"=>$name, + "value"=>$value, + "defaultValue"=>$defaultValue + }); + } + $self->{_data} .= $output; +} + + #------------------------------------------------------------------- =head2 button ( value [, label, extras, subtext, defaultValue ] ) diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index b6fe481ad..dcdf1cfc3 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -95,9 +95,10 @@ sub getOperations { 'editDatabaseLink' => 'WebGUI::Operation::DatabaseLink', 'editDatabaseLinkSave' => 'WebGUI::Operation::DatabaseLink', 'listDatabaseLinks' => 'WebGUI::Operation::DatabaseLink', - 'richEditPageTree' => 'WebGUI::Operation::RichEdit', - 'richEditImageTree' => 'WebGUI::Operation::RichEdit', - 'richEditViewThumbnail' => 'WebGUI::Operation::RichEdit', + 'formAssetTree' => 'WebGUI::Operation::FormHelpers', + 'richEditPageTree' => 'WebGUI::Operation::FormHelpers', + 'richEditImageTree' => 'WebGUI::Operation::FormHelpers', + 'richEditViewThumbnail' => 'WebGUI::Operation::FormHelpers', 'manageUsersInGroup' => 'WebGUI::Operation::Group', 'deleteGroup' => 'WebGUI::Operation::Group', 'deleteGroupConfirm' => 'WebGUI::Operation::Group', diff --git a/lib/WebGUI/Operation/RichEdit.pm b/lib/WebGUI/Operation/FormHelpers.pm similarity index 76% rename from lib/WebGUI/Operation/RichEdit.pm rename to lib/WebGUI/Operation/FormHelpers.pm index 738a990ad..461f6664f 100644 --- a/lib/WebGUI/Operation/RichEdit.pm +++ b/lib/WebGUI/Operation/FormHelpers.pm @@ -1,4 +1,4 @@ -package WebGUI::Operation::RichEdit; +package WebGUI::Operation::FormHelpers; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2004 Plain Black Corporation. @@ -16,6 +16,34 @@ use WebGUI::HTMLForm; use WebGUI::Session; use WebGUI::Style; +#------------------------------------------------------------------- +sub www_formAssetTree { + my $base = WebGUI::Asset->newByUrl || WebGUI::Asset->getRoot; + my @crumb; + my $ancestors = $base->getLineage(["self","ancestors"],{returnQuickReadObjects=>1}); + foreach my $ancestor (@{$ancestors}) { + push(@crumb,''.$ancestor->get("menuTitle").''); + } + my $output = '
'.join(" > ", @crumb)."
\n"; + my $children = $base->getLineage(["children"],{returnQuickReadObjects=>1}); + foreach my $child (@{$children}) { + next unless $child->canView; + if ($child->get("className") =~ /^$session{form}{classLimiter}/) { + $output .= '(•) '; + } else { + $output .= "(•) "; + } + $output .= ''.$child->get("menuTitle").''."