X-Git-Url: https://git.infodrom.org/?p=infodrom%2Frico3;a=blobdiff_plain;f=minsrc%2FricoLiveGrid.js;h=1afb5d64e54059043c11f9251b01500039c25e33;hp=6a5ef631b845c1cb1a6f44da2e551fc170879c20;hb=74a8f0e68b0c99e6f4b67456c6262a2ff4edcc6e;hpb=b07d1369594a42d62f8054a07ae1162ee1d928ee diff --git a/minsrc/ricoLiveGrid.js b/minsrc/ricoLiveGrid.js index 6a5ef63..1afb5d6 100644 --- a/minsrc/ricoLiveGrid.js +++ b/minsrc/ricoLiveGrid.js @@ -1,6 +1,6 @@ /* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) + * (c) 2005-2011 Richard Cowin (http://openrico.org) + * (c) 2005-2011 Matt Brown (http://dowdybrown.com) * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy of the License at @@ -13,9 +13,6 @@ * and limitations under the License. */ -if(typeof Rico=='undefined') throw("LiveGrid requires the Rico JavaScript framework"); - - /** @namespace */ if (!Rico.Buffer) Rico.Buffer = {}; @@ -34,8 +31,8 @@ Rico.Buffer.Base.prototype = { this.clear(); this.updateInProgress = false; this.lastOffset = 0; - this.rcvdRowCount = false; // true if an eof element was included in the last xml response - this.foundRowCount = false; // true if an xml response is ever received with eof true + this.rcvdRowCount = false; // true if an eof element was included in the last response + this.foundRowCount = false; // true if a response is ever received with eof true this.totalRows = 0; this.rowcntContent = ""; this.rcvdOffset = -1; @@ -43,13 +40,13 @@ Rico.Buffer.Base.prototype = { fixedHdrRows : 0, canFilter : true, // does buffer object support filtering? isEncoded : true, // is the data received via ajax html encoded? - acceptAttr : [] // attributes that can be copied from original/ajax data (e.g. className, style, id) + acceptStyle : false, // copy style from original/ajax data? + canRefresh : false // should "refresh" be shown on filter menu? }; Rico.extend(this.options, options || {}); if (dataTable) { this.loadRowsFromTable(dataTable,this.options.fixedHdrRows); - } else { - this.clear(); + dataTable.parentNode.removeChild(dataTable); // delete the data once it has been loaded } }, @@ -77,10 +74,10 @@ Rico.Buffer.Base.prototype = { }, loadRowsFromTable: function(tableElement,firstRow) { - var newRows = new Array(); + var newRows = []; var trs = tableElement.getElementsByTagName("tr"); for ( var i=firstRow || 0; i < trs.length; i++ ) { - var row = new Array(); + var row = []; var cells = trs[i].getElementsByTagName("td"); for ( var j=0; j < cells.length ; j++ ) row[j]=cells[j].innerHTML; @@ -106,10 +103,10 @@ Rico.Buffer.Base.prototype = { dom2jstable: function(rowsElement) { Rico.log('dom2jstable: encoded='+this.options.isEncoded); - var newRows = new Array(); + var newRows = []; var trs = rowsElement.getElementsByTagName("tr"); for ( var i=0; i < trs.length; i++ ) { - var row = new Array(); + var row = []; var cells = trs[i].getElementsByTagName("td"); for ( var j=0; j < cells.length ; j++ ) row[j]=Rico.getContentAsString(cells[j],this.options.isEncoded); @@ -118,26 +115,6 @@ Rico.Buffer.Base.prototype = { return newRows; }, - dom2jstableAttr: function(rowsElement,firstRow) { - var acceptAttr=this.options.acceptAttr; - Rico.log("dom2jstableAttr start, # attr="+acceptAttr.length); - var newRows = new Array(); - var trs = rowsElement.getElementsByTagName("tr"); - for ( var i=firstRow || 0; i < trs.length; i++ ) { - var row = new Array(); - var cells = trs[i].getElementsByTagName("td"); - for ( var j=0; j < cells.length ; j++ ) { - row[j]={}; - for (var k=0; k=this.size) return false; if (!this.rows[bufRow][col]) this.rows[bufRow][col]={}; this.rows[bufRow][col]=newval; - if (typeof newstyle=='string') this.rows[bufRow][col]._style=newstyle; - this.rows[bufRow][col].modified=true; + if (this.options.acceptStyle && typeof newstyle=='string') { + if (!this.attr) this.attr=[]; + if (!this.attr[bufRow]) this.attr[bufRow]=[]; + this.attr[bufRow][col]=newstyle; + } + if (!this.modified[bufRow]) this.modified[bufRow]=[]; + this.modified[bufRow][col]=true; return true; }, getRows: function(start, count) { var begPos = start - this.startPos; var endPos = Math.min(begPos + count,this.size); - var results = new Array(); + var results = []; for ( var i=begPos; i < endPos; i++ ) { results.push(this.rows[i]); } @@ -554,8 +538,8 @@ Rico.LiveGrid.prototype = { this.bookmark=document.getElementById(this.tableId+"_bookmark"); this.sizeDivs(); - var filterUIrow=this.buffer.options.canFilter ? this.options.FilterLocation : false; - if (typeof(filterUIrow)=='number' && filterUIrow<0) + var filterUIrow=-1; + if (this.buffer.options.canFilter && this.options.AutoFilter) filterUIrow=this.addHeadingRow('ricoLG_FilterRow'); this.createDataCells(this.options.visibleRows); if (this.pageSize == 0) return; @@ -580,7 +564,7 @@ Rico.LiveGrid.prototype = { this.scrollToRow(this.options.offset); this.buffer.fetch(this.options.offset); } - if (typeof(filterUIrow)=='number') + if (filterUIrow >= 0) this.createFilters(filterUIrow); this.scrollEventFunc=Rico.eventHandle(this,'handleScroll'); this.wheelEventFunc=Rico.eventHandle(this,'handleWheel'); @@ -593,6 +577,13 @@ Rico.LiveGrid.prototype = { if (this.options.windowResize) Rico.runLater(100,this,'pluginWindowResize'); Rico.log("initialize complete for "+this.tableId); + //alert('clientLeft='+this.scrollDiv.clientLeft); + if (this.direction=='rtl' && (!Rico.isWebKit || this.scrollDiv.clientLeft > 0)) { + this.scrollTab.style.right='0px'; + } else { + this.scrollTab.style.left='0px'; + Rico.setStyle(this.tabs[1], {'float': 'left'}); + } } }; @@ -662,7 +653,7 @@ Rico.LiveGridMethods = { var theads=table.getElementsByTagName("thead"); if (theads.length == 1) { Rico.log("createTables: using thead section, id="+this.tableId); - if (this.options.PanelNamesOnTabHdr && this.options.panels) { + if (this.options.ColGroupsOnTabHdr && this.options.ColGroups) { var r=theads[0].insertRow(0); this.insertPanelNames(r, 0, this.options.frozenColumns, 'ricoFrozen'); this.insertPanelNames(r, this.options.frozenColumns, this.options.columnSpecs.length); @@ -722,7 +713,7 @@ Rico.LiveGridMethods = { // create new tables for (i=0; i<3; i++) { this.tabs[i] = document.createElement("table"); - this.tabs[i].className = 'ricoLG_table'; + this.tabs[i].className = (i < 2) ? 'ricoLG_table' : 'ricoLG_scrollTab'; this.tabs[i].border=0; this.tabs[i].cellPadding=0; this.tabs[i].cellSpacing=0; @@ -731,8 +722,7 @@ Rico.LiveGridMethods = { // set headings for (i=0; i<2; i++) { this.thead[i]=this.tabs[i].createTHead(); - Rico.addClass(this.tabs[i],'ricoLG_top'); - //this.thead[i].className='ricoLG_top'; + this.thead[i].className='ricoLG_top'; if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader); } // set bodies @@ -752,7 +742,7 @@ Rico.LiveGridMethods = { } else { this.createHdr(0,0,this.options.frozenColumns); this.createHdr(1,this.options.frozenColumns,this.options.columnSpecs.length); - if (this.options.PanelNamesOnTabHdr && this.options.panels) { + if (this.options.ColGroupsOnTabHdr && this.options.ColGroups) { this.insertPanelNames(this.thead[0].insertRow(0), 0, this.options.frozenColumns); this.insertPanelNames(this.thead[1].insertRow(0), this.options.frozenColumns, this.options.columnSpecs.length); } @@ -808,11 +798,11 @@ Rico.LiveGridMethods = { switch (fmt.filterUI.charAt(0)) { case 't': // text field - field=Rico.createFormField(divs[1],'input','text',name,name); + field=Rico.createFormField(divs[1],'input',Rico.inputtypes.search ? 'search' : 'text',name,'RicoFilter'); var size=fmt.filterUI.match(/\d+/); field.maxLength=fmt.Length || 50; field.size=size ? parseInt(size,10) : 10; - divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear'))); + if (field.type != 'search') divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear'))); if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='LIKE') { var v=col.filterValues[0]; if (v.charAt(0)=='*') v=v.substr(1); @@ -827,17 +817,27 @@ Rico.LiveGridMethods = { // multi-select case 's': // drop-down select - field=Rico.createFormField(divs[1],'select',null,name); + field=Rico.createFormField(divs[1],'select',null,name,'RicoFilter'); Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll")); col.filterField=field; var options={}; Rico.extend(options, this.buffer.ajaxOptions); var colnum=typeof(fmt.filterCol)=='number' ? fmt.filterCol : c; - options.parameters = {id: this.tableId, distinct:colnum}; - options.parameters[this.actionId]="query"; + options.parameters = this.buffer.formQueryHashXML(0,-1); + options.parameters.distinct = colnum; options.onComplete = this.filterValuesUpdateFunc(c); new Rico.ajaxRequest(this.buffer.dataSource, options); break; + case 'n': + field=Rico.createFormField(divs[1],'select',null,name,'RicoFilter'); + Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll")); + col.filterField=field; + var choices=fmt.filterUI.length == 1 ? "-0+" : fmt.filterUI.substr(1); + if (choices.indexOf("-") >= 0) Rico.addSelectOption(field,"LT0","< 0"); + if (choices.indexOf("0") >= 0) Rico.addSelectOption(field,"EQ0","= 0"); + if (choices.indexOf("+") >= 0) Rico.addSelectOption(field,"GT0","> 0"); + Rico.eventBind(col.filterField,'change',Rico.eventHandle(col,'nFilterChange')); + break; case 'c': // custom if (typeof col._createFilters == 'function') @@ -872,6 +872,18 @@ Rico.LiveGridMethods = { var rowsElement = response.getElementsByTagName('rows')[0]; var col=this.columns[parseInt(colnum,10)]; var rows = this.buffer.dom2jstable(rowsElement); + var found = !col.filterValues || !col.filterValues.length; + if (!found) for (var i=0; i 0; c++) { - if (cells[0].className=='ricoFrozen') { + if (Rico.hasClass(cells[0],'ricoFrozen')) { if (r==this.headerRowIdx) this.options.frozenColumns=c+1; } else { h=1; @@ -1102,15 +1114,18 @@ Rico.LiveGridMethods = { }, adjustPageSize: function() { + Rico.log('adjustPageSize start'); var remHt=this.remainingHt(); Rico.log('adjustPageSize remHt='+remHt+' lastRow='+this.lastRowPos); if (remHt > this.rowHeight) this.autoAppendRows(remHt); else if (remHt < 0 || this.sizeTo=='data') this.autoRemoveRows(-remHt); + Rico.log('adjustPageSize end'); }, setPageSize: function(newRowCount) { + Rico.log('setPageSize '+this.tableId+' newRowCount='+newRowCount); newRowCount=Math.min(newRowCount,this.options.maxPageRows); newRowCount=Math.max(newRowCount,this.options.minPageRows); this.sizeTo='fixed'; @@ -1137,7 +1152,7 @@ Rico.LiveGridMethods = { }, resizeWindow: function() { - Rico.log('resizeWindow '+this.tableId+' lastRow='+this.lastRowPos); + Rico.log('resizeWindow '+this.tableId+' lastRow='+this.lastRowPos+' resizeState='+this.resizeState); if (this.resizeState=='finish') { Rico.log('resizeWindow postponed'); this.resizeState='resize'; @@ -1148,12 +1163,14 @@ Rico.LiveGridMethods = { return; } if (this.sizeTo=='parent' && Rico.getStyle(this.outerDiv.parentNode,'display') == 'none') return; + Rico.log('resizeWindow: about to adjustPageSize') var oldSize=this.pageSize; this.adjustPageSize(); this.finishResize(oldSize); }, finishResize: function(oldSize) { + Rico.log('finishResize '+this.tableId); if (this.pageSize > oldSize && this.buffer.totalRows>0) { this.isPartialBlank=true; var adjStart=this.adjustRow(this.lastRowPos); @@ -1167,6 +1184,7 @@ Rico.LiveGridMethods = { }, finishResize2: function() { + Rico.log('finishResize2 '+this.tableId+': resizeState='+this.resizeState); this.sizeDivs(); this.updateHeightDiv(); if (this.resizeState=='resize') { @@ -1228,11 +1246,13 @@ Rico.LiveGridMethods = { newdiv.className = 'ricoLG_cell '+cls; newdiv.id=this.tableId+'_'+this.pageSize+'_'+c; this.columns[c].dataColDiv.appendChild(newdiv); - if (this.columns[c].format.canDrag && Rico.registerDraggable) - Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx ); - newdiv.innerHTML=' '; // this seems to be required by IE if (this.columns[c]._create) { this.columns[c]._create(newdiv,this.pageSize); + } else { + newdiv.innerHTML=' '; // this seems to be required by IE + } + if (this.columns[c].format.canDrag && Rico.registerDraggable) { + Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx ); } } this.pageSize++; @@ -1679,19 +1699,12 @@ Rico.LiveGridMethods = { return -1; }, - findColumnName: function(name) { - for (var n=0; n= 0) { sortDirection=this.columns[colnum].getSortDirection(); @@ -1713,12 +1726,12 @@ Rico.LiveGridMethods = { sortDirection=sortDirection.toUpperCase(); if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC; } - switch (typeof columnNameOrNum) { + switch (typeof columnIdOrNum) { case 'string': - colnum=this.findColumnName(columnNameOrNum); + colnum=this.findColumnsBySpec('id',columnIdOrNum); break; case 'number': - colnum=columnNameOrNum; + colnum=columnIdOrNum; break; } } @@ -1994,9 +2007,9 @@ initialize: function(liveGrid,colIdx,hdrInfo,tabIdx) { Rico.extend(this, new Rico.TableColumnBase()); this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx); this.buffer=liveGrid.buffer; - if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='raw'; + if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='html'; if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type); - this.isText = /raw|text|showTags/.test(this.format.type); + this.isText = /html|text/.test(this.format.type); Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText); this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst); if (this['format_'+this.format.type]) { @@ -2109,6 +2122,8 @@ getFilterText: function() { switch (this.filterOp) { case 'EQ': return '= '+vals.join(', '); case 'NE': return Rico.getPhraseById('filterNot',vals.join(', ')); + case 'LT': return '< '+vals[0]; + case 'GT': return '> '+vals[0]; case 'LE': return '<= '+vals[0]; case 'GE': return '>= '+vals[0]; case 'LIKE': return Rico.getPhraseById('filterLike',vals[0]); @@ -2190,12 +2205,23 @@ isFiltered: function() { return this.filterType == Rico.ColumnConst.USERFILTER; }, -filterChange: function(e) { +filterChange: function(e) { var selbox=Rico.eventElement(e); - if (selbox.value==this.liveGrid.options.FilterAllToken) - this.setUnfiltered(); + if (selbox.value==this.liveGrid.options.FilterAllToken) + this.setUnfiltered(); else - this.setFilter('EQ',selbox.value,Rico.ColumnConst.USERFILTER,function() {selbox.selectedIndex=0;}); + this.setFilter('EQ',selbox.value,Rico.ColumnConst.USERFILTER,function() {selbox.selectedIndex=0;}); +}, + +nFilterChange: function(e) { + var selbox=Rico.eventElement(e); + if (selbox.value==this.liveGrid.options.FilterAllToken) { + this.setUnfiltered(); + } else { + var op=selbox.value.substr(0,2); + var value=selbox.value.substr(2); + this.setFilter(op,value,Rico.ColumnConst.USERFILTER,function() {selbox.selectedIndex=0;}); + } }, filterClear: function(e) { @@ -2288,13 +2314,6 @@ mFilterOtherClick: function(e) { }, format_text: function(v) { - if (typeof v!='string') - return ' '; - else - return Rico.stripTags(v); -}, - -format_showTags: function(v) { if (typeof v!='string') return ' '; else @@ -2319,7 +2338,7 @@ format_datetime: function(v) { }, // converts GMT/UTC to local time -format_UTCasLocalTime: function(v) { +format_utcaslocaltime: function(v) { if (typeof v=='undefined' || v=='' || v==null) return ' '; else { @@ -2382,8 +2401,8 @@ getValue: function(windowRow) { return this.buffer.getWindowCell(windowRow,this.index); }, -getBufferAttr: function(windowRow) { - return this.buffer.getWindowAttr(windowRow,this.index); +getBufferStyle: function(windowRow) { + return this.buffer.getWindowStyle(windowRow,this.index); }, setValue: function(windowRow,newval) { @@ -2414,17 +2433,8 @@ displayValue: function(windowRow) { } var gridCell=this.cell(windowRow); this._display(bufval,gridCell,windowRow); - var acceptAttr=this.buffer.options.acceptAttr; - if (acceptAttr.length==0) return; - var bufAttr=this.getBufferAttr(windowRow); - if (bufAttr==null) return; - for (var k=0; k