Some little changes...

This commit is contained in:
Xavier Guimard 2010-01-04 13:28:10 +00:00
parent 8102f72d50
commit 81377639b2
4 changed files with 95 additions and 53 deletions

View File

@ -72,8 +72,13 @@ sub menu {
return return
'<ul class="simpleTree">' '<ul class="simpleTree">'
. $self->li( 'root', 'root' ) . $self->li( 'root', 'root' )
. $self->span( 'root', "Configuration $self->{cfgNum}", . $self->span(
$self->{cfgNum}, 'cfgDatas', 'default' ) id => 'root',
text => "Configuration $self->{cfgNum}",
data => $self->{cfgNum},
js => 'cfgDatas',
help => 'default'
)
. '<ul>' . '<ul>'
. $self->node() . $self->node()
. '</ul></li></ul>'; . '</ul></li></ul>';

View File

@ -5,6 +5,7 @@
# Configuration tree builder # Configuration tree builder
package Lemonldap::NG::Manager::Downloader; package Lemonldap::NG::Manager::Downloader;
use strict;
use MIME::Base64; use MIME::Base64;
# TODO # TODO
@ -43,14 +44,14 @@ sub node {
# subnode is an ajax subnode # subnode is an ajax subnode
if ( $flag =~ /^(c?)n$/ ) { if ( $flag =~ /^(c?)n$/ ) {
$res .= $self->ajaxNode( $res .= $self->ajaxNode(
( $1 ? $target : "$node/$target" ), id => ( $1 ? $target : "$node/$target" ),
"$target", text => "$target",
"node=$node/$target", param => "node=$node/$target",
$tmp->{$target}->{_help} || $help, help => $tmp->{$target}->{_help} || $help,
$tmp->{$target}->{_js}, js => $tmp->{$target}->{_js},
'', data => '',
0, noT => 0,
$tmp->{$target}->{_call} call => $tmp->{$target}->{_call}
); );
next; next;
} }
@ -64,9 +65,11 @@ sub node {
if ( ref( $tmp->{$target} ) ) { if ( ref( $tmp->{$target} ) ) {
$res .= $self->li( "$node/$target", "closed" ) $res .= $self->li( "$node/$target", "closed" )
. $self->span( . $self->span(
"$node/$target", $target, '', id => "$node/$target",
$tmp->{$target}->{_js}, text => $target,
$tmp->{$target}->{_help} || $help data => '',
js => $tmp->{$target}->{_js},
help => $tmp->{$target}->{_help} || $help
) )
. "<ul>" . "<ul>"
. $self->node("$node/$target") . $self->node("$node/$target")
@ -120,8 +123,14 @@ sub confNode {
return unless ($h); return unless ($h);
foreach ( sort keys %$h ) { foreach ( sort keys %$h ) {
if ( ref($h) ) { if ( ref($h) ) {
$res .= $self->ajaxNode( "$target/$_", $_, $res .= $self->ajaxNode(
"node=$node/$_\&amp;key=$_", $help, $js, undef, 1 ); id => "$target/$_",
text => $_,
param => "node=$node/$_\&amp;key=$_",
help => $help,
js => $js,
noT => 1
);
} }
else { else {
$res .= $res .=
@ -155,9 +164,15 @@ sub confNode {
# Here, "notranslate" is set to true : hash values must not be # Here, "notranslate" is set to true : hash values must not be
# translated # translated
$res .= $res .= $self->li($id)
$self->li($id) . $self->span(
. $self->span( $id, "$_", $h->{$_}, $js, $help, 1 ) . "</li>"; id => $id,
text => "$_",
data => $h->{$_},
js => $js,
help => $help,
noT => 1
) . "</li>";
} }
} }
} }
@ -188,9 +203,14 @@ sub confNode {
$self->lmLog( "Type $type unknown", 'warn' ) unless ( defined $h ); $self->lmLog( "Type $type unknown", 'warn' ) unless ( defined $h );
} }
if ( ref($h) ) { if ( ref($h) ) {
$res .= $res .= $self->li( "$target", "closed" )
$self->li( "$target", "closed" ) . $self->span(
. $self->span( "$target", $text, '', $js, $help ) . "<ul>"; id => "$target",
text => $text,
data => '',
js => $js,
help => $help
) . "<ul>";
foreach ( sort keys %$h ) { foreach ( sort keys %$h ) {
if ( ref( $h->{$_} ) ) { if ( ref( $h->{$_} ) ) {
$res .= $res .=
@ -198,18 +218,28 @@ sub confNode {
} }
else { else {
my $id = "$target/$_"; my $id = "$target/$_";
$res .= $res .= $self->li($id)
$self->li($id) . $self->span(
. $self->span( $id, $_, $h->{$_}, $js, $help ) . "</li>"; id => $id,
text => $_,
data => $h->{$_},
js => $js,
help => $help
) . "</li>";
} }
} }
$res .= '</ul></li>'; $res .= '</ul></li>';
} }
else { else {
my $id = "$target"; my $id = "$target";
$res .= $res .= $self->li($id)
$self->li($id) . $self->span(
. $self->span( $id, $text, $h, $js, $help ) . "</li>"; id => $id,
text => $text,
data => $h,
js => $js,
help => $help
) . "</li>";
} }
} }
return $res; return $res;
@ -354,17 +384,18 @@ sub confObj {
# @param $noT Optional flag to block translation # @param $noT Optional flag to block translation
# @return HTML string # @return HTML string
sub ajaxNode { sub ajaxNode {
my ( $self, $id, $text, $param, $help, $js, $data, $noT, $call ) = @_; my ( $self, %args ) = @_;
$param .= "&amp;cfgNum=$self->{cfgNum}"; $args{param} .= "&amp;cfgNum=$self->{cfgNum}";
return return $self->li( $args{id} ) . $self->span(%args)
$self->li($id)
. $self->span( $id, $text, $data, $js, $help, $noT )
. "<ul class=\"ajax\">"
. $self->li("sub_$id")
. ".{url:$ENV{SCRIPT_NAME}?$param"
# . ( $js ? ",js:$js" : '' ) # . $self->span( $id, $text, $data, $js, $help, $noT )
. ( $call ? ",call:$call" : '' ) . "}</li></ul></li>\n"; . "<ul class=\"ajax\">"
. $self->li("sub_$args{id}")
. ".{url:$ENV{SCRIPT_NAME}?$args{param}"
. ( $args{deferedJs} ? ",js:$args{deferedJs}" : '' )
. ( $args{call} ? ",call:$args{call}" : '' )
. "}</li></ul></li>\n";
} }
## @method protected string span(string id,string text,string param,string help,string js,string data,boolean noT) ## @method protected string span(string id,string text,string param,string help,string js,string data,boolean noT)
@ -378,22 +409,23 @@ sub ajaxNode {
# @param $noT Optional flag to block translation # @param $noT Optional flag to block translation
# @return HTML string # @return HTML string
sub span { sub span {
my ( $self, $id, $text, $data, $js, $help, $noT ) = @_; my ( $self, %args ) = @_;
use Carp qw(cluck);
cluck('dd') if ( $js eq 'default' ); #my ( $self, $id, $text, $data, $js, $help, $noT ) = @_;
my $tmp = $text; my $tmp = $args{text};
$data = '' unless ( defined $data ); $args{data} = '' unless ( defined $args{data} );
$js ||= "none"; $args{js} ||= "none";
$id = "li_" . encode_base64( $id, '' ); $args{id} = "li_" . encode_base64( $args{id}, '' );
$id =~ s/(=*)$/length($1)/e; $args{id} =~ s/(=*)$/length($1)/e;
$js .= "('$id')" unless ( $js =~ /\(/ ); $args{js} .= "('$args{id}')" unless ( $args{js} =~ /\(/ );
$data =~ s/"/&#39;/g; $args{data} =~ s/"/&#39;/g;
$tmp =~ s/"/&#39;/g; $tmp =~ s/"/&#39;/g;
$text = join ' ', map { $self->translate($_) } split /\s+/, $text $args{text} = join ' ', map { $self->translate($_) } split /\s+/,
unless ($noT); $args{text}
$text = $self->escapeHTML($text); unless ( $args{noT} );
$args{text} = $self->escapeHTML( $args{text} );
return return
"<span name=\"$tmp\" id=\"text_$id\" onclick=\"$js\" help=\"$help\" value=\"$data\">$text</span> "<span name=\"$tmp\" id=\"text_$args{id}\" onclick=\"$args{js}\" help=\"$args{help}\" value=\"$args{data}\">$args{text}</span>
"; ";
} }

View File

@ -90,6 +90,7 @@ sub confUpload {
$errors->{errors}->{$name} = $m || $test->{keyMsgFail}; $errors->{errors}->{$name} = $m || $test->{keyMsgFail};
next; next;
} }
$errors->{warnings}->{$name} = $m if($m);
} }
if ( $test->{test} ) { if ( $test->{test} ) {
( $res, $m ) = $self->applyTest( $test->{test}, $value ); ( $res, $m ) = $self->applyTest( $test->{test}, $value );
@ -97,6 +98,7 @@ sub confUpload {
$errors->{errors}->{$name} = $m || $test->{msgFail}; $errors->{errors}->{$name} = $m || $test->{msgFail};
next; next;
} }
$errors->{warnings}->{$name} = $m if($m);
} }
# 1.3.1.2 Tests that return a warning # 1.3.1.2 Tests that return a warning

View File

@ -212,13 +212,16 @@ sub struct {
# Returns the tests to do with the datas uploaded. # Returns the tests to do with the datas uploaded.
# @return hashref # @return hashref
sub testStruct { sub testStruct {
my $safe = Safe->new();
my $assignTest = qr/(?<=[^=<!>\?])=(?![=~])/; my $assignTest = qr/(?<=[^=<!>\?])=(?![=~])/;
my $assignMsg = 'containsAnAssignment'; my $assignMsg = 'containsAnAssignment';
my $perlExpr = sub { my $perlExpr = sub {
my $e = shift; my $e = shift;
eval "use strict;$e"; $safe->reval($e,1);
return 1 unless($@);
return 1 if ( $@ =~ /Global symbol "\$.*requires explicit package/ ); return 1 if ( $@ =~ /Global symbol "\$.*requires explicit package/ );
return ( $@ ? ( 0, $@ ) : 1 ); return (1, "Function \"<b>$1</b>\" must be declared in customFunctions") if ( $@ =~ /Bareword "(.*?)" not allowed while "strict subs"/ );
return ( 0, $@ );
}; };
my $boolean = { test => qr/^(?:0|1)?$/, msgFail => 'Value must be 0 or 1' }; my $boolean = { test => qr/^(?:0|1)?$/, msgFail => 'Value must be 0 or 1' };
my $pcre = sub { my $pcre = sub {