summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormark <mark>2011-08-16 02:10:08 +0000
committermark <mark>2011-08-16 02:10:08 +0000
commit3124e61950c0a502018cc5fb0f5977f20958a87f (patch)
tree785366328fd7e6e280cb4c00e4a2e99742dc06a5
parent04eff5ae86574de31fc281bc52a65a93ef77b3e4 (diff)
reliably start batch download, #947
-rw-r--r--httemplate/elements/progress-init.html9
-rw-r--r--httemplate/misc/download-bill_batch.html6
-rwxr-xr-xhttemplate/search/bill_batch.cgi47
3 files changed, 53 insertions, 9 deletions
diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html
index 9f17370..2ec248e 100644
--- a/httemplate/elements/progress-init.html
+++ b/httemplate/elements/progress-init.html
@@ -54,7 +54,10 @@ sub process_whatever { #class method
)
%>
-<% include('/elements/init_overlib.html') %>
+% if (!$noinit) {
+<& /elements/init_overlib.html &>
+% $noinit = 1;
+% }
<SCRIPT TYPE="text/javascript">
@@ -114,6 +117,9 @@ function <%$key%>myCallback( jobnum ) {
</SCRIPT>
+<%once>
+my $noinit = 0;
+</%once>
<%init>
my( $formname, $fields, $action, $url_or_message, $key ) = @_;
@@ -126,6 +132,7 @@ if ( ref($url_or_message) ) { #its a message or something
if $url_or_message->{'url'};
$url_or_message_link = 'popup_url=' .uri_escape( $url_or_message->{'popup_url'} )
if $url_or_message->{'popup_url'};
+
} else {
$url_or_message_link = "url=$url_or_message";
}
diff --git a/httemplate/misc/download-bill_batch.html b/httemplate/misc/download-bill_batch.html
index 00d9236..9b5f1ef 100644
--- a/httemplate/misc/download-bill_batch.html
+++ b/httemplate/misc/download-bill_batch.html
@@ -12,6 +12,12 @@ $m->clear_buffer;
$r->content_type('application/pdf');
$r->headers_out->add( 'Content-Disposition' =>
'attachment;filename="invoice_batch_'.$batchnum.'.pdf"');
+my $cookie = CGI::Cookie->new(
+ -name => "bill_batch_download",
+ -value => $batchnum,
+ -expires => '+1d',
+);
+$r->headers_out->add( 'Set-Cookie' => $cookie->as_string );
$m->print($content);
$batch->pdf('');
diff --git a/httemplate/search/bill_batch.cgi b/httemplate/search/bill_batch.cgi
index a181aab..3cdb3e3 100755
--- a/httemplate/search/bill_batch.cgi
+++ b/httemplate/search/bill_batch.cgi
@@ -1,18 +1,31 @@
% my $batchnum = $cgi->param('download');
% if ( $batchnum =~ /^\d+$/ ) {
-% $cgi->delete('download');
+% my $download = $p."misc/download-bill_batch.html?$batchnum";
<HTML>
<HEAD><TITLE>Starting download...</TITLE>
<SCRIPT TYPE="text/javascript">
-function refreshParent() {
- window.top.setTimeout("window.top.location.href = '<% $cgi->self_url %>'", 2000);
- window.top.location.replace('<%$p%>misc/download-bill_batch.html?<%$batchnum%>');
+function start() {
+ window.location.replace('<% $download %>');
}
</SCRIPT>
-</HEAD><BODY onload="refreshParent();">
+<!--[if lte IE 7]>
+<SCRIPT TYPE="text/javascript">function start() {}</SCRIPT>
+<![endif]-->
+</HEAD>
+<BODY onload="start()" STYLE="background-color:#ccccff">
+<TABLE STYLE="height:125px; width:100%; text-align:center"><TR><TD STYLE="vertical-align:middle;text-align:center">
+<A HREF="<% $download %>">Click here if your download does not start</A>
+</TD></TR></TABLE>
<& /elements/footer.html &>
% }
% else {
+%# delete existing download cookie
+% my $cookie = CGI::Cookie->new(
+% -name => 'bill_batch_download',
+% -value => 0,
+% -expires => '-1d',
+% );
+% $r->headers_out->add( 'Set-Cookie' => $cookie->as_string );
<% include( 'elements/search.html',
'title' => 'Invoice Batches',
'name_singular' => 'batch',
@@ -49,10 +62,29 @@ function refreshParent() {
'',
],
'really_disable_download' => 1,
+ 'html_foot' => include('.foot'),
)
%>
%}
+<%def .foot>
+<SCRIPT type="text/javascript">
+var timer;
+function checkDownloadStatus(batchnum) {
+ var re = new RegExp('bill_batch_download=' + batchnum);
+ if ( re.test(document.cookie) ) {
+ window.clearInterval(timer);
+ window.location.reload();
+ }
+}
+function startBatch(batchnum) {
+ timer = window.setInterval(function() {
+ checkDownloadStatus(batchnum);
+ }, 2000);
+ eval('batch'+batchnum+'process()');
+}
+</SCRIPT>
+</%def>
<%init>
die "access denied"
@@ -65,7 +97,6 @@ my $count_query = 'SELECT COUNT(*) FROM bill_batch';
my $extra_sql = ''; # may add something here later
my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
-my $download_id = int(rand(1000000));
sub download_link {
my $batch = shift;
@@ -79,10 +110,10 @@ sub download_link {
"Download$batchnum",
[ 'batchnum', 'close' ],
$p.'misc/process/bill_batch-print.html',
- { url => $p."search/bill_batch.cgi?download=$batchnum" },
+ { popup_url => $p."search/bill_batch.cgi?download=$batchnum" },
"batch$batchnum" #key
);
- $html .= '<A href="#" onclick="batch'.$batchnum.'process();">' .
+ $html .= '<A href="#" onclick="startBatch('.$batchnum.');">' .
($batch->status eq 'O' ? '<B>Download and close</B>' : 'Download');
$html .= '</A></FORM>';
return $html;