added asset form control, fixed some interval problems, added a check so users can't delete the default page or the not found page

This commit is contained in:
JT Smith 2005-02-06 17:02:20 +00:00
parent 1523c9c904
commit 778236efcb
8 changed files with 198 additions and 21 deletions

View file

@ -61,6 +61,9 @@
files and images. files and images.
- Added a privilege access handler to the uploads file system. - Added a privilege access handler to the uploads file system.
- Added CDG Commerce iTransact payment plugin. - 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 6.2.11

View file

@ -2232,6 +2232,7 @@ Moves self to trash, returns www_view() method of Parent if canEdit. Otherwise r
sub www_delete { sub www_delete {
my $self = shift; my $self = shift;
return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless $self->canEdit; 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; $self->trash;
return $self->getParent->www_view; return $self->getParent->www_view;
} }

View file

@ -17,12 +17,13 @@ package WebGUI::Form;
use strict; use strict;
use HTTP::BrowserDetect; use HTTP::BrowserDetect;
use Tie::IxHash; use Tie::IxHash;
use WebGUI::Asset;
use WebGUI::Asset::Template;
use WebGUI::DateTime; use WebGUI::DateTime;
use WebGUI::International; use WebGUI::International;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::SQL; use WebGUI::SQL;
use WebGUI::Style; use WebGUI::Style;
use WebGUI::Asset::Template;
use WebGUI::URL; use WebGUI::URL;
use WebGUI::Utility; use WebGUI::Utility;
@ -38,9 +39,11 @@ Base forms package. Eliminates some of the normal code work that goes along with
use WebGUI::Form; use WebGUI::Form;
$html = WebGUI::Form::asset({value=>$assetId});
$html = WebGUI::Form::button({value=>"Click me!", extras=>qq|onclick="alert('Aaaaggggghhh!!!')"|}); $html = WebGUI::Form::button({value=>"Click me!", extras=>qq|onclick="alert('Aaaaggggghhh!!!')"|});
$html = WebGUI::Form::checkbox({name=>"whichOne", value=>"red"}); $html = WebGUI::Form::checkbox({name=>"whichOne", value=>"red"});
$html = WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days}); $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::combo({name=>"fruit",options=>\%fruit});
$html = WebGUI::Form::contentType({name=>"contentType"); $html = WebGUI::Form::contentType({name=>"contentType");
$html = WebGUI::Form::databaseLink(); $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 ) =head2 button ( hashRef )
@ -994,11 +1049,15 @@ The default value for this form element.
This will be used if no value is specified. This will be used if no value is specified.
=head3 extras
Add extra things like ids and javascript event handlers.
=cut =cut
sub hidden { sub hidden {
my $params = shift; my $params = shift;
return '<input type="hidden" name="'.$params->{name}.'" value="'._fixQuotes(_fixMacros(_fixSpecialCharacters($params->{value}))).'" />'."\n"; return '<input type="hidden" name="'.$params->{name}.'" value="'._fixQuotes(_fixMacros(_fixSpecialCharacters($params->{value}))).'" '.$params->{extras}.' />'."\n";
} }

View file

@ -32,6 +32,7 @@ This package helps in the processing of the form variables that are returned fro
use WebGUI::FormProcessor; use WebGUI::FormProcessor;
$value = WebGUI::FormProcessor::process("favoriteColor","selectList","black"); $value = WebGUI::FormProcessor::process("favoriteColor","selectList","black");
$value = WebGUI::FormProcessor::asset("assetId");
$value = WebGUI::FormProcessor::checkbox("whichOne"); $value = WebGUI::FormProcessor::checkbox("whichOne");
$value = WebGUI::FormProcessor::checkList("dayOfWeek"); $value = WebGUI::FormProcessor::checkList("dayOfWeek");
$value = WebGUI::FormProcessor::codearea("snippet"); $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 ) =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. 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 =cut
sub interval { 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 { sub process {
my ($name, $type, $default) = @_; my ($name, $type, $default) = @_;
my $value; my $value;
return undef unless (exists $session{form}{$name});
$type = "text" if ($type eq ""); $type = "text" if ($type eq "");
$value = &$type($name); $value = &$type($name);
unless (defined $value) { unless (defined $value) {

View file

@ -38,6 +38,10 @@ Package that makes HTML forms typed data and significantly reduces the code need
use WebGUI::HTMLForm; use WebGUI::HTMLForm;
$f = WebGUI::HTMLForm->new; $f = WebGUI::HTMLForm->new;
$f-asset(
-value=>$assetId,
-label=>"Pick an Asset"
);
$f->button( $f->button(
-value=>"Click me!", -value=>"Click me!",
-extras=>qq|onClick="alert('Aaaaaaaggggghh!!!!')"| -extras=>qq|onClick="alert('Aaaaaaaggggghh!!!!')"|
@ -52,6 +56,10 @@ Package that makes HTML forms typed data and significantly reduces the code need
-options=>\%days, -options=>\%days,
-label=>"Which day?" -label=>"Which day?"
); );
$f->codearea(
-name=>"stylesheet",
-label=>"Stylesheet"
);
$f->combo( $f->combo(
-name=>"fruit", -name=>"fruit",
-options=>\%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 ] ) =head2 button ( value [, label, extras, subtext, defaultValue ] )

View file

@ -95,9 +95,10 @@ sub getOperations {
'editDatabaseLink' => 'WebGUI::Operation::DatabaseLink', 'editDatabaseLink' => 'WebGUI::Operation::DatabaseLink',
'editDatabaseLinkSave' => 'WebGUI::Operation::DatabaseLink', 'editDatabaseLinkSave' => 'WebGUI::Operation::DatabaseLink',
'listDatabaseLinks' => 'WebGUI::Operation::DatabaseLink', 'listDatabaseLinks' => 'WebGUI::Operation::DatabaseLink',
'richEditPageTree' => 'WebGUI::Operation::RichEdit', 'formAssetTree' => 'WebGUI::Operation::FormHelpers',
'richEditImageTree' => 'WebGUI::Operation::RichEdit', 'richEditPageTree' => 'WebGUI::Operation::FormHelpers',
'richEditViewThumbnail' => 'WebGUI::Operation::RichEdit', 'richEditImageTree' => 'WebGUI::Operation::FormHelpers',
'richEditViewThumbnail' => 'WebGUI::Operation::FormHelpers',
'manageUsersInGroup' => 'WebGUI::Operation::Group', 'manageUsersInGroup' => 'WebGUI::Operation::Group',
'deleteGroup' => 'WebGUI::Operation::Group', 'deleteGroup' => 'WebGUI::Operation::Group',
'deleteGroupConfirm' => 'WebGUI::Operation::Group', 'deleteGroupConfirm' => 'WebGUI::Operation::Group',

View file

@ -1,4 +1,4 @@
package WebGUI::Operation::RichEdit; package WebGUI::Operation::FormHelpers;
#------------------------------------------------------------------- #-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black Corporation. # WebGUI is Copyright 2001-2004 Plain Black Corporation.
@ -16,6 +16,34 @@ use WebGUI::HTMLForm;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::Style; 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,'<a href="'.$ancestor->getUrl("op=formAssetTree&classLimiter=".$session{form}{classLimiter}."&formId="
.$session{form}{formId}).'">'.$ancestor->get("menuTitle").'</a>');
}
my $output = '<p>'.join(" &gt; ", @crumb)."</p>\n";
my $children = $base->getLineage(["children"],{returnQuickReadObjects=>1});
foreach my $child (@{$children}) {
next unless $child->canView;
if ($child->get("className") =~ /^$session{form}{classLimiter}/) {
$output .= '<a href="#" onclick="window.opener.document.getElementById(\''.$session{form}{formId}
.'\').value=\''.$child->getId.'\';window.opener.document.getElementById(\''.
$session{form}{formId}.'_display\').value=\''.$child->get("title").'\';window.close();">(&bull;)</a> ';
} else {
$output .= "(&bull;) ";
}
$output .= '<a href="'.$child->getUrl("op=formAssetTree&classLimiter=".$session{form}{classLimiter}."&formId="
.$session{form}{formId}).'">'.$child->get("menuTitle").'</a>'."<br />\n";
}
$session{page}{useEmptyStyle} = 1;
return $output;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub www_richEditPageTree { sub www_richEditPageTree {

View file

@ -60,24 +60,21 @@ sub www_editSettings {
-value=>$session{setting}{companyURL} -value=>$session{setting}{companyURL}
); );
# content settings # content settings
my $pages = WebGUI::SQL->buildHashRef("select pageId,menuTitle from page order by menuTitle");
my %htmlFilter = ( my %htmlFilter = (
'none'=>$i18n->get(420), 'none'=>$i18n->get(420),
'most'=>$i18n->get(421), 'most'=>$i18n->get(421),
'javascript'=>$i18n->get(526), 'javascript'=>$i18n->get(526),
'all'=>$i18n->get(419) 'all'=>$i18n->get(419)
); );
$tabform->getTab("content")->selectList( $tabform->getTab("content")->asset(
-name=>"defaultPage", -name=>"defaultPage",
-options=>$pages,
-label=>$i18n->get(527), -label=>$i18n->get(527),
-value=>[$session{setting}{defaultPage}] -value=>$session{setting}{defaultPage}
); );
$tabform->getTab("content")->selectList( $tabform->getTab("content")->asset(
-name=>"notFoundPage", -name=>"notFoundPage",
-options=>$pages,
-label=>$i18n->get(141), -label=>$i18n->get(141),
-value=>[$session{setting}{notFoundPage}] -value=>$session{setting}{notFoundPage}
); );
$tabform->getTab("content")->text( $tabform->getTab("content")->text(
-name=>"urlExtension", -name=>"urlExtension",
@ -101,7 +98,7 @@ sub www_editSettings {
); );
$tabform->getTab("content")->yesNo( $tabform->getTab("content")->yesNo(
-name=>"metaDataEnabled", -name=>"metaDataEnabled",
-label=>$i18n->get("Enable Metadata ?", 'MetaData'), -label=>$i18n->get("Enable Metadata ?", 'Asset'),
-value=>$session{setting}{metaDataEnabled} -value=>$session{setting}{metaDataEnabled}
); );
# user interface settings # user interface settings
@ -202,12 +199,10 @@ sub www_editSettings {
-label=>$i18n->get(540), -label=>$i18n->get(540),
-value=>$session{setting}{karmaPerLogin} -value=>$session{setting}{karmaPerLogin}
); );
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($session{setting}{sessionTimeout});
$tabform->getTab("user")->interval( $tabform->getTab("user")->interval(
-name=>"sessionTimeout", -name=>"sessionTimeout",
-label=>$i18n->get(142), -label=>$i18n->get(142),
-intervalValue=>$interval, -value=>$session{setting}{sessionTimeout}
-unitsValue=>$units
); );
$tabform->getTab("user")->yesNo( $tabform->getTab("user")->yesNo(
-name=>"selfDeactivation", -name=>"selfDeactivation",
@ -221,9 +216,9 @@ sub www_editSettings {
); );
$tabform->getTab("user")->yesNo( $tabform->getTab("user")->yesNo(
-name=>"passiveProfilingEnabled", -name=>"passiveProfilingEnabled",
-label=>$i18n->get("Enable passive profiling ?", 'MetaData'), -label=>$i18n->get("Enable passive profiling ?", 'Asset'),
-value=>$session{setting}{passiveProfilingEnabled}, -value=>$session{setting}{passiveProfilingEnabled},
-extras=>' onChange="alert(\''.$i18n->get("Illegal Warning","MetaData").'\')" ' -extras=>' onChange="alert(\''.$i18n->get("Illegal Warning","Asset").'\')" '
); );
# auth settings # auth settings
WebGUI::Style::setScript($session{config}{extrasURL}."/swapLayers.js",{language=>"Javascript"}); WebGUI::Style::setScript($session{config}{extrasURL}."/swapLayers.js",{language=>"Javascript"});