| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::DevexpressHelpers::Helpers; |
|
2
|
|
|
|
|
|
|
$Mojolicious::Plugin::DevexpressHelpers::Helpers::VERSION = '1.151250'; |
|
3
|
3
|
|
|
3
|
|
14
|
use Modern::Perl; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
15
|
|
|
4
|
3
|
|
|
3
|
|
611
|
use Mojo::ByteStream; |
|
|
3
|
|
|
|
|
39646
|
|
|
|
3
|
|
|
|
|
105
|
|
|
5
|
3
|
|
|
3
|
|
1344
|
use MojoX::AlmostJSON qw(encode_json); |
|
|
3
|
|
|
|
|
6262
|
|
|
|
3
|
|
|
|
|
1822
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub out{ |
|
8
|
6
|
|
|
6
|
1
|
8
|
my $tag = shift; |
|
9
|
6
|
|
|
|
|
26
|
return Mojo::ByteStream->new($tag); |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new{ |
|
13
|
3
|
|
|
3
|
1
|
5
|
my $class = shift; |
|
14
|
3
|
|
|
|
|
14
|
my $self = bless { |
|
15
|
|
|
|
|
|
|
next_id => 1, |
|
16
|
|
|
|
|
|
|
bindings => '', |
|
17
|
|
|
|
|
|
|
}, $class; |
|
18
|
3
|
|
|
|
|
18
|
return $self; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub add_binding{ |
|
22
|
3
|
|
|
3
|
1
|
27
|
my $self = shift; |
|
23
|
3
|
|
|
|
|
9
|
$self->{bindings} .= join "\n", @_; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub next_id{ |
|
27
|
3
|
|
|
3
|
1
|
26
|
my $self = shift; |
|
28
|
3
|
|
|
|
|
21
|
return "dxctl".($self->{next_id}++); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new_id{ |
|
32
|
3
|
|
|
3
|
1
|
6
|
my ($c, $attrs) = @_; |
|
33
|
|
|
|
|
|
|
#should compute a new uniq id |
|
34
|
3
|
|
|
|
|
8
|
$c->stash('dxHelper')->next_id; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub dxbind{ |
|
38
|
3
|
|
|
3
|
1
|
6
|
my ($c, $control, $id, $attrs, $extensions) = @_; |
|
39
|
|
|
|
|
|
|
#should return html code to be associated to the control |
|
40
|
3
|
|
|
|
|
9
|
my $binding = '$("#'.$id.'").'.$control.'({'; |
|
41
|
3
|
|
|
|
|
5
|
my @options; |
|
42
|
3
|
|
|
|
|
19
|
for my $k ( sort keys %$attrs){ |
|
43
|
7
|
|
|
|
|
29
|
my $v = $attrs->{$k}; |
|
44
|
7
|
100
|
|
|
|
29
|
if(ref($v) eq 'SCALAR'){ |
|
|
|
50
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#unref protected scalar |
|
46
|
1
|
|
|
|
|
1
|
$v = $$v; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
elsif ($v!~/^\s*(?:function\s*\()/) { |
|
49
|
6
|
|
|
|
|
16
|
$v = encode_json $v; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
7
|
|
|
|
|
240
|
push @options, "$k: $v"; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
3
|
|
|
|
|
9
|
$binding .= join ",\n", @options; |
|
54
|
3
|
|
|
|
|
4
|
$binding .= '});'; |
|
55
|
|
|
|
|
|
|
#append some extensions (eg: dxdatagrid) |
|
56
|
3
|
100
|
|
|
|
8
|
$binding .= join ";\n", @$extensions if defined $extensions; |
|
57
|
3
|
|
|
|
|
10
|
$c->stash('dxHelper')->add_binding($binding); |
|
58
|
|
|
|
|
|
|
#TODO: Possible extension: may add html attributs or sub content from special attributs |
|
59
|
3
|
|
|
|
|
15
|
out ''; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub parse_attributs{ |
|
64
|
3
|
|
|
3
|
1
|
6
|
my $c = shift; |
|
65
|
3
|
|
|
|
|
5
|
my @implicit_args = @{shift()}; |
|
|
3
|
|
|
|
|
9
|
|
|
66
|
3
|
|
|
|
|
4
|
my %attrs; |
|
67
|
|
|
|
|
|
|
IMPLICIT_ARGUMENT: |
|
68
|
3
|
|
100
|
|
|
30
|
while(defined($_[0]) and ref($_[0]) eq ''){ |
|
69
|
5
|
|
|
|
|
26
|
$attrs{ shift @implicit_args } = shift @_; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
3
|
100
|
|
|
|
9
|
if(my $args = shift){ |
|
72
|
2
|
50
|
|
|
|
9
|
if(ref($args) eq 'HASH'){ |
|
73
|
|
|
|
|
|
|
NAMED_ARGUMENT: |
|
74
|
2
|
|
|
|
|
8
|
while(my($k,$v)=each %$args){ |
|
75
|
2
|
|
|
|
|
8
|
$attrs{$k} = $v; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
3
|
|
|
|
|
8
|
return \%attrs; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub dxbutton { |
|
84
|
2
|
|
|
2
|
1
|
6375
|
my $c = shift; |
|
85
|
2
|
|
|
|
|
11
|
my $attrs = parse_attributs( $c, [qw(text onClick type)], @_ ); |
|
86
|
2
|
|
|
|
|
8
|
my $id = new_id( $c, $attrs ); |
|
87
|
2
|
|
|
|
|
8
|
dxbind( $c, 'dxButton' => $id => $attrs); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub dxdatagrid{ |
|
92
|
1
|
|
|
1
|
1
|
3416
|
my $c = shift; |
|
93
|
1
|
|
|
|
|
4
|
my $attrs = parse_attributs( $c, [qw(dataSource)], @_ ); |
|
94
|
1
|
|
|
|
|
3
|
my $id = new_id( $c, $attrs ); |
|
95
|
1
|
|
|
|
|
2
|
my @extensions; |
|
96
|
|
|
|
|
|
|
#dxbind( $c, 'dxDataGrid' => $id => $attrs, [ $dataSource ]); |
|
97
|
1
|
50
|
|
|
|
3
|
if (ref($attrs->{dataSource}) eq '') { |
|
98
|
1
|
|
|
|
|
20
|
my $dataSource = delete $attrs->{dataSource}; |
|
99
|
|
|
|
|
|
|
#push @extensions, '$.getJSON("' . $dataSource . '",function(data){$("#'.$id.'").dxDataGrid({ dataSource: data });});'; |
|
100
|
|
|
|
|
|
|
#$attrs->{dataSource} = \'[]'; #protect string to be "stringified" within dxbind |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#\"" is to protect string to be "stringified" within dxbind |
|
103
|
1
|
|
|
|
|
4
|
$attrs->{dataSource} = \"{store:{type:'odata',url:'$dataSource'}}"; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
1
|
|
|
|
|
5
|
dxbind( $c, 'dxDataGrid' => $id => $attrs, \@extensions); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub dxbuild { |
|
110
|
3
|
|
|
3
|
1
|
3214
|
my $c = shift; |
|
111
|
3
|
50
|
|
|
|
10
|
my $dxhelper = $c->stash('dxHelper') or return; |
|
112
|
3
|
50
|
|
|
|
35
|
if($dxhelper->{bindings}){ |
|
113
|
3
|
|
|
|
|
14
|
out ''; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |