nsinject.js
authorAlan Knowles <alan@roojs.com>
Mon, 10 Sep 2012 03:04:57 +0000 (11:04 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 10 Sep 2012 03:04:57 +0000 (11:04 +0800)
nsinject.js

index b0b9d3a..a520ffc 100644 (file)
@@ -1,4 +1,5 @@
 NS = {
+    timeout : 10,
     
     rungrab : function(id)
     {
@@ -7,78 +8,9 @@ NS = {
         var timeout = 10;
         var frameload = function()
         {
-            var ifd = ifr.contentWindow.document;
-            var chk = ifd.getElementById('lines');
-            if (!ifd.getElementById('rptdataarea') || !ifr.contentWindow.reportTable
-                ) {
-                console.log('report not ready?');
-                window.setTimeout(frameload,1000);
-                return;
-                
-            }
-            
-            
-            console.log('report ready?');
-            
-            if (chk.value !='T') {
-                chk.value= 'T';
-                ifd.forms[0].daterange.value = 'CUSTOM';
-
-                ifd.getElementById('date1').value = '1/1/2008';
-                ifd.getElementById('date2').value = '1/1/2013';
-                
-                ifd.getElementById('footerform').submit();
-                
-                return;
-            }
-            
-            if (   ifr.contentWindow.reportTable.oContentProvider.bRequestPending
-                || !ifr.contentWindow.reportTable.isInLoadedState()) {
-                console.log('report not ready?');
-                timeout--;
-                if (timeout < 0) {
-                    console.log(
-                         JSON.stringify ({
-                            requesturl : '',
-                            method: 'nsdownloadpage',
-                            filename : NS.id + '.csv',
-                            headers : '',
-                            contentType: '',
-                            data: []
-                        }));
-                    return;
-                    
-                    
-                }
-                
-                window.setTimeout(frameload,1000);
-                
-                return;
-                
-            }
-            
-            
+             
             
-            console.log("TRY downloading!");
             
-            var ar = ifd.getElementById('footerform').elements;
-            var data= {};
-            for(var i =0; i < ar.length; i++) {
-                var e = ar[i];
-                data[e.name] = e.value;
-            }
-            console.log(data);
-            console.log(ifr.contentWindow.reportTable.getTotalRowCount());
-             NS.downloaddata(
-                'https://system.netsuite.com/app/reporting/reportrunner.nl',
-                {
-                    id: data.id,
-                    reportaction: 'exportcsv',
-                    apptype: 'html',
-                    visibleranges: '0,' +  ifr.contentWindow.reportTable.getTotalRowCount()
-                }
-                
-            );
             
         }
         console.log("document.location" + document.location);
@@ -116,8 +48,8 @@ NS = {
          if (   reportTable.oContentProvider.bRequestPending
                 || !reportTable.isInLoadedState()) {
                 console.log('report not ready?');
-                timeout--;
-                if (timeout < 0) {
+                NS.timeout--;
+                if (NS.timeout < 0) {
                     console.log('SENDING EMTPY..?');
                     console.log(
                          JSON.stringify ({
@@ -133,7 +65,7 @@ NS = {
                     
                 }
                 
-                window.setTimeout(frameload,1000);
+                window.setTimeout(rungrab,1000);
                 
                 return;
                 
@@ -141,6 +73,30 @@ NS = {
         
         
         console.log("got rungrab");
+        
+        console.log("TRY downloading!");
+            
+        var ar = document.getElementById('footerform').elements;
+        var data= {};
+        for(var i =0; i < ar.length; i++) {
+            var e = ar[i];
+            data[e.name] = e.value;
+        }
+        console.log(data);
+        console.log(document.reportTable.getTotalRowCount());
+         NS.downloaddata(
+            'https://system.netsuite.com/app/reporting/reportrunner.nl',
+            {
+                id: data.id,
+                reportaction: 'exportcsv',
+                apptype: 'html',
+                visibleranges: '0,' +  document.reportTable.getTotalRowCount()
+            }
+            
+        );
+        
+        
+        
         return;