/[webpac2]/Webpacus/lib/Webpacus/Controller/Output.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Webpacus/lib/Webpacus/Controller/Output.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 199 by dpavlin, Wed Nov 30 23:15:28 2005 UTC revision 280 by dpavlin, Sat Dec 17 22:32:28 2005 UTC
# Line 8  use base qw/WebPAC::Common/; Line 8  use base qw/WebPAC::Common/;
8  use Template;  use Template;
9  use List::Util qw/first/;  use List::Util qw/first/;
10  use Data::Dumper;  use Data::Dumper;
11  use URI::Escape;  use URI::Escape qw/uri_escape_utf8/;
12    
13  =head1 NAME  =head1 NAME
14    
# Line 16  WebPAC::Output::TT - use Template Toolki Line 16  WebPAC::Output::TT - use Template Toolki
16    
17  =head1 VERSION  =head1 VERSION
18    
19  Version 0.02  Version 0.05
20    
21  =cut  =cut
22    
23  our $VERSION = '0.02';  our $VERSION = '0.05';
24    
25  =head1 SYNOPSIS  =head1 SYNOPSIS
26    
# Line 71  Create output from in-memory data struct Line 71  Create output from in-memory data struct
71    
72   my $text = $tt->apply(   my $text = $tt->apply(
73          template => 'text.tt',          template => 'text.tt',
74          data => $ds          data => $ds,
75            record_uri => 'database/prefix/mfn',
76   );   );
77    
78  It also has follwing template toolikit filter routies defined:  It also has follwing template toolikit filter routies defined:
# Line 196  filter to return links to search, usage Line 197  filter to return links to search, usage
197                                          } else {                                          } else {
198                                                  $s = $item->{'search'}->[0];                                                  $s = $item->{'search'}->[0];
199                                          }                                          }
200                                          $s = uri_escape( $s );                                          #$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;
201                                            $s = uri_escape_utf8( $s );
202    
203                                          my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display";                                          my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display";
204    
205                                          push @html, <<__JS_LINK_SEARCH__                                          push @html, <<__JS_LINK_SEARCH__
206  <a href="#" onclick="new Ajax.Updater( 'results',  '/search/results?$search=$s', { asynchronous: 1,onLoading: function(request){show_searching();},onLoaded: function(request){hide_searching();} } ) ; return false">$d</a>  <a href="#" onclick="new WebPAC.Updater( 'results',  '/search/results?$search=$s', { asynchronous: 1,onLoading: function(request){show_searching();},onLoaded: function(request){hide_searching();} } ) ; return false">$d</a>
207  __JS_LINK_SEARCH__  __JS_LINK_SEARCH__
208                                  }                                  }
209    
# Line 222  __JS_LINK_SEARCH__ Line 224  __JS_LINK_SEARCH__
224    
225          $args->{'search'} = tt_filter_search($args);          $args->{'search'} = tt_filter_search($args);
226    
227    =head3 load_rec
228    
229    Used mostly for onClick events like this:
230    
231      <a href="#" onClick="[% load_rec( record_uri, 'template_name.tt') %]>foo</a>
232    
233    It will automatically do sanity checking and create correct JavaScript code.
234    
235    =cut
236    
237            $args->{'load_rec'} = sub {
238                    my @errors;
239    
240                    my $record_uri = shift or push @errors, "record_uri missing";
241                    my $template = shift or push @errors, "template missing";
242    
243                    if ($record_uri !~ m#^[^/]+/[^/]+/[^/]+$#) {
244                            push @errors, "invalid format of record_uri: $record_uri";
245                    }
246    
247                    if (@errors) {
248                            return "Logger.error('errors in load_rec: " . join(", ", @errors) . "'); return false;";
249                    } else {
250                            return "load_rec('$record_uri','$template'); return false;";
251                    }
252            };
253    
254    =head3 load_template
255    
256    Used to re-submit search request and load results in different template
257    
258      <a href="#" onClick="[% load_template( 'template_name.tt' ) %]">bar</a>
259    
260    =cut
261    
262            $args->{'load_template'} = sub {
263                    my $template = shift or return "Logger.error('load_template missing template name!'); return false;";
264                    return "load_template($template); return false;";
265            };
266    
267          my $out;          my $out;
268    
269          $self->{'tt'}->process(          $self->{'tt'}->process(

Legend:
Removed from v.199  
changed lines
  Added in v.280

  ViewVC Help
Powered by ViewVC 1.1.26