File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,46 @@ $(function() {
35
35
var format = "pdf" ;
36
36
var layout = 0 ;
37
37
38
+ console . log ( requestData ) ;
39
+ var startTime = new Date ( ) . getTime ( ) ;
40
+
38
41
$ . ajax ( {
39
42
type : 'POST' ,
40
43
url : server + "print/" + id + "/report." + format ,
41
44
data : {
42
45
spec : JSON . stringify ( requestData )
43
46
} ,
44
47
success : function ( response ) {
45
- console . log ( response )
48
+ downloadWhenReady ( startTime , response . ref ) ;
49
+ } ,
50
+ error : function ( data ) {
51
+ console . log ( data ) ;
46
52
}
47
53
} ) ;
48
54
} ;
55
+
56
+ function downloadWhenReady ( startTime , reference ) {
57
+ if ( ( new Date ( ) . getTime ( ) - startTime ) > 30000 ) {
58
+ console . log ( 'Gave up waiting after 30 seconds' ) ;
59
+ }
60
+ else {
61
+ setTimeout ( function ( ) {
62
+ $ . ajax ( {
63
+ type : 'GET' ,
64
+ url : server + "print/status/" + reference + ".json" ,
65
+ dataType : 'json' ,
66
+ success : function ( response ) {
67
+ if ( ! response . done ) {
68
+ downloadWhenReady ( startTime , reference ) ;
69
+ } else {
70
+ window . location = server + "print/report/" + reference ;
71
+ }
72
+ } ,
73
+ error : function ( data ) {
74
+ console . log ( 'Error occurred requesting status' ) ;
75
+ }
76
+ } ) ;
77
+ } , 500 ) ;
78
+ }
79
+ }
49
80
} ) ;
You can’t perform that action at this time.
0 commit comments