[richfaces-svn-commits] JBoss Rich Faces SVN: r2212 - in trunk/ui/tree/src/main: resources/org/richfaces/renderkit/html/scripts and 1 other directory.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Sat Aug 11 19:25:06 EDT 2007
Author: nbelaevski
Date: 2007-08-11 19:25:05 -0400 (Sat, 11 Aug 2007)
New Revision: 2212
Modified:
trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
Log:
Tree:
- Fixes
- Client code optimized
Modified: trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-08-11 00:49:45 UTC (rev 2211)
+++ trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-08-11 23:25:05 UTC (rev 2212)
@@ -363,13 +363,13 @@
}
if (encodeScripts) {
writeScript(context, tree, encodedAreaIds, renderedAreas);
+
+ String inputId = encodeSelectionStateInput(context, tree);
+ if (inputId != null) {
+ renderedAreas.add(inputId);
+ }
}
- String inputId = encodeSelectionStateInput(context, tree);
- if (inputId != null) {
- renderedAreas.add(inputId);
- }
-
responseWriter.endElement("div");
}
} finally {
Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-08-11 00:49:45 UTC (rev 2211)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-08-11 23:25:05 UTC (rev 2212)
@@ -1,13 +1,12 @@
Tree.Item = Class.create();
Tree.Item.prototype = {
- initialize: function(id, tree, parent, index, switchType, toggleOnClick) {
- this.index = index;
+ initialize: function(id, tree, parent) {
this.parent = parent;
this.id = id;
- this.switchType = switchType;
this.tree = tree;
this.elements = {};
this.elementID = {};
+ ($(this.id)).object = this;
this.elementID.children = this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW;
this.elementID.mainRow = this.id + Tree.ID_DEVIDER + Tree.ID_MAIN_ROW;
@@ -17,9 +16,6 @@
this.elementID.icon = this.id + Tree.ID_DEVIDER + Tree.ID_ICON;
this.elementID.text = this.id + Tree.ID_DEVIDER + Tree.ID_TEXT;
- ($(this.id)).object = this;
-
- this.toggleOnClick = toggleOnClick;
this.getElements();
this.eventSelectionClick = this.toggleSelection.bindAsEventListener(this);
@@ -33,6 +29,18 @@
this.observeEvents();
},
+ destroy: function() {
+ if (this == this.tree.selectionManager.activeItem) {
+ this.tree.selectionManager.activeItem = null;
+ }
+
+ for (var i = 0; i < this.childs.length; i++) {
+ this.childs[i].destroy();
+ }
+
+ this.childs = null;
+ },
+
observeEvents: function() {
var eIcon = $(this.elementID.icon);
var eText = $(this.elementID.text);
@@ -54,19 +62,15 @@
}
}
- if (this.switchType=="client" && this.childs.length > 0) {
+ if (this.tree.switchType=="client" && this.childs.length > 0) {
this.eventCollapsionClick = this.toggleCollapsion.bindAsEventListener(this);
- if (this.toggleOnClick) {
- Event.observe(this.elementID.mainRow, "click", this.eventCollapsionClick);
- } else {
- //if (this.elements.handle)
- Event.observe(this.elementID.handle, "click", this.eventCollapsionClick);
- }
+
+ var handleElt = this.tree.toggleOnClick ? this.elementID.mainRow : this.elementID.handle;
+ Event.observe(handleElt, "click", this.eventCollapsionClick);
}
},
getElements: function() {
-
this.childs = [];
var contextMenu = Richfaces.getNSAttribute("oncontextmenu", $(this.elementID.icon));
@@ -81,7 +85,7 @@
while ( child != null )
{
if (child.nodeType == 1 && child.tagName.toLowerCase() == "table") {
- this.addChild(new Tree.Item(child.id, this.tree, this, this.childs.length, this.switchType, this.toggleOnClick));
+ this.addChild(new Tree.Item(child.id, this.tree, this));
}
child = child.nextSibling;
}
@@ -89,7 +93,7 @@
for (var i = 0; i < childsTd.childNodes.length; i++) {
var child = childsTd.childNodes[i];
if (child.nodeType == 1 && child.tagName.toLowerCase() == "table") {
- this.addChild(new Tree.Item(child.id, this.tree, this, this.childs.length, this.switchType, this.toggleOnClick));
+ this.addChild(new Tree.Item(child.id, this.tree, this));
}
}
*/
@@ -98,7 +102,6 @@
addChild: function(child) {
this.childs.push(child);
- this.tree.addItem(child);
},
fireExpansionEvent: function() {
@@ -168,17 +171,13 @@
},
collapse: function() {
- if (!this.isCollapsed() && this.switchType!="client") {
- if (this.toggleOnClick) {
- var e = $(this.elementID.mainRow);
- if (e)
- e.onclick();
- } else {
- var e = $(this.elementID.handle);
- if (e)
- e.onclick();
+ if (!this.isCollapsed() && this.tree.switchType!="client") {
+ var handleElt = $(this.tree.toggleOnClick ? this.elementID.mainRow : this.elementID.handle);
+ if (handleElt) {
+ handleElt.onclick();
}
}
+
if (this.hasChilds() && !this.isCollapsed()) {
Element.hide(this.elementID.children);
Element.hide(this.elementID.handleImgExpanded);
@@ -194,17 +193,13 @@
},
expand: function() {
- if (this.isCollapsed() && this.switchType!="client") {
- if (this.toggleOnClick) {
- var e = $(this.elementID.mainRow);
- if (e)
- e.onclick();
- } else {
- var e = $(this.elementID.handle);
- if (e)
- e.onclick();
+ if (this.isCollapsed() && this.tree.switchType!="client") {
+ var handleElt = $(this.tree.toggleOnClick ? this.elementID.mainRow : this.elementID.handle);
+ if (handleElt) {
+ handleElt.onclick();
}
}
+
if (this.hasChilds() && this.isCollapsed()) {
Element.show(this.elementID.children);
Element.show(this.elementID.handleImgExpanded);
@@ -288,7 +283,10 @@
return !evt.event["cancelSelection"];
} else {
- this.tree.deselectAll();
+ var activeItem = this.tree.selectionManager.activeItem;
+ if (activeItem) {
+ activeItem.deselect();
+ }
/*
var attr = this.elements.text.attributes;
@@ -339,19 +337,27 @@
},
next: function() {
- if (this.index < (this.parent.childs.length - 1)) {
- return this.parent.childs[this.index + 1];
- } else {
- return this;
+ var children = this.parent.childs;
+
+ for (var i = 0; i < children.length - 1; i++) {
+ if (children[i] == this) {
+ return children[i + 1];
+ }
}
+
+ return this;
},
previous: function() {
- if (this.index > 0) {
- return this.parent.childs[this.index - 1];
- } else {
- return this;
+ var children = this.parent.childs;
+
+ for (var i = 1; i < children.length; i++) {
+ if (children[i] == this) {
+ return children[i - 1];
+ }
}
+
+ return this;
},
hasChilds: function() {
Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js 2007-08-11 00:49:45 UTC (rev 2211)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-selection.js 2007-08-11 23:25:05 UTC (rev 2212)
@@ -1,35 +1,3 @@
-Tree.Selection = Class.create();
-Tree.Selection.prototype = {
- initialize: function() {
- this.indexes = [];
- this.ranges = [];
- },
-
- addRange: function(range) {
- this.ranges.push(range);
- },
-
- addIndex: function(index) {
- this.indexes.push(index);
- },
-
- getRanges: function() {
- var ranges = [];
- if (this.indexes.length == 0) return ranges;
- ranges.push(new DataGrid.Range(this.indexes[0], this.indexes[0]));
- var current = ranges[ranges.length - 1];
- for (var i = 1; i < this.indexes.length; i++) {
- if (this.indexes[i] - current.indexes[1] > 1) {
- ranges.push(new DataGrid.Range(this.indexes[i], this.indexes[i]));
- current = ranges[ranges.length - 1];
- } else {
- current.indexes[1] = this.indexes[i];
- }
- }
- return ranges;
- }
-}
-
Tree.SelectionManager = Class.create();
Tree.SelectionManager.prototype = {
initialize: function(tree) {
Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-08-11 00:49:45 UTC (rev 2211)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-08-11 23:25:05 UTC (rev 2212)
@@ -20,7 +20,6 @@
Tree.prototype = {
initialize: function(id, input, switchType, events, onAjaxSelect, dragIndicatorId, toggleOnClick) {
- this.items = [];
this.childs = [];
this.elements = {};
@@ -118,7 +117,7 @@
if (this.elements.contentTd) {
for(var child = this.elements.contentTd.firstChild; child != null; child = child.nextSibling ) {
if (child.nodeType == 1 && child.tagName.toLowerCase() == "table") {
- this.addChild(new Tree.Item(child.id, this, this, this.childs.length, this.switchType, this.toggleOnClick));
+ this.addChild(new Tree.Item(child.id, this, this));
}
}
/*
@@ -164,36 +163,36 @@
addChild: function(child) {
this.childs.push(child);
- this.addItem(child);
},
- addItem: function(item) {
- this.items.push(item);
- },
-
- deselectAll: function() {
- this.items.each(function(item) {item.deselect();} );
- },
-
-
getNodeElements: function(nodeIds) {
if (nodeIds) {
for (var i = 0; i < nodeIds.length; i++ ) {
- this._getNodeElements(this, nodeIds[i]);
+ var nodeId = nodeIds[i];
+ this._getNodeElements(this, nodeId, nodeId.substring(0, nodeId.lastIndexOf(':')));
}
+ //input holding selection has been refreshed
+ this.input = $(this.inputId);
this.selectionManager.restoreSelection();
}
},
- _getNodeElements: function(node, nodeId) {
- if (node.id == nodeId) {
- node.getElements();
- node.observeEvents();
- this.input = $(this.inputId);
- } else {
- for (var i = 0; i < node.childs.length; i++) {
- this._getNodeElements(node.childs[i], nodeId);
+ _getNodeElements: function(node, nodeId, sNodeId) {
+ for (var i = 0; i < node.childs.length; i++) {
+ var child = node.childs[i];
+ var cid = child.id;
+
+ if (cid == nodeId) {
+ child.destroy();
+ node.childs[i] = new Tree.Item(cid, this, child.parent);
+ break;
+ } else {
+ var scid = cid.substring(0, cid.lastIndexOf(':'));
+ if (sNodeId.substr(0, scid.length) == scid && sNodeId.charAt(scid.length) == ':') {
+ this._getNodeElements(child, nodeId, sNodeId);
+ break;
+ }
}
}
},
More information about the richfaces-svn-commits
mailing list