sproutcore/sproutcore — Issue #743: Support progress event on SC.Request
Author: rajeshsegu
Created: 2012-03-10 07:37:58+00:00
State: open

HTML5 browsers today support "progress" event which is very helpful to track file upload progress and heavy responses. We personally are using this progress event extensively and I would like to see this added to the core SC code.

Here is the code that we added to our local X.Request ( extends SC.Request ) class.

SC.Request {

/**
* Callback method whenever request "progress" event fires.
*/
progress: null,

/**
* Helper method to register progress callback method
*/
notifyProgress: function(target, action, params){
this.set("progress", {
target: target,
action: action,
params: params
});
return this;
}

}

SC.Response {

/**
* Add progress events to the raw xmlhttp request
* whenever progress callbacks are set on the Octopus.Upload.Request
* NOTE: Need to update this code whenever we plan to update SC framwork.
*/
invokeTransport: function() {
..........

//Handle Request progess
if(this.getPath("request.progress")){
var progressParams = this.getPath("request.progress");
if(rawRequest.upload){
var target = progressParams.target;
var action = progressParams.action;
var params = progressParams.params;
//Add progress events to raw request object
rawRequest.upload.addEventListener("progress", function(evt){
action.call(target, evt, params);
}, false);
}
}
................
}

Ideally, we should make invokeTransport() method moduler, which would provide extensibility. We could have methods like SC.Response#processRequest which would give better control to coders to process native XMLHttp object.

- Rajesh Segu