url: baseURL + '/Images/Download/0/myfile.jpg',
newWindow : false,
params: { .... },
+ doctype: 'pdf'
success : function() {
Roo.MessageBox.alert("File has downloaded");
}
* @cfg {String} url Location to download from.
* @cfg {String} method GET or POST (default GET), POST will create a form, and post that into the hidden frame.
* @cfg {Boolean} newWindow (optional) download to new window
-* @cfg {Boolean limit (optional) limit for grid downloads.
+* @cfg {String} doctype (optional) download PDF to new window
+* @cfg {Boolean} limit (optional) limit for grid downloads.
+* @cfg {Boolean} showDownloading default false - show a dialog indicating that the file is downloading
+ * @cfg {String} csvCols - use '*' to override grid coluns
+ * @cfg {String} csvTitles - use '*' to override grid coluns
+ * @cfg {String} hiddenCols - default 'show' (use 'hide' to not display them on download)
+
* @cfg {Function} success (optional) MAY fire on download completed (fails on attachments)..
* @cfg {Number} timeout (optional) in milliseconds before it gives up (default 30000 = 30s)
Pman.Download = function(cfg)
{
+
+
this.params = {};
Roo.apply(this, cfg);
}
- if (cfg.newWindow && this.method == 'GET') {
- // as ie seems buggy...
- window.open( cfg.url + '?' + Roo.urlEncode(cfg.params || {}), '_blank');
+ if (this.newWindow && this.method == 'GET') {
+ // as ie seems buggy...
+ window.open( this.url + '?' + Roo.urlEncode(this.params || {}), '_blank');
return ;
}
- 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);
Roo.log("creating form?");
+ this.form = new FormData();
+ /*
var b = Roo.get(document.body);
this.form = b.createChild({
tag: 'form',
method : this.method,
action : this.url,
- target : this.csvFrame.id,
+ target : this.newWindow ? '_new' : this.csvFrame.id,
enctype : 'multipart/form-data'
-
-
-
});
+ **/
+//
+// if(this.doctype == 'pdf'){
+// this.pdfEmbed = b.createChild({
+// tag: 'embed',
+// src : this.url,
+// pluginspage : 'http://www.adobe.com/products/acrobat/readstep2.html',
+// alt: this.doctype
+// });
+// }
+ //Roo.log(this.params);
+ this.params._get = 1; // always do a post request, with _get passed
for(var i in this.params) {
-
+ this.form.append(i, this.params[i]);
+ /*
var el = this.form.createChild( {
ns : 'html',
tag : 'input',
name : i,
value : this.params[i]
});
+ */
}
+ var req = new XMLHttpRequest();
+ req.responseType = 'blob';
+ req.open('POST', this.url);
+
+ var _t = this;
+ req.onload = function( ev )
+ {
+ if (req.status == 200) {
+ 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(ev) : '';
+ }
+
+ }
+ if (this.showDownloading) {
+ Roo.MessageBox.alert("Downloading", "The file should download shortly");
+ }
+ req.send(this.form);
+ /*
(function() {
this.submit = true;
this.form.dom.submit();
this.cleanup.defer(this.timeout || 30000,this);
}).defer(100, this);
-
+ */
}
method : 'GET',
+ success : false,
+ failure : false,
+
+ hiddenCols : 'show', // set to 'hide' to hide them..
+
+ showDownloading : 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..
if (!this.submit) {
return false;
}
- return false;
+ //return false;
var frame = this.csvFrame;
var success = true;
Roo.MessageBox.alert("Download Error", doc.body.innerHTML);
success = false;
-
-
+ if (this.failure) {
+ this.failure();
+ }
+ return true;
}
Roo.log(doc.body.innerHTML);
Roo.log(e.toString());
Roo.log(e);
}
+ if (this.success) {
+ this.success();
+ }
// we can not actually do anything with the frame... as it may actually still be downloading..
return true;
},
-
+ */
// private - clean up download elements.
cleanup :function()
{
- Roo.log('cleanup?');
+ /* Roo.log('cleanup?');
if (this.form) {
this.form.remove();
this.form= false;
Roo.get(this.csvFrame).remove();
this.csvFrame= false;
}
+ */
},
this.url = this.grid.ds.proxy.conn.url;
- this.method = this.grid.ds.proxy.conn.method ;
+ this.method = this.method || this.grid.ds.proxy.conn.method ;
var t = this;
// work out the cols
- Roo.each(this.grid.cm.config, function(c,i) {
- t.params['csvCols['+i+']'] = c.dataIndex;
- t.params['csvTitles['+i+']'] = c.header;
-
- });
+ if (this.csvCols) {
+ t.params.csvCols = this.csvCols;
+ t.params.csvTitles = this.csvTitles;
+ } else {
+
+ Roo.each(this.grid.cm.config, function(c,i) {
+
+ if (t.hiddenCols != 'show' && t.grid.cm.isHidden(i)) {
+ return;
+ }
+
+ t.params['csvCols['+i+']'] = c.dataIndex;
+ t.params['csvTitles['+i+']'] = c.header;
+
+ });
+ }
if (this.grid.loadMask) {
this.grid.loadMask.onLoad();
}
this.params.limit = this.limit;
// do it as a post, as args can get long..
- this.params._get = 1;
- this.method = 'POST';
+ this.method = 'POST';
+ if (this.method == 'POST') {
+ this.params._get = 1;
+ }
}
-
-
-
-
-
-
});