[richfaces-svn-commits] JBoss Rich Faces SVN: r1120 - trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Jun 11 11:31:11 EDT 2007


Author: konstantin.mishin
Date: 2007-06-11 11:31:11 -0400 (Mon, 11 Jun 2007)
New Revision: 1120

Modified:
   trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js
Log:
Updated a client part of selection.

Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js	2007-06-11 14:38:30 UTC (rev 1119)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js	2007-06-11 15:31:11 UTC (rev 1120)
@@ -187,6 +187,8 @@
  
 Object.extend(ClientUI.controls.grid.SelectionManager.prototype, {
 	initialize: function(grid) {
+		this.selectionFlag;
+		this.firstIndex;
 		var gridElement = grid.getElement();
 		this.prefix = gridElement.id;
 		this.selection = new ClientUI.controls.grid.Selection();
@@ -194,17 +196,9 @@
 		this.inputElement = grid.options.selectionInput;
 
 		this.restoreState();
+		this.setListeners();
 		this.eventKeyPress = this.processKeyDown.bindAsEventListener(this);
 		Event.observe(document, "keypress", this.eventKeyPress);
-		var frows = $(this.prefix + ":f").rows;
-		var nrows = $(this.prefix + ":n").rows;
-		this.rowCount = frows.length;
-		var rowIndex;
-		for(var i = 0; i < this.rowCount; i++) {
-			rowIndex = Number(frows[i].id.split(this.prefix)[1].split(":")[2]);
-			this.addListener(frows[i], rowIndex);
-			this.addListener(nrows[i], rowIndex);
-		}
 		if (document.selection) {
 			Event.observe(gridElement, "click", this.resetSelection.bindAsEventListener(this));
 		}
@@ -229,7 +223,9 @@
 	},
 
 	restoreState: function() {
+		this.selectionFlag = null;
 		this.selection.initRanges($(this.inputElement).value);
+		this.firstIndex = Number($(this.prefix + ":f").rows[0].id.split(this.prefix)[1].split(":")[2]);;
 		var i = 0;
 		var j;
 		while(i < this.selection.ranges.length) {
@@ -245,6 +241,18 @@
 		}
 	},
 	
+	setListeners: function() {
+		var frows = $(this.prefix + ":f").rows;
+		var nrows = $(this.prefix + ":n").rows;
+		this.rowCount = frows.length;
+		var rowIndex;
+		for(var i = 0; i < this.rowCount; i++) {
+			rowIndex = Number(frows[i].id.split(this.prefix)[1].split(":")[2]);
+			this.addListener(frows[i], rowIndex);
+			this.addListener(nrows[i], rowIndex);
+		}
+	},
+	
 	addListener: function(element, rowIndex) {
 		Event.observe(element, "click", this.processClick.bindAsEventListener(this, rowIndex));	
 	},
@@ -279,13 +287,14 @@
 		var noDefault = false;
 		switch (event.keyCode || event.charCode) {
 			case Event.KEY_UP:
-				if (this.inFocus && activeRow && activeRow > 0) {
+				if (this.inFocus && activeRow) {
 					if(activeRow) {
-						rowIndex = this.rowCount  - 1;
+						rowIndex = activeRow - 1;
 					} else {
-						rowIndex = activeRow - 1;
+						rowIndex = this.rowCount - 1;
 					}
 					if (!event.ctrlKey && !event.shiftKey) {
+						this.selectionFlag = "x";
 						range = [rowIndex, rowIndex];
 						this.setSelection(range);		
 					} else if (!event.ctrlKey && event.shiftKey) {
@@ -303,13 +312,14 @@
 				}
 				break;
 			case Event.KEY_DOWN:
-				if (this.inFocus && activeRow) {
+				if (this.inFocus && activeRow != null) {
 					if(activeRow == this.rowCount  - 1) {
 						rowIndex = 0;
 					} else {
 						rowIndex = activeRow + 1;
 					}
 					if (!event.ctrlKey && !event.shiftKey) {
+						this.selectionFlag = "x";
 						range = [rowIndex, rowIndex];
 						this.setSelection(range);		
 					} else if (!event.ctrlKey && event.shiftKey) {
@@ -328,6 +338,7 @@
 				break;
 			case 65: case 97:								// Ctrl-A
 				if (this.inFocus && event.ctrlKey) {
+					this.selectionFlag = "a";
 					range = [0, this.rowCount];
 					this.setSelection(range);		
 					noDefault = true;
@@ -337,7 +348,7 @@
 				this.lostFocus();
 		}
 		if (noDefault) {
-			$(this.prefix+":s").value = this.selection.inspectRanges();			
+			$(this.inputElement).value = this.selection.inspectRanges() + this.selectionFlag;			
 			if (event.preventBubble) event.preventBubble();
 			Event.stop(event);
 		}
@@ -349,11 +360,13 @@
 		}		
 		var range;
 		if ( event.shiftKey && !event.ctrlKey && !event.altKey) {
+			this.selectionFlag = "x";
 			if(!this.shiftRow) {
 				this.shiftRow = this.activeRow;
 			}
 			this.startRow = this.shiftRow;
-			if (this.startRow <= rowIndex) {
+			if (((this.startRow <= rowIndex) && (this.firstIndex < this.startRow || rowIndex < this.firstIndex))
+				|| (this.startRow > rowIndex && this.firstIndex >= this.startRow && rowIndex >= this.firstIndex)) {
 				this.endRow = rowIndex;
 			} else {
 				this.endRow = this.startRow;
@@ -368,6 +381,7 @@
 				this.addRowToSelection(rowIndex);
 			}
 		} else  if (!event.shiftKey && !event.ctrlKey && !event.altKey) {
+			this.selectionFlag = "x";
 			range = [rowIndex, rowIndex];
 			this.setSelection(range);		
 		}
@@ -377,7 +391,7 @@
 		} else if (document.selection) {
 			document.selection.empty();
 		}
-		$(this.prefix+":s").value = this.selection.inspectRanges();			
+		$(this.inputElement).value = this.selection.inspectRanges()+ this.selectionFlag;			
 	},
 
 	setShiftRow: function(event) {
@@ -391,15 +405,15 @@
 	},
 	
 	setSelection: function(range) {
-		var i = 0;
-		for (; i < range[0]; i++) {
-			this.removeRowFromSelection(i);
-		}
-		for (; i <= range[1]; i++) {
+		var i = range[0];
+		range[1] = (range[1] + 1) % this.rowCount;		
+		while (i != range[1]) {
 			this.addRowToSelection(i);
+			i = (i + 1) % this.rowCount;		
 		}
-		for (; i < this.rowCount; i++) {
+		while (i != range[0]) {
 			this.removeRowFromSelection(i);
+			i = (i + 1) % this.rowCount;				
 		}
 	},
 	
@@ -427,7 +441,7 @@
 
 	setActiveRow: function(rowIndex) {
 		var fElement, nElement;
-		if(this.activeRow) {
+		if(this.activeRow != null) {
 			fElement = $(this.prefix + ":f:" + this.activeRow);
 			nElement = $(this.prefix + ":n:" + this.activeRow);
 			fElement.style.color = "#000000";




More information about the richfaces-svn-commits mailing list