Skip to content

Commit 631b139

Browse files
committed
Print demo working
1 parent 319ca8d commit 631b139

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

assets/javascripts/gtt_print.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,46 @@ $(function() {
3535
var format = "pdf";
3636
var layout = 0;
3737

38+
console.log(requestData);
39+
var startTime = new Date().getTime();
40+
3841
$.ajax({
3942
type: 'POST',
4043
url: server + "print/" + id + "/report." + format,
4144
data: {
4245
spec: JSON.stringify(requestData)
4346
},
4447
success: function (response) {
45-
console.log(response)
48+
downloadWhenReady(startTime, response.ref);
49+
},
50+
error: function (data) {
51+
console.log(data);
4652
}
4753
});
4854
};
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+
}
4980
});

0 commit comments

Comments
 (0)