Pman.Download = function(cfg)
{
+
+
this.params = {};
Roo.apply(this, cfg);
- this.submit = false;
- this.createCsvFrame();
+ //this.submit = false;
+ //this.createCsvFrame();
- var requested = 0;
+ //var requested = 0;
- Roo.EventManager.on( this.csvFrame, 'load', this.onLoad, this);
+ //Roo.EventManager.on( this.csvFrame, 'load', this.onLoad, this);
//--- simple method..
if (this.method == 'GET' && !this.params) {
(function() {
+
+
+ this.createCsvFrame();
+ //Roo.EventManager.on( this.csvFrame, 'load', this.onLoad, this);
this.submit = true;
this.csvFrame.src = cfg.url;
//this.cleanup.defer(cfg.timeout || 30000,this);
}
var req = new XMLHttpRequest();
+ req.responseType = 'blob';
req.open(this.method, this.url);
var _t = this;
req.onload = function( ev )
{
if (req.status == 200) {
- _t.success ? _t.sucess() : '';
+ Roo.log(ev);
+ var cd = req.getResponseHeader('Content-Disposition');
+
+ var filename = '';
+ var matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(cd);
+ if (matches != null && matches[1]) {
+ filename = matches[1].replace(/['"]/g, '');
+ }
+
+ var blob = new Blob([req.response], {type: req.responseType });
+
+ var a = document.createElement("a");
+ a.style = "display: none";
+ document.body.appendChild(a);
+ var url = window.URL.createObjectURL(blob);
+ a.href = url;
+ a.download = filename;
+ a.click();
+ //release the reference to the file by revoking the Object URL
+ window.URL.revokeObjectURL(url);
+
+ _t.success ? _t.success(ev) : '';
} else {
- _t.failure ? _t.failure() : '';
+ _t.failure ? _t.failure(ev) : '';
}
}
failure : false,
// private..
+ //used by simple GET method.
createCsvFrame: function()
{
if (this.csvFrame) {
}
},
-
+ /* not used as it didn't work..
onLoad : function()
{
// requested++; // second request is real one..
},
-
+ */
// private - clean up download elements.
cleanup :function()
{