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