MARC import: part 5 of large file support
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / background-job.inc
1 <!-- Background job progress indicator -->
2 <script type="text/javascript">
3     //<![CDATA
4     var jobID = '';
5     var savedForm;
6     function updateJobProgress() {
7         $.getJSON("/cgi-bin/koha/tools/background-job-progress.pl?jobID=" + jobID, function(json) {
8             var percentage = Math.floor(100 * json.progress / json.job_size);
9             if (json.job_status == 'completed') {
10                 percentage = 100;
11             }
12             $("#jobprogress").text(percentage + '%');
13             if (percentage < 100) {
14                 setTimeout("updateJobProgress()",200);
15             } else {
16                 completeJob();
17             }
18         });
19     }
20
21     function completeJob() {
22         savedForm.completedJobID.value = jobID;
23         savedForm.submit();
24     }
25
26     // submit a background job with data
27     // supplied from form f and activate
28     // progress indicator
29     function submitBackgroundJob(f) {
30         // check for background field
31         if (f.runinbackground) {
32             // set value of this hidden field for 
33             // use by CGI script
34             savedForm = f;
35             f.mainformsubmit.disabled = true;
36             f.runinbackground.value = 'true';
37
38             // gather up form submission
39             var inputs = [];
40             $(':input', f).each(function() {
41                 if (this.type == 'radio') {
42                     if (this.checked) {
43                         inputs.push(this.name + '=' + escape(this.value));
44                     }
45                 } else if (this.type == 'button') {
46                     ; // do nothing
47                 } else {
48                     inputs.push(this.name + '=' + escape(this.value));
49                 }
50                 
51             });
52
53             // and submit the request
54             $("#jobstatus").show();
55             setTimeout("updateJobProgress()", 2000);
56             $.ajax({
57                 data: inputs.join('&'),
58                 url: f.action,
59                 dataType: 'json',
60                 success: function(json) {
61                     jobID = json.jobID;
62                 },
63                 error: function(xml, textStatus) {
64                     alert('Failed to submit form: ' + testStatus);
65                 }
66
67             });
68
69         } else {
70             // background job support not enabled,
71             // so just do a normal form submission
72             f.submit();
73         }
74         
75         //$("#jobstatus").show();
76         //setTimeout("updateJobProgress()",2000);
77         //updateJobProgress();
78         return false;
79
80     }
81     //]]>
82 </script>