[ Index ] |
|
Code source de PRADO 3.0.6 |
1 Prado.RicoLiveGrid = Class.create(); 2 Prado.RicoLiveGrid.prototype = Object.extend(Rico.LiveGrid.prototype, 3 { 4 initialize : function(tableId, options) 5 { 6 this.options = { 7 tableClass: $(tableId).className || '', 8 loadingClass: $(tableId).className || '', 9 scrollerBorderRight: '1px solid #ababab', 10 bufferTimeout: 20000, 11 sortAscendImg: 'images/sort_asc.gif', 12 sortDescendImg: 'images/sort_desc.gif', 13 sortImageWidth: 9, 14 sortImageHeight: 5, 15 ajaxSortURLParms: [], 16 onRefreshComplete: null, 17 requestParameters: null, 18 inlineStyles: true, 19 visibleRows: 10, 20 totalRows: 0, 21 initialOffset: 0 22 }; 23 Object.extend(this.options, options || {}); 24 25 //this.ajaxOptions = {parameters: null}; 26 //Object.extend(this.ajaxOptions, ajaxOptions || {}); 27 28 this.tableId = tableId; 29 this.table = $(tableId); 30 31 this.addLiveGridHtml(); 32 33 var columnCount = this.table.rows[0].cells.length; 34 this.metaData = new Rico.LiveGridMetaData(this.options.visibleRows, this.options.totalRows, columnCount, options); 35 this.buffer = new Rico.LiveGridBuffer(this.metaData); 36 37 var rowCount = this.table.rows.length; 38 this.viewPort = new Rico.GridViewPort(this.table, 39 this.table.offsetHeight/rowCount, 40 this.options.visibleRows, 41 this.buffer, this); 42 this.scroller = new Rico.LiveGridScroller(this,this.viewPort); 43 this.options.sortHandler = this.sortHandler.bind(this); 44 45 if ( $(tableId + '_header') ) 46 this.sort = new Rico.LiveGridSort(tableId + '_header', this.options) 47 48 this.processingRequest = null; 49 this.unprocessedRequest = null; 50 51 //this.initAjax(url); 52 if (this.options.initialOffset >= 0) 53 { 54 var offset = this.options.initialOffset; 55 this.scroller.moveScroll(offset); 56 this.viewPort.scrollTo(this.scroller.rowToPixel(offset)); 57 if (this.options.sortCol) { 58 this.sortCol = options.sortCol; 59 this.sortDir = options.sortDir; 60 } 61 var grid = this; 62 setTimeout(function(){ 63 grid.requestContentRefresh(offset); 64 },100); 65 } 66 }, 67 68 fetchBuffer: function(offset) 69 { 70 if ( this.buffer.isInRange(offset) && 71 !this.buffer.isNearingLimit(offset)) { 72 return; 73 } 74 if (this.processingRequest) { 75 this.unprocessedRequest = new Rico.LiveGridRequest(offset); 76 return; 77 } 78 var bufferStartPos = this.buffer.getFetchOffset(offset); 79 this.processingRequest = new Rico.LiveGridRequest(offset); 80 this.processingRequest.bufferOffset = bufferStartPos; 81 var fetchSize = this.buffer.getFetchSize(offset); 82 var partialLoaded = false; 83 84 // var queryString 85 // if (this.options.requestParameters) 86 // queryString = this._createQueryString(this.options.requestParameters, 0); 87 var param = 88 { 89 'page_size' : fetchSize, 90 'offset' : bufferStartPos 91 }; 92 if(this.sortCol) 93 { 94 Object.extend(param, 95 { 96 'sort_col': this.sortCol, 97 'sort_dir': this.sortDir 98 }); 99 } 100 /*queryString = (queryString == null) ? '' : queryString+'&'; 101 queryString = queryString+'id='+this.tableId+'&page_size='+fetchSize+'&offset='+bufferStartPos; 102 if (this.sortCol) 103 queryString = queryString+'&sort_col='+escape(this.sortCol)+'&sort_dir='+this.sortDir; 104 105 this.ajaxOptions.parameters = queryString; 106 107 ajaxEngine.sendRequest( this.tableId + '_request', this.ajaxOptions ); 108 */ 109 Prado.Callback(this.tableId, param, this.ajaxUpdate.bind(this), this.options); 110 this.timeoutHandler = setTimeout( this.handleTimedOut.bind(this), this.options.bufferTimeout); 111 112 }, 113 114 ajaxUpdate: function(result, output) 115 { 116 try { 117 clearTimeout( this.timeoutHandler ); 118 this.buffer.update(result,this.processingRequest.bufferOffset); 119 this.viewPort.bufferChanged(); 120 } 121 catch(err) {} 122 finally {this.processingRequest = null; } 123 this.processQueuedRequest(); 124 } 125 }); 126 127 Object.extend(Rico.LiveGridBuffer.prototype, 128 { 129 update: function(newRows, start) 130 { 131 if (this.rows.length == 0) { // initial load 132 this.rows = newRows; 133 this.size = this.rows.length; 134 this.startPos = start; 135 return; 136 } 137 if (start > this.startPos) { //appending 138 if (this.startPos + this.rows.length < start) { 139 this.rows = newRows; 140 this.startPos = start;// 141 } else { 142 this.rows = this.rows.concat( newRows.slice(0, newRows.length)); 143 if (this.rows.length > this.maxBufferSize) { 144 var fullSize = this.rows.length; 145 this.rows = this.rows.slice(this.rows.length - this.maxBufferSize, this.rows.length) 146 this.startPos = this.startPos + (fullSize - this.rows.length); 147 } 148 } 149 } else { //prepending 150 if (start + newRows.length < this.startPos) { 151 this.rows = newRows; 152 } else { 153 this.rows = newRows.slice(0, this.startPos).concat(this.rows); 154 if (this.rows.length > this.maxBufferSize) 155 this.rows = this.rows.slice(0, this.maxBufferSize) 156 } 157 this.startPos = start; 158 } 159 this.size = this.rows.length; 160 } 161 }); 162 163 164 Object.extend(Rico.GridViewPort.prototype, 165 { 166 populateRow: function(htmlRow, row) 167 { 168 if(isdef(htmlRow)) 169 { 170 for (var j=0; j < row.length; j++) { 171 htmlRow.cells[j].innerHTML = row[j] 172 } 173 } 174 } 175 });
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |