Author: nbelaevski
Date: 2011-04-12 08:19:34 -0400 (Tue, 12 Apr 2011)
New Revision: 22415
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js
Log:
https://issues.jboss.org/browse/RF-10626
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java 2011-04-12
10:31:45 UTC (rev 22414)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java 2011-04-12
12:19:34 UTC (rev 22415)
@@ -23,11 +23,6 @@
package org.richfaces.component;
-import org.richfaces.PanelMenuMode;
-import org.richfaces.cdk.annotations.*;
-import org.richfaces.event.ItemChangeEvent;
-import org.richfaces.event.PanelToggleEvent;
-
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
@@ -35,6 +30,15 @@
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
+import org.richfaces.PanelMenuMode;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.event.ItemChangeEvent;
+import org.richfaces.event.PanelToggleEvent;
+
/**
* @author akolonitsky
* @since 2010-10-25
@@ -82,11 +86,44 @@
Boolean previous = (Boolean) getValue();
setExpanded(expanded);
setSubmittedExpanded(null);
+
if (previous != null && !previous.equals(expanded)) {
+ if (expanded && getMode() == PanelMenuMode.server &&
getPanelMenu().isExpandSingle()) {
+ collapseOtherTopGroups();
+ }
+
queueEvent(new PanelToggleEvent(this, previous));
}
}
+ private AbstractPanelMenuGroup getTopGroup() {
+ AbstractPanelMenuGroup c = this;
+
+ while (c.getParent() instanceof AbstractPanelMenuGroup) {
+ c = (AbstractPanelMenuGroup) c.getParent();
+ }
+
+ return c;
+ }
+
+ private void collapseOtherTopGroups() {
+ UIComponent topGroup = getTopGroup();
+ for (UIComponent child: getPanelMenu().getChildren()) {
+ if (!(child instanceof AbstractPanelMenuGroup)) {
+ continue;
+ }
+
+ AbstractPanelMenuGroup group = (AbstractPanelMenuGroup) child;
+
+ if (group == topGroup) {
+ continue;
+ }
+
+ group.setSubmittedExpanded(null);
+ group.setExpanded(false);
+ }
+ }
+
private void executeValidate(FacesContext context) {
try {
validate(context);
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js 2011-04-12
10:31:45 UTC (rev 22414)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js 2011-04-12
12:19:34 UTC (rev 22415)
@@ -195,11 +195,11 @@
return item.itemName == this.activeItem;
},
- __collapseGroups : function (event) {
- var topGroup = rf.$(event.target.id).__rfTopGroup();
+ __collapseGroups : function (source) {
+ var topGroup = source.__rfTopGroup();
this.__childGroups().each (function (index, group) {
- if (group.id != event.target.id && (!topGroup || group.id !=
topGroup.id)) {
- rf.$(group.id).__collapse();
+ if (group.id != source.getEventElement() && (!topGroup || group.id
!= topGroup.id)) {
+ rf.$(group).__collapse();
}
});
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js 2011-04-12
10:31:45 UTC (rev 22414)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js 2011-04-12
12:19:34 UTC (rev 22415)
@@ -203,14 +203,6 @@
});
}
- if (menuGroup.options.expandSingle) {
- var component = this;
- menuGroup.__group().bind("expand", function (event) {
- component.__rfPanelMenu().__collapseGroups(event);
- event.stopPropagation();
- });
- }
-
/*this.__addUserEventHandler("beforecollapse");
this.__addUserEventHandler("collapse");
this.__addUserEventHandler("beforeexpand");
@@ -238,7 +230,9 @@
__expand : function () {
this.__updateStyles(true);
- return this.__fireEvent("expand");
+ this.__collapseForExpandSingle();
+
+ return this.__fireEvent("expand");
},
collapsed : function () {
@@ -350,6 +344,12 @@
return this.__expandValueInput().value == "true";
},
+ __collapseForExpandSingle: function() {
+ if (this.options.expandSingle) {
+ this.__rfPanelMenu().__collapseGroups(this);
+ }
+ },
+
/**
* @methodOf
* @name PanelMenuGroup#__setExpandValue
@@ -367,6 +367,10 @@
},
__changeState : function () {
+ if (!this.__getExpandValue()) {
+ this.__collapseForExpandSingle();
+ }
+
var state = {};
state["expanded"] =
this.__setExpandValue(!this.__getExpandValue());
if (this.options.selectable) {