Author: konstantin.mishin
Date: 2007-06-08 06:28:09 -0400 (Fri, 08 Jun 2007)
New Revision: 1094
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js
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/GridBody.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js 2007-06-08
09:19:38 UTC (rev 1093)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js 2007-06-08
10:28:09 UTC (rev 1094)
@@ -54,7 +54,7 @@
this.createControl(template);
this.registerEvents();
this.updateLayout();
- this.selectionManager = new
ClientUI.controls.grid.SelectionManager(this.grid.getElement());
+ this.selectionManager = new ClientUI.controls.grid.SelectionManager(this.grid);
},
registerEvents: function() {
Event.observe(this.scrollBox.eventHScroll, "grid body hscroll",
this._eventOnHScroll);
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-08
09:19:38 UTC (rev 1093)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-06-08
10:28:09 UTC (rev 1094)
@@ -186,17 +186,19 @@
});
Object.extend(ClientUI.controls.grid.SelectionManager.prototype, {
- initialize: function(gridElement) {
- this.rowPrefix = gridElement.id;
+ initialize: function(grid) {
+ var gridElement = grid.getElement();
+ this.prefix = gridElement.id;
this.selection = new ClientUI.controls.grid.Selection();
-// this.restoreState();
+ this.restoreState();
this.eventKeyPress = this.processKeyDown.bindAsEventListener(this);
Event.observe(document, "keypress", this.eventKeyPress);
- var frows = $(this.rowPrefix + ":f").rows;
- var nrows = $(this.rowPrefix + ":n").rows;
+ var frows = $(this.prefix + ":f").rows;
+ var nrows = $(this.prefix + ":n").rows;
+ this.rowCount = frows.length;
var rowIndex;
- for(var i = 0; i < frows.length; i++) {
- rowIndex = Number(frows[i].id.split(this.rowPrefix)[1].split(":")[2]);
+ 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);
}
@@ -221,31 +223,29 @@
// }
},
-
- addListener: function(element, rowIndex) {
- Event.observe(element, "click", this.processClick.bindAsEventListener(this,
rowIndex));
- },
-
-/* restoreState: function() {
- this.selection.initRanges(this.grid.options.selectionField.value);
- this.oldState = this.selection.getState();
+ restoreState: function() {
+ this.selection.initRanges($(this.prefix+":s").value);
var i = 0;
var j;
while(i < this.selection.ranges.length) {
j = this.selection.ranges[i].indexes[0];
while(j <= this.selection.ranges[i].indexes[1]) {
- var r = this.grid.getRowFromId(j);
- if(r) {
- r.addListener();
- }
+ var fElement = $(this.prefix + ":f:" + j);
+ var nElement = $(this.prefix + ":n:" + j);
+ fElement.style.backgroundColor = "#DDDDFF";
+ nElement.style.backgroundColor = "#DDDDFF";
j++;
}
i++;
}
},
- getGridSelection: function() {
+ addListener: function(element, rowIndex) {
+ Event.observe(element, "click", this.processClick.bindAsEventListener(this,
rowIndex));
+ },
+
+/* getGridSelection: function() {
return this.selection.getRanges();
},*/
@@ -276,7 +276,11 @@
switch (event.keyCode || event.charCode) {
case Event.KEY_UP:
if (this.inFocus && activeRow && activeRow > 0) {
- rowIndex = activeRow - 1;
+ if(activeRow) {
+ rowIndex = this.rowCount - 1;
+ } else {
+ rowIndex = activeRow - 1;
+ }
if (!event.ctrlKey && !event.shiftKey) {
range = [rowIndex, rowIndex];
this.setSelection(range);
@@ -296,7 +300,11 @@
break;
case Event.KEY_DOWN:
if (this.inFocus && activeRow) {
- rowIndex = activeRow + 1;
+ if(activeRow == this.rowCount - 1) {
+ rowIndex = 0;
+ } else {
+ rowIndex = activeRow + 1;
+ }
if (!event.ctrlKey && !event.shiftKey) {
range = [rowIndex, rowIndex];
this.setSelection(range);
@@ -316,7 +324,7 @@
break;
case 65: case 97: // Ctrl-A
if (this.inFocus && event.ctrlKey) {
- range = [0, $(this.rowPrefix + ":f").rows.length];
+ range = [0, this.rowCount];
this.setSelection(range);
noDefault = true;
}
@@ -325,6 +333,7 @@
this.lostFocus();
}
if (noDefault) {
+ $(this.prefix+":s").value = this.selection.inspectRanges();
if (event.preventBubble) event.preventBubble();
Event.stop(event);
}
@@ -364,6 +373,7 @@
} else if (document.selection) {
document.selection.empty();
}
+ $(this.prefix+":s").value = this.selection.inspectRanges();
},
setShiftRow: function(event) {
@@ -384,7 +394,7 @@
for (; i <= range[1]; i++) {
this.addRowToSelection(i);
}
- for (; i < $(this.rowPrefix + ":f").rows.length; i++) {
+ for (; i < this.rowCount; i++) {
this.removeRowFromSelection(i);
}
},
@@ -397,16 +407,16 @@
addRowToSelection: function(rowIndex) {
this.selection.addId(rowIndex);
- var fElement = $(this.rowPrefix + ":f:" + rowIndex);
- var nElement = $(this.rowPrefix + ":n:" + rowIndex);
+ var fElement = $(this.prefix + ":f:" + rowIndex);
+ var nElement = $(this.prefix + ":n:" + rowIndex);
fElement.style.backgroundColor = "#DDDDFF";
nElement.style.backgroundColor = "#DDDDFF";
},
removeRowFromSelection: function(rowIndex) {
this.selection.removeId(rowIndex);
- var fElement = $(this.rowPrefix + ":f:" + rowIndex);
- var nElement = $(this.rowPrefix + ":n:" + rowIndex);
+ var fElement = $(this.prefix + ":f:" + rowIndex);
+ var nElement = $(this.prefix + ":n:" + rowIndex);
fElement.style.backgroundColor = "#FFFFFF";
nElement.style.backgroundColor = "#FFFFFF";
},
@@ -414,13 +424,13 @@
setActiveRow: function(rowIndex) {
var fElement, nElement;
if(this.activeRow) {
- fElement = $(this.rowPrefix + ":f:" + this.activeRow);
- nElement = $(this.rowPrefix + ":n:" + this.activeRow);
+ fElement = $(this.prefix + ":f:" + this.activeRow);
+ nElement = $(this.prefix + ":n:" + this.activeRow);
fElement.style.color = "#000000";
nElement.style.color = "#000000";
}
- fElement = $(this.rowPrefix + ":f:" + rowIndex);
- nElement = $(this.rowPrefix + ":n:" + rowIndex);
+ fElement = $(this.prefix + ":f:" + rowIndex);
+ nElement = $(this.prefix + ":n:" + rowIndex);
fElement.style.color = "#0000AA";
nElement.style.color = "#0000AA";
this.activeRow = rowIndex;