From 5bcf34aba512440d181347598dd79c179d4bc9a8 Mon Sep 17 00:00:00 2001 From: Queen Vinyl Darkscratch Date: Tue, 15 Oct 2019 16:32:43 -0700 Subject: [PATCH] Add events for form upload progress --- applications/welcome/static/js/web2py.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index 8eaf54aa..80138930 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -367,6 +367,24 @@ 'data': data, 'processData': !isFormData, 'contentType': contentType, + 'xhr': function() { + var xhr = new window.XMLHttpRequest(); + + xhr.upload.addEventListener("progress", function(evt) { + if (evt.lengthComputable) { + var percentComplete = evt.loaded / evt.total; + percentComplete = parseInt(percentComplete * 100); + web2py.fire(element, 'w2p:uploadProgress', [percentComplete], target); + + if (percentComplete === 100) { + web2py.fire(element, 'w2p:uploadComplete', [], target); + } + + } + }, false); + + return xhr; + }, 'beforeSend': function (xhr, settings) { xhr.setRequestHeader('web2py-component-location', document.location); xhr.setRequestHeader('web2py-component-element', target);