blib/lib/DBIx/ReportBuilder/Render/Edit.pm untested

filter: Statementstmt 0.0% 0 / 107 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 35 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 18 totaltotal 0.0% 0 / 223 CC 12 SCAR 20.8
CC
12
Cov
0%
clause
20.0
twigTable
20.0
part
12.0
CRAP 8.0
1 # $File: //member/autrijus/DBIx-ReportBuilder/lib/DBIx/ReportBuilder/Render/Edit.pm $ $Author: autrijus $
2 # $Revision: #17 $ $Change: 8712 $ $DateTime: 2003/11/06 15:01:35 $
3  
4 package DBIx::ReportBuilder::Render::Edit;
5 use base 'DBIx::ReportBuilder::Render';
6 use strict;
7 use NEXT;
8  
9 sub new {
10 my ($class, %args) = @_;
11 my $self = $class->SUPER::new(
12 %args,
13 twig_handlers => {
14 html => \&html,
15 head => sub { $_->erase },
16 body => \&body,
17  
18 preamble => \&section,
19 header => \&section,
20 content => \&section,
21 footer => \&section,
22 postamble => \&section,
23 part => \&part, # called indirectly
24 include => \&include,
25  
26 var => \&var,
27 joins => \&clauses,
28 limits => \&clauses,
29 orderbys => \&clauses,
30 groupbys => \&clauses,
31 table => \&twigTable,
32 graph => \&twigGraph,
33 %{$args{twig_handlers}||{}},
34 },
35 start_tag_handlers => {
36 content => \&enterContent,
37 table => \&search,
38 graph => \&search,
39 %{$args{start_tag_handlers}||{}},
40 },
41 end_tag_handlers => {
42 content => \&leaveContent,
43 %{$args{end_tag_handlers}||{}},
44 },
45 twig_roots => {
46 'html' => 1,
47 %{$args{twig_roots}||{}},
48 },
49 pretty_print => ($args{pretty_print} || 'indented_c'),
50 );
51  
52 return $self;
53 }
54  
55 sub html {
56 $_->del_att('xmlns');
57 $_->set_tag('div');
58 $_->set_att( align => 'center' );
59 }
60  
61 sub body {
62 $_->set_tag('table');
63 $_->set_att(
64 border => 0,
65 style => 'border-bottom: 2px ridge',
66 width => 870,
67 name => 'ContentTable',
68 bgcolor => '#a0a0a0',
69 cellspacing => 0,
70 cellpadding => 0,
71 );
72 }
73  
74 sub section {
75 my $self = shift;
76 my $section = $_;
77 $self->part($_) for $section->children;
78 $section->insert(
79 'tr',
80 'td' => {
81 width => '92%', class => 'tableEmboss',
82 height => 42, bgcolor => '#FFFFFF',
83 },
84 'table' => {
85 border => 0, width => '100%',
86 cellspacing => 0, cellpadding => 0,
87 },
88 );
89 $section->first_child->insert_new_elt(
90 'td' => {
91 width => '8%', class => 'tableTitle', height => 42,
92 },
93 )->set_text($self->loc($section->tag));
94 $section->erase;
95 1;
96 }
97  
98 sub clause {
99 my ($self, $clause, $clause_cur, $part_id) = @_;
100 my $clause_id = $1 if $clause->id =~ /(\d+)$/;
101 my $checked = ($clause_id eq $clause_cur);
102  
103 $clause->set_att( bgcolor => ($checked ? '#6666cc' : 'gray') );
104  
105 my $trigger = "parent.property.location.href='Property.html?".
106 "ClauseId=$clause_id&PartId=$part_id';";
107 $clause->set_att(
108 onclick => "ClearAway(this, 'th');$trigger",
109 );
110 $self->Object->SetTrigger($trigger) if $checked;
111 }
112  
113 sub twigTable {
114 my $self = shift;
115 my $part = shift or return;
116 my $part_id = shift || $part->id;
117 my $clause_cur = $self->Object->ClauseId;
118  
119 my $cnt = 0;
120 foreach my $th ($part->find_nodes('thead/tr/th')) {
121 $th->insert_new_elt($self->type_icon('cell', 'left'));
122 $self->clause($th, $clause_cur, $part_id);
123 $cnt++;
124 }
125  
126 $part->set_att(border => '3');
127 $part->set_att(bgcolor => '#c9c9c9');
128  
129 my $tbody = $part->first_child('tbody');
130 if ($cnt and $tbody) {
131 my $tr = $tbody->insert_new_elt(last_child => 'tr');
132 $tr->insert_new_elt('td', '...') for 1 .. $cnt;
133 }
134  
135 my $clauses = $part->att('#Clauses') || $part->parent('#Clauses') or return;
136 return unless @$clauses;
137  
138 $tbody = $part->insert_new_elt(last_child => 'tbody');
139  
140 foreach my $item (@$clauses) {
141 foreach my $clause ($item->children) {
142 no warnings 'uninitialized';
143 my $th = $tbody->insert_new_elt(last_child => 'tr')
144 ->insert_new_elt('th',
145 { bgcolor => 'gray', colspan => ($cnt || 1),
146 align => 'left', style => 'font-size: small' });
147 $th->set_text( join(
148 ', ',
149 map {
150 $self->Object->loc($self->Object->ucase($_)) .
151 " => '" .
152 (($_ eq 'text') ? $clause->text : $clause->att($_)) .
153 "'"
154 } $self->Object->Atts($clause->tag)
155 ) );
156 $th->insert_new_elt($self->type_icon($clause->tag, 'left'));
157 $th->set_id($clause->id);
158 $self->clause($th, $clause_cur, $part_id);
159 }
160 }
161 }
162  
163 sub twigGraph {
164 my $self = shift;
165 my $item = shift;
166 $self->twigTable($item, @_);
167  
168 $item->set_tag('table');
169 $item->set_att(
170 '#Tag' => 'graph',
171 'width' => '100%',
172 'border' => '3',
173 );
174  
175 $self->plotGraph($item);
176 }
177  
178 sub part {
179 my ($self, $part) = @_;
180 my $type = $part->att('#Tag') || $part->tag;
181  
182 my $part_id = $self->NextPart;
183 $self->$type($part, $part_id);
184  
185 my $trigger = "parent.property.location.href='Property.html?".
186 "PartId=$part_id'";
187 my $checked = ($self->Object->PartId eq $part_id);
188 $self->Object->SetTrigger($trigger)
189 if $checked and !$self->Object->Trigger;
190 my $color = ($checked ? '#6666cc' : 'white');
191 $part->wrap_in(
192 'td' => {
193 id => "Part$part_id",
194 class => 'content',
195 onclick => "ClearAway(this, 'td');" .
196 "if(clicked != 1){$trigger;};clicked=false",
197 style => "border-left: solid $color 8px;" .
198 "border-right: solid $color 8px;" .
199 "border-top: solid $color 1px;" .
200 "border-bottom: solid $color 1px;",
201 },
202 'tr' => { valign => 'top' },
203 );
204 $part->parent->parent->insert_new_elt(
205 'last_child', 'td', { width => 19 }
206 )->insert_new_elt($self->type_icon($type));
207 }
208  
209 sub search {
210 my $self = shift;
211 $_->set_att(rows => 2) unless $_->tag eq 'graph';
212 $_->set_att('#Clauses' => []);
213 $self->NEXT::search(@_);
214 }
215  
216 sub clauses {
217 my $self = shift;
218 my $item = $_;
219 push @{$item->parent->att('#Clauses')}, $item->copy;
220 my $method = "SUPER::" . $item->tag;
221 $self->$method(@_);
222 }
223  
224 sub p {
225 my $self = shift;
226 $_->set_text(chr(0xA0)) unless length($_->text);
227 $self->NEXT::p(@_);
228 }
229  
230 sub include {
231 my $self = shift;
232 $_->set_text(
233 $self->Object->loc($_->tag) .
234 ': ' .
235 $self->Object->describe_report($_->att('report'))
236 );
237 }
238  
239 sub img {
240 $_->set_att('src' => '/RG/img/imgUpload.png') unless $_->att('src');
241 }
242  
243 sub var {
244 my $self = shift;
245 my $item = $_;
246 $self->NEXT::var(@_);
247 $item->set_att('style' => 'background: gray');
248 }
249  
250 sub inContent { $_[0]->{in_content} || 0 }
251 sub enterContent { $_[0]->{in_content} = 1 }
252 sub leaveContent { $_[0]->{in_content} = 0 }
253  
254 sub type_icon {
255 my ($self, $type, $align) = @_;
256 return 'img' => {
257 width => 19,
258 height => 19,
259 align => ($align || 'right'),
260 valign => 'absmiddle',
261 src => "/RG/img/obj\u$type.png",
262 alt => $self->loc($type),
263 title => $self->loc($type),
264 style => 'background: #e0e0e0; border: 1px black ridge',
265 }
266 }
267  
268 1;