Skip to content

Commit

Permalink
Item13897: Commiting modified contrib files.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Mar 4, 2016
1 parent f7b3e6b commit 7255248
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 206 deletions.
60 changes: 30 additions & 30 deletions CommentPlugin/lib/Foswiki/Plugins/CommentPlugin.pm
Expand Up @@ -3,10 +3,12 @@
# See Plugin topic for history and plugin information

package Foswiki::Plugins::CommentPlugin;
use v5.14;

use strict;
use warnings;
use Assert;
use Try::Tiny;
use Foswiki::Exception;

use Foswiki::Func ();
use Foswiki::Plugins ();
Expand Down Expand Up @@ -132,11 +134,11 @@ sub _restSave {
$response->print("No such web '$web'");
}
else {
throw Foswiki::OopsException(
'oopsattention',
status => 403,
def => 'web_not_found',
params => [ $web, "$web.$topic" ]
Foswiki::OopsException->throw(
template => 'oopsattention',
status => 403,
def => 'web_not_found',
params => [ $web, "$web.$topic" ]
);
}
}
Expand All @@ -156,11 +158,11 @@ sub _restSave {
$response->print("No such topic '$topic'");
}
else {
throw Foswiki::OopsException(
'oopsattention',
status => 403,
def => 'invalid_topic_parameter',
params => [ "$origTopic", 'comment_target' ]
Foswiki::OopsException->throw(
template => 'oopsattention',
status => 403,
def => 'invalid_topic_parameter',
params => [ "$origTopic", 'comment_target' ]
);
}
}
Expand Down Expand Up @@ -234,37 +236,35 @@ sub _restSave {
Foswiki::Func::getScriptUrl( $web, $topic, 'view' ) );
}
}
catch Foswiki::AccessControlException with {
my $e = shift;
if ($isXHR) {
$response->header( -status => 404 );
$response->print( $e->stringify );
}
else {
$e->throw();
}
}
case {
catch {
my $e = $_;
if ( ref($e) ) {

#code
# Redirect already requested to clear the endpoint
if ( $e->stringify =~ 'restauth-redirect' ) {
$query->param( redirectto => '' );
if ( $e->isa('Foswiki::AccessControlException') ) {
if ($isXHR) {
$response->header( -status => 404 );
$response->print( $e->stringify );
}
else {
$e->rethrow;
}
}
else {
Foswiki::Exception::Fatal->rethrow($e);
# Redirect already requested to clear the endpoint
if ( $e->stringify =~ 'restauth-redirect' ) {
$query->param( redirectto => '' );
}
else {
$e->rethrow;
}
}
}
else {

if ($isXHR) {
$response->header( -status => 500 );
$response->print($e);
}
else {
Foswiki::Exception::Fatal->rehtrow($e);
Foswiki::Exception::Fatal->rethrow($e);
}

}
Expand Down
29 changes: 15 additions & 14 deletions JQueryPlugin/lib/Foswiki/Form/Color.pm
@@ -1,18 +1,16 @@
# See bottom of file for license and copyright information
package Foswiki::Form::Color;
use Foswiki::Form::FieldDefinition;
our @ISA = qw( Foswiki::Form::FieldDefinition );
use v5.14;

use Foswiki::Plugins::JQueryPlugin ();

use strict;
use warnings;
use Moo;
use namespace::clean;
extends qw( Foswiki::Form::FieldDefinition );

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
sub BUILD {
my $this = shift;
Foswiki::Plugins::JQueryPlugin::createPlugin("farbtastic");
return $this;
}

sub renderForEdit {
Expand All @@ -35,28 +33,31 @@ sub renderForEdit {

my $field = CGI::textfield(
-class => $this->cssClasses('foswikiInputField jqFarbtastic'),
-name => $this->{name},
-name => $this->name,
-size => 11,
-override => 1,
-value => $value,
-id => $this->{name},
-id => $this->name,
);

return ( '', $field );
}

sub renderForDisplay {
around renderForDisplay => sub {
my $orig = shift;
my ( $this, $format, $value, $attrs ) = @_;

Foswiki::Plugins::JQueryPlugin::createPlugin("farbtastic");

my $displayValue =
"<span class='jqFarbtasticFG' style='background-color:$value;width:$this->{size}em'>$value</span>";
"<span class='jqFarbtasticFG' style='background-color:$value;width:"
. $this->size
. "em'>$value</span>";
$format =~ s/\$value\(display\)/$displayValue/g;
$format =~ s/\$value/$value/g;

return $this->SUPER::renderForDisplay( $format, $value, $attrs );
}
return $orig->( $this, $format, $value, $attrs );
};

1;
__END__
Expand Down
99 changes: 46 additions & 53 deletions JQueryPlugin/lib/Foswiki/Form/Rating.pm
@@ -1,64 +1,51 @@
# See bottom of file for license and copyright information
package Foswiki::Form::Rating;
use v5.14;

use strict;
use warnings;
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::Func ();
use JSON ();

use Foswiki::Form::ListFieldDefinition ();
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::Func ();
use JSON ();
use Moo;
use namespace::clean;
extends qw(Foswiki::Form::ListFieldDefinition);

our @ISA = ('Foswiki::Form::ListFieldDefinition');
has json => (
is => 'rw',
lazy => 1,
default => sub { JSON->new->allow_nonref },
);

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
sub BUILD {
my $this = shift;

my $options = $this->getOptions();
if ( $options && @$options ) {
$this->{size} = scalar(@$options);
$this->size( scalar(@$options) );
}
else {
$this->{size} ||= 0;
$this->{size} =~ s/\D//g;
$this->{size} ||= 0;
$this->{size} = 5 if ( $this->{size} < 1 );
}

return $this;
}

sub finish {
my $this = shift;
$this->SUPER::finish();
undef $this->{valueMap};
undef $this->{json};
}

sub json {
my $this = shift;

unless ( $this->{json} ) {
$this->{json} = JSON->new->allow_nonref;
my $size = $this->size || 0;
$size =~ s/\D//g;
$size ||= 0;
$size = 5 if ( $size < 1 );
$this->size($size);
}

return $this->{json};
}

sub getOptions {
around getOptions => sub {
my $orig = shift;
my $this = shift;

my $options = $this->{_options};
my $options = $this->_options;
return $options if $options;
$options = $this->SUPER::getOptions();
$options = $orig->($this);

unless ( $this->{valueMap} ) {
unless ( $this->valueMap ) {

# 2.0 does the value map for you in the superclass.
if ( $this->{type} =~ m/\+values/ ) {
$this->{valueMap} = ();
$this->{_options} = ();
if ( $this->type =~ m/\+values/ ) {
$this->clear_valueMap;
$this->_options( [] );
my $str;
foreach my $val (@$options) {
if ( $val =~ m/^(.*?[^\\])=(.*)$/ ) {
Expand All @@ -70,15 +57,15 @@ sub getOptions {
$str = $val;
}
$str =~ s/%([\da-f]{2})/chr(hex($1))/gei;
$this->{valueMap}{$val} = $str;
push @{ $this->{_options} }, $val;
$this->valueMap->{$val} = $str;
push @{ $this->_options }, $val;
}
$options = $this->{_options};
$options = $this->_options;
}
}

return $options;
}
};

sub getDataValues {
my $this = shift;
Expand All @@ -87,10 +74,10 @@ sub getDataValues {
my @vals = ();

foreach my $val (@$options) {
if ( $this->{type} =~ m/\+values/
&& defined( $this->{valueMap}{$val} ) )
if ( $this->type =~ m/\+values/
&& defined( $this->valueMap->{$val} ) )
{
push @vals, { $this->{valueMap}{$val} => $val };
push @vals, { $this->valueMap->{$val} => $val };
}
else {
push @vals, $val;
Expand All @@ -107,9 +94,12 @@ sub renderForEdit {
Foswiki::Plugins::JQueryPlugin::createPlugin("stars");

my $result =
"<input type='hidden' autocomplete='off' name='$this->{name}' value='$value' class='jqStars {$this->{attributes}}' "
"<input type='hidden' autocomplete='off' name='"
. $this->name
. "' value='$value' class='jqStars {"
. $this->attributes . "}' "
. "data-num-stars='"
. $this->{size} . "' "
. $this->size . "' "
. $this->getDataValues() . ">";

return ( '', $result );
Expand All @@ -121,7 +111,7 @@ sub renderForDisplay {
$format =~ s/\$value\(display\)/$this->renderDisplayValue($value)/ge;
$format =~ s/\$value/$value/g;

return $this->SUPER::renderForDisplay( $format, $value, $attrs );
return $orig->( $this, $format, $value, $attrs );
}

sub renderDisplayValue {
Expand All @@ -132,9 +122,12 @@ sub renderDisplayValue {
my @htmlAttrs = ();

return
"<input type='hidden' disabled autocomplete='off' name='$this->{name}' value='$value' class='jqStars {$this->{attributes}}' "
"<input type='hidden' disabled autocomplete='off' name='"
. $this->name
. "' value='$value' class='jqStars {"
. $this->attributes . "}' "
. "data-num-stars='"
. $this->{size} . "' "
. $this->size . "' "
. $this->getDataValues() . ">";
}

Expand Down

0 comments on commit 7255248

Please sign in to comment.