[richfaces-svn-commits] JBoss Rich Faces SVN: r935 - trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Tue May 29 13:28:22 EDT 2007
Author: abelevich
Date: 2007-05-29 13:28:22 -0400 (Tue, 29 May 2007)
New Revision: 935
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js
Log:
Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js 2007-05-29 17:28:13 UTC (rev 934)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js 2007-05-29 17:28:22 UTC (rev 935)
@@ -7,6 +7,7 @@
ClientUILib.requireClass("ClientUI.common.box.Box");
ClientUILib.requireClass("ClientUI.common.box.SplashBox");
+ClientUILib.requireClass("ClientUI.controls.grid.DataCash");
/*
* GridHeader.js - Grid control header pane
@@ -128,7 +129,6 @@
this.frozenContentBox = new ClientUI.common.box.Box(frozen);
this.frozenContentBox.makeAbsolute();
-
this.helpObject1 = new ClientUI.common.box.Box($(document.createElement("img")), this.contentBox.getElement());
this.helpObject1.setWidth(10);
this.helpObject1.setHeight(10);
@@ -136,9 +136,8 @@
this.helpObject2 = new ClientUI.common.box.Box($(document.createElement("img")), this.frozenContentBox.getElement());
this.helpObject2.setWidth(10);
this.helpObject2.setHeight(10);
- this.helpObject2.makeAbsolute();
+ this.helpObject2.makeAbsolute();
-
// create row template
var ch = this.frozenContentBox.getElement().firstChild;
while(ch) {
@@ -160,6 +159,16 @@
}
this.parseTemplate(this.templFrozen.getElement(), this.templNormal.getElement());
+
+ // init cash with initial data
+ var cash = this.getCash();
+ var frows = this.templFrozen.getElement().rows;
+ var nrows = this.templNormal.getElement().rows;
+ var count = this.rowsCount;
+ for(var i=0; i<count; i++) {
+ cash.setRow(i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
+ }
+
this.controlCreated = true;
},
parseTemplate: function(templFrozen, templNormal) {
@@ -180,11 +189,12 @@
this.countToLoad = 0;
this.startRow = 0;
this.startIndex = 0;
- this.currRange = $R(0,this.rowsCount);
+ this.currRange = $R(0, this.rowsCount);
return true;
},
setScrollPos: function(pos) {
+ ClientUILib.log(ClientUILogger.ERROR, "setScrollPos: " + pos);
this.contentBox.getElement().scrollTop = pos;
this.frozenContentBox.getElement().scrollTop = pos;
if(ClientUILib.isIE && !ClientUILib.isIE7) {
@@ -265,9 +275,21 @@
// check direction and predict some next rows
var from = Math.max(first - (forwardDir ? 1 : (this.rowsCount - this.dataVisible - 1)), 0);
- var to = Math.min(first + (forwardDir ? this.rowsCount-1 : this.dataVisible + 1), this.grid.dataModel.getCount() - 1);
+ var to = Math.min(first + (forwardDir ? this.rowsCount-1 : this.dataVisible + 1), this.grid.dataModel.getCount());
+
+ if(from == 0) {
+ to = this.rowsCount;
+ }
+ else if(to == this.grid.dataModel.getCount()) {
+ from = to - this.rowsCount;
+ }
+
var range = $R(from, to);
-
+
+ if(this.currRange.start == from && this.currRange.end == to) {
+ return;
+ }
+
if(from >= to) {
ClientUILib.log(ClientUILogger.WARNING, "!!! GridBody: adjustDataPosition. Pos: " + pos + ", From:" + from + ", To:" + to);
return;
@@ -371,6 +393,15 @@
startIndex = this.currRange.end;
}
}
+ else if(range.start == this.currRange.start) {
+ switchType = 3;
+ countToLoad = range.end - this.currRange.end;
+ if(countToLoad > 0) {
+ startIndex = this.currRange.end;
+ var restCount = this.rowsCount - countToLoad;
+ startRowIndx = frozenTbl.rows[restCount].index;
+ }
+ }
else {
switchType = 2;
countToLoad = this.currRange.start - range.start;
@@ -392,27 +423,36 @@
if(countToLoad > 0 && process) {
this.updateStarted = true;
ClientUILib.log(ClientUILogger.WARNING, "Start loading...");
+ ClientUILib.log(ClientUILogger.WARNING, "start index: " + startIndex + ", and startRow: " + startRowIndx + ", and count: " + countToLoad);
this.currRange = range;
this.currentPos = task.pos;
this.taskDefineTime = (new Date()).getTime();
this.showSplash();
-
- // Make timer to handle quick clicks on scrollbar arrows
- setTimeout(function() {
-
- // 4. start data loading
- //this.container.hide();
- this.updateInterval = screen.updateInterval;
- screen.updateInterval = 500;
-
- this.grid.dataModel.loadRows({
+
+ var options = {
index: startIndex,
count: countToLoad,
startRow: startRowIndx,
- switchType: switchType});
- }.bind(this), 10);
+ switchType: switchType
+ };
+ options = this.processCashedValues(options);
+ if(options.count > 0) {
+ // Make timer to handle quick clicks on scrollbar arrows
+ setTimeout(function() {
+
+ // 4. start data loading
+ this.container.hide();
+ this.updateInterval = screen.updateInterval;
+ screen.updateInterval = 1000;
+
+ this.grid.dataModel.loadRows(options);
+ }.bind(this), 10);
+ }
+ else {
+ this.updateStarted = false;
+ }
}
else {
this.updateStarted = false;
@@ -433,110 +473,143 @@
this.splash.updateLayout();
},
- /**
- * show hiden rows after loading them from datasource
- * @param {Object} options
- */
- invalidate: function(options) {
-
- ClientUILib.log(ClientUILogger.WARNING, "Stop loading.");
+ rearrangeRows: function(options, updateCash, showContainer) {
var frozenTbl = this.templFrozen.getElement();
var normalTbl = this.templNormal.getElement();
-
- screen.updateInterval = this.updateInterval;
- //this.container.show();
-
- setTimeout(function (){
- if(options.switchType === 0) {
- var visibleRowPos = this.defaultRowHeight * options.index;
- this.templFrozen.moveToY(visibleRowPos);
- this.templNormal.moveToY(visibleRowPos);
+ var cash = this.getCash();
+
+ if(options.switchType === 0) {
+ var visibleRowPos = this.defaultRowHeight * options.index;
+ var test = this.contentBox.getElement().scrollTop;
+ if(showContainer) this._showContainer();
+ this.templFrozen.moveToY(visibleRowPos);
+ this.templNormal.moveToY(visibleRowPos);
+
+ if(updateCash) {
+ var frows = frozenTbl.rows;
+ var nrows = normalTbl.rows;
+ var count = frows.length;
+ var index = options.index;
+ for(var i=0; i<count; i++) {
+ cash.setRow(index+i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
+ }
}
- else if(options.switchType === 1 || options.switchType === 2) {
- // store visible row pos to restore after rows reerrange
- var count = frozenTbl.rows.length;
- var frows = new Array(count), nrows = new Array(count);
- var j = 0;
-
- if(options.switchType === 1) {
- for(i=options.count; i<this.rowsCount; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- j++;
+ }
+ else if(options.switchType === 1 || options.switchType === 2) {
+ // store visible row pos to restore after rows reerrange
+ var count = frozenTbl.rows.length;
+ var frows = new Array(count), nrows = new Array(count);
+ var j = 0, i;
+ var index = options.index;
+
+ if(options.switchType === 1) {
+ for(i=options.count; i<this.rowsCount; i++) {
+ frows[j] = frozenTbl.rows[i];
+ nrows[j] = normalTbl.rows[i];
+ j++;
+ }
+ for(i=0; i<options.count; i++) {
+ frows[j] = frozenTbl.rows[i];
+ nrows[j] = normalTbl.rows[i];
+ if(updateCash) {
+ cash.setRow(index+i, {f: frows[j].innerHTML, n: nrows[j].innerHTML});
}
- for(i=0; i<options.count; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- j++;
- }
+ j++;
}
- else {
- for(i=this.rowsCount - options.count; i<this.rowsCount; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- j++;
+ }
+ else {
+ for(i=this.rowsCount - options.count; i<this.rowsCount; i++) {
+ frows[j] = frozenTbl.rows[i];
+ nrows[j] = normalTbl.rows[i];
+ if(updateCash) {
+ cash.setRow(index+j, {f: frows[j].innerHTML, n: nrows[j].innerHTML});
}
- for(i=0; i<this.rowsCount - options.count; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- j++;
- }
+ j++;
}
-
-
- // Mozilla is faster when doing the DOM manipulations on
- // an orphaned element. MSIE is not
- var removeChilds = navigator.product == "Gecko";
- var fbody = frozenTbl.tBodies[0];
- var nbody = normalTbl.tBodies[0];
- var fnextSibling = fbody.nextSibling;
- var nnextSibling = nbody.nextSibling;
-
- if (removeChilds) { // remove all rows
- fp = fbody.parentNode;
- fp.removeChild(fbody);
- np = nbody.parentNode;
- np.removeChild(nbody);
+ for(i=0; i<this.rowsCount - options.count; i++) {
+ frows[j] = frozenTbl.rows[i];
+ nrows[j] = normalTbl.rows[i];
+ j++;
}
+ }
- if(options.switchType === 2) {
- var visibleRowPos = options.index * this.defaultRowHeight;
- this.templFrozen.moveToY(visibleRowPos);
- this.templNormal.moveToY(visibleRowPos);
- }
- // insert in the new order
- for (i = 0; i < count; i++) {
- fbody.appendChild(frows[i]);
- nbody.appendChild(nrows[i]);
- }
+ // Mozilla is faster when doing the DOM manipulations on
+ // an orphaned element. MSIE is not
+ var removeChilds = navigator.product == "Gecko";
+ var fbody = frozenTbl.tBodies[0];
+ var nbody = normalTbl.tBodies[0];
+ var fnextSibling = fbody.nextSibling;
+ var nnextSibling = nbody.nextSibling;
- if(removeChilds) {
- fp.insertBefore(fbody, fnextSibling);
- np.insertBefore(nbody, nnextSibling);
+ if (removeChilds) { // remove all rows
+ fp = fbody.parentNode;
+ fp.removeChild(fbody);
+ np = nbody.parentNode;
+ np.removeChild(nbody);
+ }
+
+ // insert in the new order
+ for (i = 0; i < count; i++) {
+ fbody.appendChild(frows[i]);
+ nbody.appendChild(nrows[i]);
+ }
+
+ if(removeChilds) {
+ fp.insertBefore(fbody, fnextSibling);
+ np.insertBefore(nbody, nnextSibling);
+ }
+
+ var visibleRowPos = (options.switchType == 1) ? this.currRange.start * this.defaultRowHeight : options.index * this.defaultRowHeight;
+ if(showContainer) this._showContainer();
+ this.templFrozen.moveToY(visibleRowPos);
+ this.templNormal.moveToY(visibleRowPos);
+ }
+ else {
+ if(updateCash) {
+ var frows = frozenTbl.rows;
+ var nrows = normalTbl.rows;
+ var count = frows.length;
+ var index = options.index;
+ for(var i=0; i<count; i++) {
+ cash.setRow(index+i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
}
-
- if(options.switchType === 1) {
- var visibleRowPos = this.currRange.start * this.defaultRowHeight;
- this.templFrozen.moveToY(visibleRowPos);
- this.templNormal.moveToY(visibleRowPos);
- }
}
-
+ var visibleRowPos = this.currRange.start * this.defaultRowHeight;
+ if(showContainer) this._showContainer();
+ this.templFrozen.moveToY(visibleRowPos);
+ this.templNormal.moveToY(visibleRowPos);
+ }
+ },
+ _showContainer: function() {
+ this.container.show();
+ this.setScrollPos(this.currentPos);
+ },
+ /**
+ * show hiden rows after loading them from datasource
+ * @param {Object} options
+ */
+ invalidate: function(options) {
+
+ ClientUILib.log(ClientUILogger.WARNING, "Stop loading.");
+ screen.updateInterval = this.updateInterval;
+
+ setTimeout(function () {
+ this.rearrangeRows(options, true, true);
this.splash.hide();
this.updateStarted = false;
+
}.bind(this), 10);
-
- if(this.processedPos != this.currentPos) {
+ /*if(this.processedPos != this.currentPos) {
this.currentPos = this.processedPos;
setTimeout(function (){
this.pendedUpdate();
}.bind(this), this.grid.dataModel.getRequestDelay());
- }
+ }*/
},
- pendedUpdate: function() {
+ /*pendedUpdate: function() {
if(this.processedPos != this.currentPos) {
this.currentPos = this.processedPos;
setTimeout(function (){
@@ -546,5 +619,62 @@
else {
this.adjustDataPosition(this.processedPos);
}
+ },*/
+ getCash: function() {
+ if(!this.cash) {
+ this.cash = new ClientUI.controls.grid.DataCash(this.grid.dataModel.getCount());
+ }
+ return this.cash;
+ },
+ processCashedValues: function(options) {
+ return options;
+
+ var cash = this.getCash();
+ var opt = {};
+ var frows = this.templFrozen.getElement().rows;
+ var nrows = this.templNormal.getElement().rows;
+
+ var i = 0;
+ var count = opt.count;
+ var index = opt.index;
+ var startRow = opt.startRow;
+ var rowC, row, rowU;
+ while(i<count && !(rowC = cash.getRow(index + i))) i++;
+ if(i<count) {
+ if(i > 0) {
+ options.count = i;
+ }
+ opt.count = count - i;
+ opt.index = index + i;
+ startRow += i;
+ if(startRow >= this.rowsCount) startRow -= this.rowsCount;
+ opt.startRow = startRow;
+
+ do {
+ row = frows[startRow];
+ rowU = row.cloneNode(true);
+ rowU.innerHTML = rowC.f;
+ row.parentNode.replaceChild(rowU, row);
+
+ row = nrows[startRow];
+ rowU = row.cloneNode(true);
+ rowU.innerHTML = rowC.n;
+ row.parentNode.replaceChild(rowU, row);
+
+ i++;
+ startRow++;
+ if(startRow >= this.rowsCount) startRow = 0;
+ rowC = cash.getRow(index + i);
+ } while(i<count && rowC);
+
+ if(i<=count) {
+ options.count = count - i;
+ options.index = index + i;
+ opt.count = i;
+ }
+ this.rearrangeRows(opt);
+ }
+
+ return options;
}
});
More information about the richfaces-svn-commits
mailing list