<%doc> ############################################################################### # A customized version of the generic dynamic_list_query.html ############################################################################### <%args> $val => $ARGS{crit}; $caller => $ARGS{self}; <%init> my $DEBUG = 0; print "

     ", Dumper(%ARGS), "

" if $DEBUG; <%perl> if ( $DEBUG ){ use Data::Dumper; print "

     ", Dumper(%ARGS), "

"; print &backbone_search("end_id", "1"); } else { do "jsrsServer.pm"; jsrsDispatch("backbone_search"); } <%shared> sub backbone_search { # Arguments: # - field: Form element to add the results into # - crit: Criteria. A string with one or more keywords to search my $field = shift; my $crit = shift; my $val = $crit; my @terms; if ( $val =~ /\w+/ ) { if ( $val =~ /\w+\s+\w+/ ){ # if there's more than one word @terms = split /\s+/, $val; }else{ $val =~ s/\s+//; push @terms, $val; } } my $site_id = $terms[0] if ( scalar(@terms) ); my $site_graph = BackboneCable->get_site_graph(); my @results = keys %{$site_graph->{$site_id}}; my $MAX_RESULTS = $ui->config->get('DEFAULT_SELECTMAX'); my $response = $field."&"; if ( scalar(@results ) < $MAX_RESULTS) { $response .= "0=".$ui->url_encode("No matches") unless (scalar(@results)); @results = sort { $a->name cmp $b->name } map { Site->retrieve($_) } @results; foreach my $site ( @results ){ $response .= $site->id."=".$ui->url_encode($site->name)."&"; } }else{ $response .= "0=".$ui->url_encode("More than ".$MAX_RESULTS." matches.")."&"; $response .= "0=".$ui->url_encode("Refine search.")."&"; } return $response; }