Pman.Download.js
[Pman.Core] / Pman.Download.js
index 1a35433..71eef77 100644 (file)
@@ -51,9 +51,6 @@ Pman.Download = function(cfg)
     
     if (this.newWindow && this.method == 'GET') {
         // as ie seems buggy...
-        var url = cfg.url || this.url;
-        var params = cfg.params || this.params;
-        
         window.open( this.url + '?' + Roo.urlEncode(this.params || {}), '_blank');
         return ; 
         
@@ -61,12 +58,12 @@ Pman.Download = function(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..
@@ -86,6 +83,8 @@ Pman.Download = function(cfg)
     
     Roo.log("creating form?");
     
+    this.form = new FormData();
+    /*
     var b = Roo.get(document.body);
     this.form = b.createChild({
         tag: 'form',
@@ -94,6 +93,7 @@ Pman.Download = function(cfg)
         target : this.newWindow ? '_new' : this.csvFrame.id,
         enctype : 'multipart/form-data'
     });
+    **/
 //    
 //    if(this.doctype == 'pdf'){
 //        this.pdfEmbed = b.createChild({
@@ -104,9 +104,10 @@ Pman.Download = function(cfg)
 //        });
 //    }
  
+    Roo.log(this.params);
     for(var i in this.params) {
-        
+        this.form.append(i, this.params[i]);
+        /*
         var el = this.form.createChild( {
             ns : 'html',
             tag : 'input',
@@ -115,16 +116,32 @@ Pman.Download = function(cfg)
             name : i,
             value : this.params[i]
         });
+        */
         
         
+    }
+    var req = new XMLHttpRequest();
+    req.open(this.method, this.url);
+    
+    var _t = this;
+    req.onload = function( ev )
+    {
+        if (req.status == 200) {
+            _t.success ? _t.sucess() : '';
+        } else {
+            _t.failure ? _t.failure() : '';
+        }
+        
     }
     
+    req.send(this.form);
+    /*
     (function() {
         this.submit = true;
         this.form.dom.submit();
         this.cleanup.defer(this.timeout || 30000,this);
     }).defer(100, this);
-    
+    */
      
  
 }
@@ -146,7 +163,11 @@ Roo.apply(Pman.Download.prototype, {
     
     method : 'GET',
     
+    success : false,
+    failure : false,
+    
     // private..
+    /*
     createCsvFrame: function()
     {
         if (this.csvFrame) {
@@ -168,7 +189,7 @@ Roo.apply(Pman.Download.prototype, {
         }
         
     },
-    
+   
     onLoad : function()
     {
        // requested++; // second request is real one..
@@ -179,7 +200,7 @@ Roo.apply(Pman.Download.prototype, {
         if (!this.submit) {
             return false;
         }
-        return false;
+        //return false;
       
         var frame = this.csvFrame;
         var success  = true; 
@@ -194,8 +215,10 @@ Roo.apply(Pman.Download.prototype, {
                   
                 Roo.MessageBox.alert("Download Error", doc.body.innerHTML);
                 success  = false;
-                 
-                
+                if (this.failure) {
+                    this.failure();
+                }
+                return true;
             }
             
             Roo.log(doc.body.innerHTML);
@@ -205,6 +228,9 @@ Roo.apply(Pman.Download.prototype, {
             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;
     
@@ -220,11 +246,11 @@ Roo.apply(Pman.Download.prototype, {
         
 
     },
-    
+     */
     // private - clean up download elements.
     cleanup :function()
     {
-        Roo.log('cleanup?');
+       /* Roo.log('cleanup?');
         if (this.form) {
             this.form.remove();
             this.form= false;
@@ -236,6 +262,7 @@ Roo.apply(Pman.Download.prototype, {
             Roo.get(this.csvFrame).remove();
             this.csvFrame= false;
         }
+        */
          
     },