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