]> mj.ucw.cz Git - pciids.git/blob - PciIds/Html/List.pm
4115bbb7caf9cecf4c85bcd5373405db39d1c85d
[pciids.git] / PciIds / Html / List.pm
1 package PciIds::Html::List;
2 use strict;
3 use warnings;
4 use PciIds::Address;
5 use PciIds::Html::Util;
6 use Apache2::Const qw(:common :http);
7 use base 'Exporter';
8
9 our @EXPORT = qw(&loadItem);
10
11 sub loadItem( $$ ) {
12         my( $tables, $uri ) = @_;
13         my $address = PciIds::Address::new( $uri );
14         return ( 0 ) unless( defined $address );
15         my $item = $tables->item( $address->get() );
16         return ( 0 ) unless( defined $item );
17         my( $parent, $name, $description, $maincomment ) = @{$item};
18         return ( 1, $parent, $name, $description, $address, $maincomment );
19 }
20
21 sub list( $$$$ ) {
22         my( $req, $args, $tables, $auth ) = @_;
23         my( $ok, $parent, $name, $description, $address, $mid ) = loadItem( $tables, $req->uri() );
24         return NOT_FOUND unless( $ok );
25         my $id = $address->pretty();
26         genHtmlHead( $req, $id, undef );
27         print '<h1>'.encode( $id ).'</h1>';
28         genMenu( $address, $args, $auth );
29         print htmlDiv( 'name', '<p>'.encode( $name ) ) if( defined( $name ) );
30         print htmlDiv( 'description', '<p>'.encode( $description ) ) if( defined( $description ) );
31         genPath( $address, 0 );
32         my $diss = 0;
33         my $comment;
34         foreach $comment ( @{$tables->history( $address->get() )} ) {
35                 unless( $diss ) {
36                         print "<div class='discussion'>\n<h2>Discussion</h2>";
37                         $diss = 1;
38                 }
39                 my( $id, $text, $time, $name, $description, $seen, $user ) = @{$comment};
40                 my $type = $seen ? 'comment' : 'unseen-comment';
41                 $type = 'main-comment' if( defined( $mid ) && ( $id == $mid ) );
42                 print "<div class='$type'>\n";
43                 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
44                 print "<p class='itemdescription'>Description: ".encode( $description )."\n" if( defined( $description ) && ( $description ne '' ) );
45                 if( defined( $text ) && ( $text ne '' ) ) {
46                         $text = encode( $text );
47                         $text =~ s/\n/<br>/g;
48                         print "<p class='comment-text'>$text\n";
49                 }
50                 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
51                 print "<p class='time'>".encode( $time )."\n";
52                 print "</div>\n";
53         }
54         print "</div>\n" if( $diss );
55         unless( $address->leaf() ) {
56                 print "<h2>Subitems</h2>\n";
57                 my $restricts = $address->defaultRestrictList();
58                 if( scalar @{$restricts} ) {
59                         print "<p>";
60                         my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
61                         foreach( @{$restricts} ) {
62                                 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
63                         }
64                 }
65                 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
66                 my $sort = ( $args->{'sort'} or 'id' );
67                 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
68                 genTableHead( 'subnodes', [ '<a href="'.$url.'?sort='.$sort_id.'">Id</a>', '<a href="'.$url.'?sort='.$sort_name.'">Name</a>', 'Description' ], [ 'id-col', 'name-col', 'desc-col' ] );
69                 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
70                 $tables->nodes( $address->get(), $args );
71                 genTableTail();
72         }
73         genHtmlTail();
74         return OK;
75 }
76
77 1;