| 1 | package HTML::GUI::log::eventList; | ||
| 2 | |||
| 3 | 14 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 14 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 14 | ▶ | use UNIVERSAL qw(isa); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | use HTML::GUI::tag; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | HTML::GUI::log::eventList - Create and control a eventList input for webapp | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | Version 0.01 | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | our $VERSION = '0.01'; | ||
| 19 | #TODO : creer un objet htmlTag pour ne plus boucler a l'infini sur l'objet widget | ||
| 20 | our @ISA = qw(HTML::GUI::tag); | ||
| 21 | |||
| 22 | my $SProcessEventList = HTML::GUI::log::eventList->new(); | ||
| 23 | |||
| 24 | =head1 EVENTLIST | ||
| 25 | |||
| 26 | The eventList module to store all the events we need. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | |||
| 31 | =head1 PUBLIC METHODS | ||
| 32 | |||
| 33 | =pod | ||
| 34 | |||
| 35 | =head3 new | ||
| 36 | |||
| 37 | create a new eventList | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub new | ||
| 42 | { | ||
| 43 | my($class, | ||
| 44 | ) = @_; | ||
| 45 | my $this = {}; | ||
| 46 | if (!$this){ | ||
| 47 | return undef; | ||
| 48 | } | ||
| 49 | $this->{eventList} = []; | ||
| 50 | |||
| 51 | bless($this, $class); | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | =pod | ||
| 56 | |||
| 57 | =head3 addEvent | ||
| 58 | |||
| 59 | Description : | ||
| 60 | Add $event to the EventList object | ||
| 61 | Parameters : | ||
| 62 | $event : a HTML::GUI::log::event | ||
| 63 | returns : | ||
| 64 | 1 if the event is effectively added | ||
| 65 | 0 if there was a problem | ||
| 66 | |||
| 67 | =cut | ||
| 68 | sub addEvent | ||
| 69 | { | ||
| 70 | my($self,$event) = @_; | ||
| 71 | |||
| 72 | if (!isa($event,'HTML::GUI::log::event')){ | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | push @{$self->{eventList}},$event; | ||
| 76 | return 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | =pod | ||
| 80 | |||
| 81 | =head3 forget | ||
| 82 | |||
| 83 | Description : | ||
| 84 | Erase all events of the eventList | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | sub forget | ||
| 89 | { | ||
| 90 | my($self) = @_; | ||
| 91 | |||
| 92 | $self->{eventList}=[]; | ||
| 93 | } | ||
| 94 | |||
| 95 | =pod | ||
| 96 | |||
| 97 | =head3 getCurrentEventList | ||
| 98 | |||
| 99 | Description : | ||
| 100 | Return the EventList object of the proces | ||
| 101 | |||
| 102 | =cut | ||
| 103 | |||
| 104 | sub getCurrentEventList | ||
| 105 | { | ||
| 106 | return $SProcessEventList; | ||
| 107 | } | ||
| 108 | |||
| 109 | =pod | ||
| 110 | |||
| 111 | =head3 getHtml | ||
| 112 | |||
| 113 | Description : | ||
| 114 | Return the html of the eventList. The HTML is like this one : | ||
| 115 | <div class="errorList"> | ||
| 116 | <h2 class="errorList">Some errors occured.</h2> | ||
| 117 | <dl class="errorList"> | ||
| 118 | <dt>Object label</dt> | ||
| 119 | <dd>Event label.</dd> | ||
| 120 | ...other events... | ||
| 121 | </div> | ||
| 122 | |||
| 123 | Parameters : | ||
| 124 | $type : | ||
| 125 | 'error' : render error events | ||
| 126 | 'info' : render info events | ||
| 127 | 'debug' : render debug events | ||
| 128 | 'all' : render all events | ||
| 129 | $visibility : | ||
| 130 | 'pub' for public, only public events are rendered | ||
| 131 | 'all' for private, all events (private and public) are rendered | ||
| 132 | |||
| 133 | |||
| 134 | =cut | ||
| 135 | |||
| 136 | sub getHtml | ||
| 137 | { | ||
| 138 | my($self,$type,$visibility) = @_; | ||
| 139 | my @displayList = (); | ||
| 140 | |||
| 141 | $type ||= 'all'; | ||
| 142 | $visibility ||= 'pub'; | ||
| 143 | |||
| 144 | if (!scalar @{$self->{eventList}}){ | ||
| 145 | #no error to display !! | ||
| 146 | return ''; | ||
| 147 | } | ||
| 148 | @displayList = grep {$type eq 'all' || $type eq $_->getType()} | ||
| 149 | @{$self->{eventList}}; | ||
| 150 | |||
| 151 | |||
| 152 | #generate HTML for each event !!! | ||
| 153 | my $listHtml = ''; | ||
| 154 | my $lastDomainHtml = ''; | ||
| 155 | foreach my $event (@displayList){ | ||
| 156 | my $domainHtml = $event->getDtHtml(); | ||
| 157 | if ($lastDomainHtml ne $domainHtml){ | ||
| 158 | $listHtml .= $domainHtml; | ||
| 159 | } | ||
| 160 | $lastDomainHtml = $domainHtml; | ||
| 161 | $listHtml .= $event->getDdHtml(); | ||
| 162 | } | ||
| 163 | |||
| 164 | |||
| 165 | $listHtml = $self->getHtmlTag("h2",{class=>("errorList")},$self->escapeHtml('Some errors occured.') ) | ||
| 166 | .$self->getHtmlTag("dl",{class=>("errorList")},$listHtml ); | ||
| 167 | $listHtml = $self->getHtmlTag("div",{class=>("errorList")}, | ||
| 168 | $listHtml ); | ||
| 169 | return $listHtml; | ||
| 170 | } | ||
| 171 | |||
| 172 | sub DESTROY | ||
| 173 | { | ||
| 174 | my($self) = @_; | ||
| 175 | |||
| 176 | delete $self->{eventList} ; | ||
| 177 | |||
| 178 | } | ||
| 179 | |||
| 180 | =head1 AUTHOR | ||
| 181 | |||
| 182 | Jean-Christian Hassler, C<< <jhassler at free.fr> >> | ||
| 183 | |||
| 184 | =head1 BUGS | ||
| 185 | |||
| 186 | Please report any bugs or feature requests to | ||
| 187 | C<bug-gui-libhtml-eventList at rt.cpan.org>, or through the web interface at | ||
| 188 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-GUI-widget>. | ||
| 189 | I will be notified, and then you'll automatically be notified of progress on | ||
| 190 | your bug as I make changes. | ||
| 191 | |||
| 192 | =head1 SUPPORT | ||
| 193 | |||
| 194 | You can find documentation for this module with the perldoc command. | ||
| 195 | |||
| 196 | perldoc HTML::GUI::widget | ||
| 197 | |||
| 198 | You can also look for information at: | ||
| 199 | |||
| 200 | =over 4 | ||
| 201 | |||
| 202 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 203 | |||
| 204 | L<http://annocpan.org/dist/HTML-GUI-widget> | ||
| 205 | |||
| 206 | =item * CPAN Ratings | ||
| 207 | |||
| 208 | L<http://cpanratings.perl.org/d/HTML-GUI-widget> | ||
| 209 | |||
| 210 | =item * RT: CPAN's request tracker | ||
| 211 | |||
| 212 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-GUI-widget> | ||
| 213 | |||
| 214 | =item * Search CPAN | ||
| 215 | |||
| 216 | L<http://search.cpan.org/dist/HTML-GUI-widget> | ||
| 217 | |||
| 218 | =back | ||
| 219 | |||
| 220 | =head1 ACKNOWLEDGEMENTS | ||
| 221 | |||
| 222 | =head1 COPYRIGHT & LICENSE | ||
| 223 | |||
| 224 | Copyright 2007 Jean-Christian Hassler, all rights reserved. | ||
| 225 | |||
| 226 | This program is free software; you can redistribute it and/or modify it | ||
| 227 | under the same terms as Perl itself. | ||
| 228 | |||
| 229 | =cut | ||
| 230 | |||
| 231 | 1; # End of HTML::GUI::event::eventList | ||