From ec5c3d0ee2ad6fd3eb63b7995bb5485697d51097 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Mon, 19 May 2008 16:23:35 -0500 Subject: [PATCH] Add AJAX output sub, EXPORT_TAGS and enable loop_context_vars for HTML::Template::Pro. The loop_context_vars will be very useful in display. They are: __first__, __last__, __inner__, __odd__, __counter__. Note: apparently __even__ does not exist, so instead use something like: Signed-off-by: Joshua Ferraro --- C4/Output.pm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/C4/Output.pm b/C4/Output.pm index fc1a840b49..3b6aba5814 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -31,13 +31,19 @@ use C4::Context; use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language ); use HTML::Template::Pro; -use vars qw($VERSION @ISA @EXPORT); +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); BEGIN { # set the version for version checking - $VERSION = 3.01; + $VERSION = 3.02; require Exporter; @ISA = qw(Exporter); + @EXPORT_OK = qw(&output_ajax_with_http_headers); # More stuff should go here instead + %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar + &output_ajax_with_http_headers &output_html_with_http_headers)], + ajax =>[qw(&output_ajax_with_http_headers)], + html =>[qw(&output_html_with_http_headers)] + ); push @EXPORT, qw( &themelanguage &gettemplate setlanguagecookie pagination_bar ); @@ -88,6 +94,7 @@ sub gettemplate { die_on_bad_params => 1, global_vars => 1, case_sensitive => 1, + loop_context_vars => 1, # enable: __first__, __last__, __inner__, __odd__, __counter__ path => ["$htdocs/$theme/$lang/$path"] ); my $themelang=( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ) @@ -213,7 +220,7 @@ sub pagination_bar { my $pages_around = 2; my $url = - $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '='; + $base_url . ( $base_url =~ m/[?&]/ ? '&' : '?' ) . $startfrom_name . '='; my $pagination_bar = ''; @@ -347,6 +354,17 @@ sub output_html_with_http_headers ($$$) { ), $html; } +sub output_ajax_with_http_headers ($$) { + my ($query, $js) = @_; + print $query->header( + -type => 'text/javascript', + -charset => 'UTF-8', + -Pragma => 'no-cache', + -'Cache-Control' => 'no-cache', + -expires =>'-1d', + ), $js; +} + END { } # module clean-up code here (global destructor) 1; -- 2.39.5