1 package PciIds::Html::Jump;
5 use PciIds::Html::Forms;
6 use PciIds::Html::Users;
7 use PciIds::Html::Util;
8 use PciIds::Html::Format;
10 use Apache2::Const qw(:common :http);
12 our @EXPORT = qw(&jumpWindow);
14 sub jumpWindow( $$ ) {
15 my( $req, $args ) = @_;
16 print "<form id='jump' class='jump' name='jump' method='POST' action='".buildExcept( 'action', $args )."?action=jump".( defined $args->{'action'} ? "?origin=".$args->{'action'} : "" )."'>\n";
18 print "<input type='text' class='jump' name='where'><input type='submit' value='Jump'>\n";
23 my( $req, $args, $addr ) = @_;
24 my $prefix = ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read' : 'mods';
25 my $url = "http://".$req->hostname()."/$prefix/$addr".buildArgs( $args );
26 return HTTPRedirect( $req, $url );
29 sub itemExists( $$ ) {
30 my( $tables, $addr ) = @_;
31 return defined $tables->item( $addr );
34 sub tryDirect( $$$$ ) {
35 my( $req, $args, $tables, $search ) = @_;
36 my $address = PciIds::Address::new( $req->uri() );
39 my( $top ) = $address->get() =~ /^([^\/]+)/;
40 $search =~ s/^\//$top\//;
41 #Is it absolute address?
42 my $saddr = PciIds::Address::new( $search );
43 return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
44 while( defined $address ) {
45 $saddr = PciIds::Address::new( $address->get()."/$search" );
46 return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
47 $address = $address->parent();
53 my( $req, $args, $tables, $auth ) = @_;
54 $args->{'action'} = delete $args->{'origin'};
55 my $search = getFormValue( 'where', '' );
56 my $idOnly = $search =~ s/^#//;
57 my $direct = tryDirect( $req, $args, $tables, $search );
58 return $direct if defined $direct;
59 my $address = PciIds::Address::new( $req->uri() );
60 unless( $idOnly || length $search < 3 ) {#Try extended search
61 my( $prefix ) = $address->get() =~ /^([^\/]+)/;
62 $prefix = undef if $search =~ s/^\*//;
63 my $result = $tables->searchName( $search, $prefix );
65 genHtmlHead( $req, 'Search results', undef );
66 print "<div class='top'>\n";
67 print "<h1>Search results</h1>\n";
68 genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ], [ '', 'jump' ] ] );
69 print "<div class='clear'></div>\n";
71 genPath( $req, $address, 1 );
72 print "<h2>Found items</h2>\n";
73 genTableHead( 'found', [ 'ID', 'Name', 'Parent' ], [] );
74 my $prefix = 'http://'.$req->hostname().'/'.( ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read/' : 'mods/' );
75 my $suffix = buildArgs( $args );
76 htmlFormatTable( $result, 3, [], [ sub {
78 my $address = PciIds::Address::new( $addr );
79 return "<a href='$prefix".$address->get()."$suffix'>".encode( $address->fullPretty() )."</a>";
80 } ], sub { 1; }, sub { ' class="item"'; } );
86 genHtmlHead( $req, 'No matches', undef );
87 print "<div class='top'>\n";
88 print '<h1>No matches</h1>';
89 genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ] ] );
90 print "<div class='clear'></div>\n";
92 genPath( $req, $address, 1 );
93 print "<p>Your search request matches no item. Would you like to try again?\n<p>\n";
94 jumpWindow( $req, $args );