a37cf24ebecc857b054f35bd97a65bf0858a4321
[freeside.git] / httemplate / elements / progress-popup.html
1 %
2 %  my $jobnum = $cgi->param('jobnum');
3 %  my $url = $cgi->param('url');
4 %  my $message = $cgi->param('message');
5 %  my $popup_url = $cgi->param('popup_url');
6 %  my $formname = scalar($cgi->param('formname'));
7 %  my $error_url = $cgi->param('error_url');
8 %
9
10 <HTML>
11   <HEAD>
12     <TITLE></TITLE>
13   </HEAD>
14   <BODY BGCOLOR="#ccccff" onLoad="refreshStatus()">
15
16 <% include('/elements/xmlhttp.html',
17               'url'  => $p.'elements/jsrsServer.html',
18               'subs' => [ 'job_status' ],
19            )
20 %>
21 <SCRIPT TYPE="text/javascript" src="<%$fsurl%>elements/qlib/control.js"></SCRIPT>
22 <SCRIPT TYPE="text/javascript" src="<%$fsurl%>elements/qlib/imagelist.js"></SCRIPT>
23 <SCRIPT TYPE="text/javascript" src="<%$fsurl%>elements/qlib/progress.js"></SCRIPT>
24 <SCRIPT TYPE="text/javascript">
25 function refreshStatus () {
26   //jsrsExecute( '<%$p%>elements/jsrsServer.html', updateStatus, 'job_status', '<% $jobnum %>' );
27
28   job_status( '<% $jobnum %>', updateStatus );
29 }
30 function updateStatus( status_statustext ) {
31
32   //var Array = status_statustext.split("\n");
33   var statusArray = eval('(' + status_statustext + ')');
34   var status = statusArray[0];
35   var statustext = statusArray[1];
36   var actiontext = statusArray[2];
37
38   //if ( status == 'progress' ) {
39   //IE workaround, no i have no idea why
40   if ( status.indexOf('progress') > -1 ) {
41     document.getElementById("progress_message").innerHTML = actiontext + '...';
42     document.getElementById("progress_percent").innerHTML = statustext + '%';
43     bar1.set(statustext);
44     bar1.update;
45     //jsrsExecute( '<%$p%>elements/jsrsServer.html', updateStatus, 'job_status', '<% $jobnum %>' );
46     job_status( '<% $jobnum %>', updateStatus );
47   } else if ( status.indexOf('complete') > -1 ) {
48 % if ( $message ) {
49 %
50 %   my $onClick = $url
51 %                   ? "window.top.location.href = \\'$url\\';"
52 %                   : 'parent.nd(1);';
53
54     document.getElementById("progress_message").innerHTML = "<% $message %>";
55     document.getElementById("progress_bar").innerHTML = '';
56     document.getElementById("progress_percent").innerHTML =
57       '<INPUT TYPE="button" VALUE="OK" onClick="<% $onClick %>">';
58     document.getElementById("progress_jobnum").innerHTML = '';
59
60 %   unless ( $url ) {
61         if ( parent.document.<%$formname%>.submit.disabled == true ) {
62           parent.document.<%$formname%>.submit.disabled=false;
63         }
64 %   }
65
66 % } elsif ( $url ) {
67     parent.nd(1);
68     window.top.location.href = '<% $url %>';
69 % } elsif ( $popup_url ) {
70     document.location.replace('<% $popup_url %>');
71 % } else { 
72
73
74     alert('job done but no url or message specified');
75 % } 
76   } else if ( status.indexOf('done') > -1 ) {
77
78     document.getElementById("progress_message").innerHTML = "Loading report";
79     document.getElementById("progress_bar").innerHTML = '';
80     document.getElementById("progress_percent").innerHTML = '';
81     document.getElementById("progress_jobnum").innerHTML = '';
82     window.top.location.href = statustext.substr(8, statustext.length-18);
83
84   } else if ( status.indexOf('error') > -1 ) {
85 %
86 % # default behavior: just close the popup
87 % my $onClick = 'parent.nd(1);';
88 % if ( $error_url ) { # then on clicking to confirm, redirect somewhere
89 %   $onClick = "window.top.location.href = \\'$error_url\\';";
90 % }
91
92     document.getElementById("progress_message").innerHTML = '<FONT SIZE="+1" COLOR="#FF0000">Error: ' + statustext + '</FONT>';
93     document.getElementById("progress_bar").innerHTML = '';
94     document.getElementById("progress_percent").innerHTML = '<INPUT TYPE="button" VALUE="OK" onClick="<% $onClick %>">';
95     document.getElementById("progress_jobnum").innerHTML = '';
96     if ( parent.document.<%$formname%>.submit.disabled == true ) {
97       parent.document.<%$formname%>.submit.disabled=false;
98     }
99   } else {
100     alert('XXX unknown status returned from server: ' + status);
101   }
102   
103 }
104 </SCRIPT>
105
106     <TABLE WIDTH="100%">
107       <TR>
108         <TD ALIGN="center" ID="progress_message">
109           Server processing job...
110         </TD>
111       </TR><TR>
112         <TD ALIGN="center" ID="progress_bar">
113           <SCRIPT TYPE="text/javascript">
114             // Create imagelist
115             SEGS = new QImageList(4, 23, "<%$fsurl%>images/progressbar-empty.png", "<%$fsurl%>images/progressbar-full.png");
116             // Create bars
117             bar1 = new QProgress(null, "bar1", SEGS, 100);
118             // bar1.set(0);
119             // bar1.update;
120           </SCRIPT>
121         </TD>
122       </TR><TR>
123         <TD ALIGN="center">
124           <DIV ID="progress_percent">%</DIV>
125         </TD>
126       </TR><TR>
127         <TD ALIGN="center" ID="progress_jobnum">
128           (progress of job #<% $jobnum %>)
129         </TD>
130       </TR>
131     </TABLE>
132
133   </BODY>
134 </HTML>
135