d2395464e5546cbc24ff5a946d18d55326d36891
[infodrom/rico3] / minsrc / ricoLiveGridAjax.js
1 /*
2  *  (c) 2005-2011 Richard Cowin (http://openrico.org)
3  *  (c) 2005-2011 Matt Brown (http://dowdybrown.com)
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6  *  file except in compliance with the License. You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software distributed under the
11  *  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12  *  either express or implied. See the License for the specific language governing permissions
13  *  and limitations under the License.
14  */
15
16 if(typeof Rico=='undefined') throw("LiveGridAjax requires the Rico JavaScript framework");
17
18 if (!Rico.Buffer) Rico.Buffer = {};
19
20 Rico.Buffer.AjaxLoadOnce = function(url,options,ajaxOptions) {
21   this.initialize(url,options,ajaxOptions);
22 }
23
24 Rico.Buffer.AjaxLoadOnce.prototype = {
25 /**
26  * @class Implements buffer for LiveGrid. Loads data from server via a single AJAX call.
27  * @extends Rico.Buffer.Base
28  * @constructs
29  */
30   initialize: function(url,options,ajaxOptions) {
31     Rico.extend(this, new Rico.Buffer.Base());
32     Rico.extend(this, Rico.Buffer.AjaxXMLMethods);
33     this.dataSource=url;
34     this.options.bufferTimeout=20000;            // time to wait for ajax response (milliseconds)
35     this.options.requestParameters=[];
36     this.options.waitMsg=Rico.getPhraseById("waitForData");  // replace this with an image tag if you prefer
37     this.options.canFilter=true;
38     this.options.fmt='xml';
39     Rico.extend(this.options, options || {});
40     this.ajaxOptions = { parameters: null, method : 'get' };
41     Rico.extend(this.ajaxOptions, ajaxOptions || {});
42     this.requestCount=0;
43     this.processingRequest=false;
44     this.pendingRequest=-2;
45     this.fetchData=true;
46     this.sortParm={};
47   }
48 }
49
50 Rico.Buffer.AjaxXMLMethods = {
51
52 /** @lends Rico.Buffer.AjaxLoadOnce# */
53   fetch: function(offset) {
54     if (this.fetchData) {
55       this.foundRowCount=true;
56       this.fetchData=false;
57       this.processingRequest=true;
58       this.liveGrid.showMsg(this.options.waitMsg);
59       this.timeoutHandler = Rico.runLater(this.options.bufferTimeout,this,'handleTimedOut');
60       this.ajaxOptions.parameters = this.formQueryHashXML(0,-1);
61       Rico.log('sending request');
62       var self=this;
63       if (typeof this.dataSource=='string') {
64         this.ajaxOptions.onComplete = function(xhr) { self.ajaxUpdate(offset,xhr); };
65         new Rico.ajaxRequest(this.dataSource, this.ajaxOptions);
66       } else {
67         this.ajaxOptions.onComplete = function(newRows, newStyle, totalRows, errMsg) { self.jsUpdate(offset, newRows, newStyle, totalRows, errMsg); };
68         this.dataSource(this.ajaxOptions);
69       }
70     } else {
71       if (offset < 0) {
72         this.applyFilters();
73         this.setTotalRows(this.size);
74         offset=0;
75       }
76       this.liveGrid.refreshContents(offset);
77     }
78   },
79
80 /**
81  * Server did not respond in time... assume that there could have been
82  * an error, and allow requests to be processed again.
83  */
84   handleTimedOut: function() {
85     Rico.log("Request Timed Out");
86     this.liveGrid.showMsg(Rico.getPhraseById("requestTimedOut"));
87   },
88
89   formQueryHashXML: function(startPos,fetchSize) {
90     var queryHash= {
91       id: this.liveGrid.tableId,
92       page_size: (typeof fetchSize=='number') ? fetchSize : this.totalRows,
93       offset: startPos.toString()
94     };
95     queryHash[this.liveGrid.actionId]="query";
96     if (this.options.requestParameters) {
97       for ( var i=0; i < this.options.requestParameters.length; i++ ) {
98         var anArg = this.options.requestParameters[i];
99         if ( anArg.name != undefined && anArg.value != undefined ) {
100           queryHash[anArg.name]=anArg.value;
101         } else {
102           var ePos  = anArg.indexOf('=');
103           var argName  = anArg.substring( 0, ePos );
104           var argValue = anArg.substring( ePos + 1 );
105           queryHash[argName]=argValue;
106         }
107       }
108     }
109     return queryHash;
110   },
111
112   clearTimer: function() {
113     if(typeof this.timeoutHandler != "number") return;
114     window.clearTimeout(this.timeoutHandler);
115     delete this.timeoutHandler;
116   },
117
118   // used by both LoadOnce and SQL buffers
119   jsUpdate: function(startPos, newRows, newStyle, totalRows, errMsg) {
120     this.clearTimer();
121     this.processingRequest=false;
122     Rico.log("jsUpdate: "+arguments.length);
123     if (errMsg) {
124       Rico.log("jsUpdate: received error="+errMsg);
125       this.liveGrid.showMsg(Rico.getPhraseById("requestError",errMsg));
126       return;
127     }
128     this.rcvdRows = newRows.length;
129     if (typeof totalRows=='number') {
130       this.rowcntContent = totalRows.toString();
131       this.rcvdRowCount = true;
132       this.foundRowCount = true;
133       Rico.log("jsUpdate: found RowCount="+this.rowcntContent);
134     }
135     this.updateBuffer(startPos, newRows, newStyle);
136     if (this.options.onAjaxUpdate)
137       this.options.onAjaxUpdate();
138     this.updateGrid(startPos);
139     if (this.options.TimeOut && this.timerMsg)
140       this.restartSessionTimer();
141     if (this.pendingRequest>=-1) {
142       var offset=this.pendingRequest;
143       Rico.log("jsUpdate: found pending request for offset="+offset);
144       this.pendingRequest=-2;
145       this.fetch(offset);
146     }
147   },
148
149   // used by both LoadOnce and SQL buffers
150   ajaxUpdate: function(startPos,xhr) {
151     this.clearTimer();
152     this.processingRequest=false;
153     if (xhr.status != 200) {
154       Rico.log("ajaxUpdate: received http error="+xhr.status);
155       this.liveGrid.showMsg(Rico.getPhraseById("httpError",xhr.status));
156       return;
157     }
158     Rico.log("ajaxUpdate: startPos="+startPos);
159     this._responseHandler=this['processResponse'+this.options.fmt.toUpperCase()];
160     if (!this._responseHandler(startPos,xhr)) return;
161     if (this.options.onAjaxUpdate)
162       this.options.onAjaxUpdate();
163     this.updateGrid(startPos);
164     if (this.options.TimeOut && this.timerMsg)
165       this.restartSessionTimer();
166     if (this.pendingRequest>=-1) {
167       var offset=this.pendingRequest;
168       Rico.log("ajaxUpdate: found pending request for offset="+offset);
169       this.pendingRequest=-2;
170       this.fetch(offset);
171     }
172   },
173   
174   // used by both LoadOnce and SQL buffers
175   processResponseXML: function(startPos,request) {
176     // The response text may contain META DATA for debugging if client side debugging is enabled in VS\r
177     var xmlDoc = request.responseXML;\r
178     if (request.responseText.substring(0, 4) == "<!--") {\r
179       var nEnd = request.responseText.indexOf("-->");\r
180       if (nEnd == -1) {\r
181         this.liveGrid.showMsg('Web server error - client side debugging may be enabled');\r
182         return false;\r
183       }\r
184       xmlDoc = Rico.createXmlDocument();\r
185       xmlDoc.loadXML(request.responseText.substring(nEnd+3));\r
186     }
187     
188     if (!xmlDoc) {
189       alert("Data provider returned an invalid XML response");
190       Rico.log("Data provider returned an invalid XML response");
191       return false;
192     }
193
194     // process children of <ajax-response>
195     var response = xmlDoc.getElementsByTagName("ajax-response");
196     if (response == null || response.length != 1) {
197       alert("Received invalid response from server");
198       return false;
199     }
200     Rico.log("Processing ajax-response");
201     this.rcvdRows = 0;
202     this.rcvdRowCount = false;
203     var ajaxResponse=response[0];
204     var debugtags = ajaxResponse.getElementsByTagName('debug');
205     for (var i=0; i<debugtags.length; i++)
206       Rico.log("ajaxUpdate: debug msg "+i+": "+Rico.getContentAsString(debugtags[i],this.options.isEncoded));
207     var error = ajaxResponse.getElementsByTagName('error');
208     if (error.length > 0) {
209       var msg=Rico.getContentAsString(error[0],this.options.isEncoded);
210       alert("Data provider returned an error:\n"+msg);
211       Rico.log("Data provider returned an error:\n"+msg);
212       return false;
213     }
214     var rowsElement = ajaxResponse.getElementsByTagName('rows')[0];
215     if (!rowsElement) {
216       Rico.log("ajaxUpdate: invalid response");
217       this.liveGrid.showMsg(Rico.getPhraseById("invalidResponse"));
218       return false;
219     }
220     var rowcnttags = ajaxResponse.getElementsByTagName('rowcount');
221     if (rowcnttags && rowcnttags.length==1) {
222       this.rowcntContent = Rico.getContentAsString(rowcnttags[0],this.options.isEncoded);
223       this.rcvdRowCount = true;
224       this.foundRowCount = true;
225       Rico.log("ajaxUpdate: found RowCount="+this.rowcntContent);
226     }
227
228     // process <rows>
229     this.updateUI = rowsElement.getAttribute("update_ui") == "true";
230     this.rcvdOffset = rowsElement.getAttribute("offset");
231     Rico.log("ajaxUpdate: rcvdOffset="+this.rcvdOffset);
232     var newRows = this.dom2jstable(rowsElement);
233     var newStyle = (this.options.acceptStyle) ? this.dom2jstableStyle(rowsElement) : false;
234     this.rcvdRows = newRows.length;
235     this.updateBuffer(startPos, newRows, newStyle);
236     return true;
237   },
238
239   dom2jstableStyle: function(rowsElement,firstRow) {
240     Rico.log("dom2jstableStyle start");
241     var newRows = [];
242     var trs = rowsElement.getElementsByTagName("tr");
243     for ( var i=firstRow || 0; i < trs.length; i++ ) {
244       var row = [];
245       var cells = trs[i].getElementsByTagName("td");
246       for ( var j=0; j < cells.length ; j++ ) {
247         row[j]=cells[j].getAttribute('style') || '';
248       }
249       newRows.push( row );
250     }
251     Rico.log("dom2jstableStyle end");
252     return newRows;
253   },
254
255   processResponseJSON: function(startPos,request) {
256     var json = Rico.getJSON(request);
257     if (!json || json == null) {
258       alert("Data provider returned an invalid JSON response");
259       Rico.log("Data provider returned an invalid JSON response");
260       return false;
261     }
262
263     if (json.debug) {
264       for (var i=0; i<json.debug.length; i++)
265         Rico.writeDebugMsg("debug msg "+i+": "+json.debug[i]);
266     }
267     if (json.error) {
268       alert("Data provider returned an error:\n"+json.error);
269       Rico.writeDebugMsg("Data provider returned an error:\n"+json.error);
270       return false;
271     }
272
273     if (json.rowcount) {
274       this.rowcntContent = json.rowcount;
275       this.rcvdRowCount = true;
276       this.foundRowCount = true;
277       Rico.writeDebugMsg("loadRows, found RowCount="+json.rowcount);
278     }
279
280     this.rcvdRows = json.rows.length;
281     this.updateBuffer(startPos, json.rows, json.styles);
282     return true;
283   },
284
285   // specific to LoadOnce buffer
286   updateBuffer: function(start, newRows, newStyle) {
287     this.baseRows = newRows;
288     this.attr = newStyle;
289     Rico.log("updateBuffer: # of rows="+this.rcvdRows);
290     this.rcvdRowCount=true;
291     this.rowcntContent=this.rcvdRows;
292     if (typeof this.delayedSortCol=='number')
293       this.sortBuffer(this.delayedSortCol);
294     this.applyFilters();
295     this.startPos = 0;
296   },
297
298   // used by both LoadOnce and SQL buffers
299   updateGrid: function(offset) {
300     Rico.log("updateGrid, size="+this.size+' rcv cnt type='+typeof(this.rowcntContent));
301     var newpos;
302     if (this.rcvdRowCount==true) {
303       Rico.log("found row cnt: "+this.rowcntContent);
304       var eofrow=parseInt(this.rowcntContent,10);
305       var lastTotalRows=this.totalRows;
306       if (!isNaN(eofrow) && eofrow!=lastTotalRows) {
307         this.setTotalRows(eofrow);
308         newpos=Math.min(this.liveGrid.topOfLastPage(),offset);
309         Rico.log("updateGrid: new rowcnt="+eofrow+" newpos="+newpos);
310         this.liveGrid.scrollToRow(newpos);
311         if ( this.isInRange(newpos) ) {
312           this.liveGrid.refreshContents(newpos);
313         } else {
314           this.fetch(newpos);
315         }
316         return;
317       }
318     } else {
319       var lastbufrow=offset+this.rcvdRows;
320       if (lastbufrow>this.totalRows) {
321         var newcnt=lastbufrow;
322         Rico.log("extending totrows to "+newcnt);
323         this.setTotalRows(newcnt);
324       }
325     }
326     newpos=this.liveGrid.pixeltorow(this.liveGrid.scrollDiv.scrollTop);
327     Rico.log("updateGrid: newpos="+newpos);
328     this.liveGrid.refreshContents(newpos);
329   }
330
331 };
332
333
334
335 Rico.Buffer.AjaxSQL = function(url,options,ajaxOptions) {
336   this.initialize(url,options,ajaxOptions);
337 }
338
339 Rico.Buffer.AjaxSQL.prototype = {
340 /**
341  * @class Implements buffer for LiveGrid. Loads data from server in chunks as user scrolls through the grid.
342  * @extends Rico.Buffer.AjaxLoadOnce
343  * @constructs
344  */
345   initialize: function(url,options,ajaxOptions) {
346     Rico.extend(this, new Rico.Buffer.AjaxLoadOnce());
347     Rico.extend(this, Rico.Buffer.AjaxSQLMethods);
348     this.dataSource=url;
349     this.options.canFilter=true;
350     this.options.largeBufferSize  = 7.0;   // 7 pages
351     this.options.nearLimitFactor  = 1.0;   // 1 page
352     this.options.canRefresh=true;
353     Rico.extend(this.options, options || {});
354     Rico.extend(this.ajaxOptions, ajaxOptions || {});
355   }
356 }
357
358 Rico.Buffer.AjaxSQLMethods = {
359 /** @lends Rico.Buffer.AjaxSQL# */
360
361   registerGrid: function(liveGrid) {
362     this.liveGrid = liveGrid;
363     this.sessionExpired=false;
364     this.timerMsg=document.getElementById(liveGrid.tableId+'_timer');
365     if (this.options.TimeOut && this.timerMsg) {
366       if (!this.timerMsg.title) this.timerMsg.title=Rico.getPhraseById("sessionExpireMinutes");
367       this.restartSessionTimer();
368     }
369   },
370
371   setBufferSize: function(pageSize) {
372     this.maxFetchSize = Math.max(50,parseInt(this.options.largeBufferSize * pageSize,10));
373     this.nearLimit = parseInt(this.options.nearLimitFactor * pageSize,10);
374     this.maxBufferSize = this.maxFetchSize * 3;
375   },
376
377   restartSessionTimer: function() {
378     if (this.sessionExpired==true) return;
379     this.sessionEndTime = (new Date()).getTime() + this.options.TimeOut*60000;
380     if (this.sessionTimer) clearTimeout(this.sessionTimer);
381     this.updateSessionTimer();
382   },
383
384   updateSessionTimer: function() {
385     var now=(new Date()).getTime();
386     if (now > this.sessionEndTime) {
387       this.displaySessionTimer(Rico.getPhraseById("sessionExpired"));
388       this.timerMsg.style.backgroundColor="red";
389       this.sessionExpired=true;
390     } else {
391       var timeRemaining=Math.ceil((this.sessionEndTime - now) / 60000);
392       this.displaySessionTimer(timeRemaining);
393       this.sessionTimer=Rico.runLater(10000,this,'updateSessionTimer');
394     }
395   },
396
397   displaySessionTimer: function(msg) {
398     this.timerMsg.innerHTML='&nbsp;'+msg+'&nbsp;';
399   },
400
401   /**
402    * Update the grid with fresh data from the database, maintaining scroll position.
403    * @param resetRowCount indicates whether the total row count should be refreshed as well
404    */
405   refresh: function(resetRowCount) {
406     var lastGridPos=this.liveGrid.lastRowPos;\r
407     this.clear();
408     if (resetRowCount) {
409       this.setTotalRows(0);
410       this.foundRowCount = false;
411     }
412     this.liveGrid.clearBookmark();
413     this.liveGrid.clearRows();
414     this.fetch(lastGridPos);
415   },
416
417   /**
418    * Fetch data from database.
419    * @param offset position (row) within the dataset (-1=clear existing buffer before issuing request)
420    */
421   fetch: function(offset) {
422     Rico.log("AjaxSQL fetch: offset="+offset+', lastOffset='+this.lastOffset);
423     if (this.processingRequest) {
424       Rico.log("AjaxSQL fetch: queue request");
425       this.pendingRequest=offset;
426       return;
427     }
428     if ((typeof offset == 'undefined') || (offset < 0)) {
429       this.clear();
430       this.setTotalRows(0);
431       this.foundRowCount = false;
432       offset=0;
433     }
434     var lastOffset = this.lastOffset;
435     this.lastOffset = offset;
436     if (this.isInRange(offset)) {
437       Rico.log("AjaxSQL fetch: in buffer");
438       this.liveGrid.refreshContents(offset);
439       if (offset > lastOffset) {
440         if (offset+this.liveGrid.pageSize < this.endPos()-this.nearLimit) return;
441         if (this.endPos()==this.totalRows && this.foundRowCount) return;
442       } else if (offset < lastOffset) {
443         if (offset > this.startPos+this.nearLimit) return;
444         if (this.startPos==0) return;
445       } else return;
446     }
447     if (offset >= this.totalRows && this.foundRowCount) return;
448
449     this.processingRequest=true;
450     Rico.log("AjaxSQL fetch: processing offset="+offset);
451     var bufferStartPos = this.getFetchOffset(offset);
452     var fetchSize = this.getFetchSize(bufferStartPos);
453     var partialLoaded = false;
454
455     this.liveGrid.showMsg(this.options.waitMsg);
456     this.timeoutHandler = Rico.runLater(this.options.bufferTimeout, this, 'handleTimedOut');
457     this.ajaxOptions.parameters = this.formQueryHashSQL(bufferStartPos,fetchSize,this.options.fmt);
458     this.requestCount++;
459     Rico.log('sending req #'+this.requestCount);
460     var self=this;
461     if (typeof this.dataSource=='string') {
462       this.ajaxOptions.onComplete = function(xhr) { self.ajaxUpdate(bufferStartPos, xhr); };
463       new Rico.ajaxRequest(this.dataSource, this.ajaxOptions);
464     } else {
465       this.ajaxOptions.onComplete = function(newRows, newStyle, totalRows, errMsg) { self.jsUpdate(bufferStartPos, newRows, newStyle, totalRows, errMsg); };
466       this.dataSource(this.ajaxOptions);
467     }
468   },
469
470   formQueryHashSQL: function(startPos,fetchSize,fmt) {
471     var queryHash=this.formQueryHashXML(startPos,fetchSize);
472     if (!this.foundRowCount) queryHash['get_total']='true';
473     if (fmt) queryHash._fmt=fmt;
474
475     // sort
476     Rico.extend(queryHash,this.sortParm);
477
478     // filters
479     for (var n=0; n<this.liveGrid.columns.length; n++) {
480       var c=this.liveGrid.columns[n];
481       if (c.filterType == Rico.ColumnConst.UNFILTERED) continue;
482       var colnum=typeof(c.format.filterCol)=='number' ? c.format.filterCol : c.index;
483       queryHash['f['+colnum+'][op]']=c.filterOp;
484       queryHash['f['+colnum+'][len]']=c.filterValues.length;
485       for (var i=0; i<c.filterValues.length; i++) {
486         var fval=c.filterValues[i];
487         if (c.filterOp=='LIKE' && fval.indexOf('*')==-1) {
488             if (c.format.filterUI.charAt(1) == '^') fval=fval+'*';
489             else if (c.format.filterUI.charAt(1) == '$') fval='*'+fval;
490             else fval='*'+fval+'*';
491         }
492         queryHash['f['+colnum+']['+i+']']=fval;
493       }
494     }
495     return queryHash;
496   },
497
498   getFetchSize: function(adjustedOffset) {
499     var adjustedSize = 0;
500     if (adjustedOffset >= this.startPos) { //appending
501       var endFetchOffset = this.maxFetchSize + adjustedOffset;
502       adjustedSize = endFetchOffset - adjustedOffset;
503       if(adjustedOffset == 0 && adjustedSize < this.maxFetchSize)
504         adjustedSize = this.maxFetchSize;
505       Rico.log("getFetchSize/append, adjustedSize="+adjustedSize+" adjustedOffset="+adjustedOffset+' endFetchOffset='+endFetchOffset);
506     } else { //prepending
507       adjustedSize = Math.min(this.startPos - adjustedOffset,this.maxFetchSize);
508     }
509     return adjustedSize;
510   },
511
512   getFetchOffset: function(offset) {
513     var adjustedOffset = offset;
514     if (offset > this.startPos)
515       adjustedOffset = Math.max(offset, this.endPos());  //appending
516     else if (offset + this.maxFetchSize >= this.startPos)
517       adjustedOffset = Math.max(this.startPos - this.maxFetchSize, 0);  //prepending
518     return adjustedOffset;
519   },
520
521   updateBuffer: function(start, newRows, newStyle) {
522     Rico.log("updateBuffer: start="+start+", # of rows="+this.rcvdRows);
523     if (this.rows.length == 0) { // initial load
524       this.rows = newRows;
525       this.attr = newStyle;
526       this.startPos = start;
527     } else if (start > this.startPos) { //appending
528       if (this.startPos + this.rows.length < start) {
529         this.rows =  newRows;
530         this.attr = newStyle;
531         this.startPos = start;
532       } else {
533         this.rows = this.rows.concat( newRows.slice(0, newRows.length));
534         if (this.attr && newStyle) this.attr = this.attr.concat( newStyle.slice(0, newStyle.length));
535         if (this.rows.length > this.maxBufferSize) {
536           var fullSize = this.rows.length;
537           this.rows = this.rows.slice(this.rows.length - this.maxBufferSize, this.rows.length);
538           if (this.attr) this.attr = this.attr.slice(this.attr.length - this.maxBufferSize, this.attr.length);
539           this.startPos = this.startPos +  (fullSize - this.rows.length);
540         }
541       }
542     } else { //prepending
543       if (start + newRows.length < this.startPos) {
544         this.rows = newRows;
545         this.attr = newStyle;
546       } else {
547         this.rows = newRows.slice(0, this.startPos).concat(this.rows);
548         if (newStyle) this.attr = newStyle.slice(0, this.startPos).concat(this.attr);
549         if (this.maxBufferSize && this.rows.length > this.maxBufferSize) {
550           this.rows = this.rows.slice(0, this.maxBufferSize);
551           if (this.attr) this.attr = this.attr.slice(0, this.maxBufferSize);
552         }
553       }
554       this.startPos =  start;
555     }
556     this.size = this.rows.length;
557   },
558
559   sortBuffer: function(colnum) {
560     this.sortParm={};
561     var col=this.liveGrid.columns[colnum];
562     if (this.options.sortParmFmt) {
563       this.sortParm['sort_col']=col[this.options.sortParmFmt];
564       this.sortParm['sort_dir']=col.getSortDirection();
565     } else {
566       this.sortParm['s'+colnum]=col.getSortDirection();
567     }
568     this.clear();
569   },
570
571   printAllSQL: function(exportType) {
572     var parms=this.formQueryHashSQL(0,this.liveGrid.options.maxPrint,exportType);
573     parms.hidden=this.liveGrid.listInvisible('index').join(',');
574     var url=this.dataSource+'?'+Rico.toQueryString(parms);
575     window.open(url,'',this.liveGrid.options.exportWindow);
576   },
577
578   printVisibleSQL: function(exportType) {
579     var parms=this.formQueryHashSQL(this.liveGrid.contentStartPos-1, this.liveGrid.pageSize, exportType);
580     parms.hidden=this.liveGrid.listInvisible('index').join(',');
581     var url=this.dataSource+'?'+Rico.toQueryString(parms);
582     window.open(url,'',this.liveGrid.options.exportWindow);
583   },
584
585   // for datasource that is a javascript function
586   _printAll: function() {
587     this.liveGrid.exportStart();
588     this.ajaxOptions.parameters = this.formQueryHashSQL(0,this.liveGrid.options.maxPrint);
589     var self=this;
590     this.ajaxOptions.onComplete = function() { self._jsExport(); };
591     this.dataSource(this.ajaxOptions);
592   },
593
594   _jsExport: function(newRows, newStyle, totalRows, errMsg) {
595     Rico.log("_jsExport: "+arguments.length);
596     if (errMsg) {
597       Rico.log("_jsExport: received error="+errMsg);
598       this.liveGrid.showMsg(Rico.getPhraseById("requestError",errMsg));
599       return;
600     }
601     this.exportBuffer(newRows,0);
602     this.liveGrid.exportFinish();
603   }
604
605 };