Set up filtering on title, menuTitle and URL. This is done via "around".
This commit is contained in:
parent
0c4710c4ad
commit
0e90ad00b8
3 changed files with 74 additions and 61 deletions
|
|
@ -50,6 +50,16 @@ property title => (
|
||||||
fieldType => 'text',
|
fieldType => 'text',
|
||||||
defaultValue => 'Untitled',
|
defaultValue => 'Untitled',
|
||||||
);
|
);
|
||||||
|
around title => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $self = shift;
|
||||||
|
if (@_ > 1) {
|
||||||
|
my $title = $_[0];
|
||||||
|
$title = 'Untitled' if $title eq '';
|
||||||
|
$title = WebGUI::HTML::filter($title, 'all');
|
||||||
|
}
|
||||||
|
$self->$orig(@_);
|
||||||
|
};
|
||||||
property menuTitle => (
|
property menuTitle => (
|
||||||
tab => "properties",
|
tab => "properties",
|
||||||
label => ['411','Asset'],
|
label => ['411','Asset'],
|
||||||
|
|
@ -58,6 +68,16 @@ property menuTitle => (
|
||||||
fieldType => 'text',
|
fieldType => 'text',
|
||||||
defaultValue => 'Untitled',
|
defaultValue => 'Untitled',
|
||||||
);
|
);
|
||||||
|
around menuTitle => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $self = shift;
|
||||||
|
if (@_ > 1) {
|
||||||
|
my $title = $_[0];
|
||||||
|
$title = $self->title if $title eq '';
|
||||||
|
$title = WebGUI::HTML::filter($title, 'all');
|
||||||
|
}
|
||||||
|
$self->$orig(@_);
|
||||||
|
};
|
||||||
property url => (
|
property url => (
|
||||||
tab => "properties",
|
tab => "properties",
|
||||||
label => ['104','Asset'],
|
label => ['104','Asset'],
|
||||||
|
|
@ -66,6 +86,15 @@ property url => (
|
||||||
fieldType => 'text',
|
fieldType => 'text',
|
||||||
defaultValue => sub { return $_[0]->getId; },
|
defaultValue => sub { return $_[0]->getId; },
|
||||||
);
|
);
|
||||||
|
around url => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $self = shift;
|
||||||
|
if (@_ > 1) {
|
||||||
|
my $url = $_[0];
|
||||||
|
$url = $self->fixUrl($url);
|
||||||
|
}
|
||||||
|
$self->$orig(@_);
|
||||||
|
};
|
||||||
property isHidden => (
|
property isHidden => (
|
||||||
tab => "display",
|
tab => "display",
|
||||||
label => ['886','Asset'],
|
label => ['886','Asset'],
|
||||||
|
|
@ -133,6 +162,22 @@ property extraHeadTags => (
|
||||||
defaultValue => undef,
|
defaultValue => undef,
|
||||||
customDrawMethod=> 'drawExtraHeadTags',
|
customDrawMethod=> 'drawExtraHeadTags',
|
||||||
);
|
);
|
||||||
|
around extraHeadTags => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $self = shift;
|
||||||
|
if (@_ > 1) {
|
||||||
|
my $unpacked = $_[0];
|
||||||
|
my $packed = $unpacked; ##Undo magic aliasing since a reference is passed below
|
||||||
|
HTML::Packer::minify( \$packed, {
|
||||||
|
remove_comments => 1,
|
||||||
|
remove_newlines => 1,
|
||||||
|
do_javascript => "shrink",
|
||||||
|
do_stylesheet => "minify",
|
||||||
|
} );
|
||||||
|
$self->extraHeadTagsPacked($packed);
|
||||||
|
}
|
||||||
|
$self->$orig(@_);
|
||||||
|
};
|
||||||
property extraHeadTagsPacked => (
|
property extraHeadTagsPacked => (
|
||||||
fieldType => 'hidden',
|
fieldType => 'hidden',
|
||||||
defaultValue => undef,
|
defaultValue => undef,
|
||||||
|
|
@ -495,21 +540,6 @@ If specified, stores it, but also updates extraHeadTagsPacked with the packed ve
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub extraHeadTags {
|
|
||||||
my ( $self, $unpacked ) = @_;
|
|
||||||
if (@_ > 1) {
|
|
||||||
my $packed = $unpacked;
|
|
||||||
HTML::Packer::minify( \$packed, {
|
|
||||||
remove_comments => 1,
|
|
||||||
remove_newlines => 1,
|
|
||||||
do_javascript => "shrink",
|
|
||||||
do_stylesheet => "minify",
|
|
||||||
} );
|
|
||||||
$self->extraHeadTagsPacked($packed);
|
|
||||||
}
|
|
||||||
return $self->next::method($unpacked);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 fixUrl ( [value] )
|
=head2 fixUrl ( [value] )
|
||||||
|
|
@ -1462,6 +1492,18 @@ sub logView {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 title ( [value] )
|
||||||
|
|
||||||
|
Returns the title of the asset.
|
||||||
|
|
||||||
|
=head3 value
|
||||||
|
|
||||||
|
If specified this value will be used to set the title after it goes through some validation checking.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 menuTitle ( [value] )
|
=head2 menuTitle ( [value] )
|
||||||
|
|
||||||
Returns the menuTitle of the asset, which is used in navigations.
|
Returns the menuTitle of the asset, which is used in navigations.
|
||||||
|
|
@ -1472,17 +1514,6 @@ If specified this value will be used to set the title after it goes through some
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub menuTitle {
|
|
||||||
my ($self, $title) = @_;
|
|
||||||
if (@_ > 1) {
|
|
||||||
if ($title eq "") {
|
|
||||||
$title = $self->title;
|
|
||||||
}
|
|
||||||
$title = WebGUI::HTML::filter($title, 'all');
|
|
||||||
}
|
|
||||||
return $self->next::method($title);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 new ( session, assetId [, className, revisionDate ] )
|
=head2 new ( session, assetId [, className, revisionDate ] )
|
||||||
|
|
@ -1723,7 +1754,7 @@ The asset's id
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub newPending {
|
sub newPending {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $assetId = shift;
|
my $assetId = shift;
|
||||||
croak "First parameter to newPending needs to be a WebGUI::Session object"
|
croak "First parameter to newPending needs to be a WebGUI::Session object"
|
||||||
|
|
@ -2167,30 +2198,6 @@ sub setSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 title ( [value] )
|
|
||||||
|
|
||||||
Returns the title of the asset.
|
|
||||||
|
|
||||||
=head3 value
|
|
||||||
|
|
||||||
If specified this value will be used to set the title after it goes through some validation checking.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub title {
|
|
||||||
my ($self, $title) = @_;
|
|
||||||
if (@_ > 1) {
|
|
||||||
if ($title eq "") {
|
|
||||||
$title = 'Untitled';
|
|
||||||
}
|
|
||||||
$title = WebGUI::HTML::filter($title, 'all');
|
|
||||||
}
|
|
||||||
return $self->next::method($title);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 toggleToolbar ( )
|
=head2 toggleToolbar ( )
|
||||||
|
|
@ -2314,18 +2321,8 @@ The new value to set the URL to.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub url {
|
|
||||||
my ($self, $url) = @_;
|
|
||||||
if (@_ > 1) {
|
|
||||||
$url = $self->fixUrl($url);
|
|
||||||
}
|
|
||||||
return $self->next::method($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
=head2 urlExists ( session, url [, options] )
|
=head2 urlExists ( session, url [, options] )
|
||||||
|
|
||||||
Returns true if the asset URL is used within the system. This is a class method.
|
Returns true if the asset URL is used within the system. This is a class method.
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,10 @@ A property is a special object attribute with it's type constraints set by
|
||||||
HTML form properties, such as base type (Text, Integer, Float, SelectList),
|
HTML form properties, such as base type (Text, Integer, Float, SelectList),
|
||||||
default value, value, etc.
|
default value, value, etc.
|
||||||
|
|
||||||
|
By default, the Moose option C<is => 'rw'> is added to all properties to make
|
||||||
|
sure the accessors are generated. If you want to prevent that from happening,
|
||||||
|
pass an explicit C<is => 'ro'> along with %options.
|
||||||
|
|
||||||
=head3 $name
|
=head3 $name
|
||||||
|
|
||||||
The name of the property.
|
The name of the property.
|
||||||
|
|
|
||||||
|
|
@ -91,12 +91,21 @@ my $called_getProperties;
|
||||||
property 'property2' => (
|
property 'property2' => (
|
||||||
fieldType => 'text',
|
fieldType => 'text',
|
||||||
label => 'property2',
|
label => 'property2',
|
||||||
|
writer => '_set_property_2',
|
||||||
);
|
);
|
||||||
property 'property1' => (
|
property 'property1' => (
|
||||||
fieldType => 'text',
|
fieldType => 'text',
|
||||||
label => 'property1',
|
label => 'property1',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $filter2 = 0;
|
||||||
|
around 'property2' => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $self = shift;
|
||||||
|
$filter2 = 1;
|
||||||
|
$self->$orig(@_);
|
||||||
|
};
|
||||||
|
|
||||||
my $written;
|
my $written;
|
||||||
sub write {
|
sub write {
|
||||||
$written++;
|
$written++;
|
||||||
|
|
@ -122,6 +131,9 @@ my $called_getProperties;
|
||||||
$object->update;
|
$object->update;
|
||||||
::is $written, 1, 'update calls write';
|
::is $written, 1, 'update calls write';
|
||||||
|
|
||||||
|
$object->property2('foo');
|
||||||
|
::is $filter2, 1, 'around modifier works';
|
||||||
|
|
||||||
::is $object->tableName, 'asset', 'tableName set for object';
|
::is $object->tableName, 'asset', 'tableName set for object';
|
||||||
$object->tableName('not asset');
|
$object->tableName('not asset');
|
||||||
::is $object->tableName, 'asset', 'tableName may not be set from the object';
|
::is $object->tableName, 'asset', 'tableName may not be set from the object';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue