Bug 12150 - Use more javascript string formatting in intranet for translated strings.
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / file-upload.inc
1 <!-- AJAX file upload stuff -->
2 <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/ajaxfileupload.js"></script>
3 <script type="text/javascript">
4     //<![CDATA[
5     var fileUploadProgressTimer = 0;
6     var inFileUploadProgressTimer = false;
7     var fileUploadProgressTimerCanceled = false;
8     function updateProgress() {
9         if (inFileUploadProgressTimer) {
10             // since $.getJSON is asynchronous, wait
11             // until the last one is finished
12             return;
13         }
14         inFileUploadProgressTimer = true;
15         $.getJSON("/cgi-bin/koha/tools/upload-file-progress.pl", function(json) {
16             if (!fileUploadProgressTimerCanceled) {
17                                 var bgproperty = (parseInt(json.progress)*2-300)+"px 0px";
18                 $("#fileuploadprogress").css("background-position",bgproperty);
19                                 $("#fileuploadpercent").text(json.progress);
20             }
21             inFileUploadProgressTimer = false;
22         });
23     }
24     function ajaxFileUpload()
25     {
26         fileUploadProgressTimerCanceled = false;
27                 $("#uploadpanel").show();
28         $("#fileuploadstatus").show();
29         fileUploadProgressTimer = setInterval("updateProgress()",500);
30         $.ajaxFileUpload (
31             {
32                 url:'/cgi-bin/koha/tools/upload-file.pl',
33                 secureuri:false,
34                 global:false,
35                 fileElementId:'fileToUpload',
36                 dataType: 'json',
37                 success: function (data, status) {
38                     if (data.status == 'denied') {
39                         $("#fileuploadstatus").hide();
40                         $("#fileuploadfailed").show();
41                         $("#fileuploadfailed").text("Upload failed -- no permission to upload files");
42                     } else if (data.status == 'failed') {
43                         $("#fileuploadstatus").hide();
44                         $("#fileuploadfailed").show();
45                         $("#fileuploadfailed").text("Upload failed -- unable to store file on server");
46                     } else if (data.status == 'maintenance') {
47                         $("#fileuploadstatus").hide();
48                         $("#fileuploadfailed").show();
49                         $("#fileuploadfailed").text("Upload failed -- database in maintenance state");
50                     } else {
51                          $("#uploadedfileid").val(data.fileid);
52                          $("#fileuploadprogress").css("background-position","0px 0px");
53                                                  $("#processfile").show();
54                         $("#fileuploadpercent").text("100");
55                     }
56                     fileUploadProgressTimerCanceled = true;
57                     clearInterval(fileUploadProgressTimer);
58                 },
59                 error: function (data, status, e) {
60                     fileUploadProgressTimerCanceled = true;
61                     alert(e);
62                     clearInterval(fileUploadProgressTimer);
63                 }
64             }
65         )
66         return false;
67
68     }
69     //]]>
70 </script>