Author: nbelaevski
Date: 2011-01-26 18:27:29 -0500 (Wed, 26 Jan 2011)
New Revision: 21251
Modified:
trunk/examples/output-demo/src/main/webapp/examples/panelMenu.xhtml
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.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/panelMenuItem.js
Log:
https://issues.jboss.org/browse/RF-10211
Modified: trunk/examples/output-demo/src/main/webapp/examples/panelMenu.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/examples/panelMenu.xhtml 2011-01-26
20:08:44 UTC (rev 21250)
+++ trunk/examples/output-demo/src/main/webapp/examples/panelMenu.xhtml 2011-01-26
23:27:29 UTC (rev 21251)
@@ -49,7 +49,7 @@
itemLeftIconDisabled="triangleLeft"
topItemLeftIconDisabled="triangleUp"
topItemLeftIcon="triangleDown"
- groupMode="client">
+ groupMode="client" activeItem="item41">
<rich:panelMenuGroup id="group1" label="Group 1"
disabled="true">
<rich:panelMenuItem id="item11" label="Item 1.1" />
<rich:panelMenuItem id="item12" label="Item 1.2" />
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2011-01-26
20:08:44 UTC (rev 21250)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2011-01-26
23:27:29 UTC (rev 21251)
@@ -42,10 +42,14 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSObject;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.richfaces.PanelMenuMode;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPanelMenuGroup;
import org.richfaces.component.AbstractPanelMenuItem;
+import org.richfaces.renderkit.HtmlConstants;
import com.google.common.base.Strings;
@@ -220,5 +224,65 @@
protected Class<? extends UIComponent> getComponentClass() {
return AbstractPanelMenuGroup.class;
}
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ private boolean containsActiveItem(UIComponent component, String activeItem) {
+ if (component instanceof AbstractPanelMenuItem) {
+ AbstractPanelMenuItem item = (AbstractPanelMenuItem) component;
+ if (activeItem.equals(item.getName())) {
+ return true;
+ }
+ }
+
+ if (component instanceof AbstractPanelMenuGroup) {
+ AbstractPanelMenuGroup group = (AbstractPanelMenuGroup) component;
+ if (!group.isBubbleSelection()) {
+ return false;
+ }
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ if (!child.isRendered()) {
+ continue;
+ }
+
+ if (!(child instanceof AbstractPanelMenuItem)) {
+ continue;
+ }
+
+ if (containsActiveItem(child, activeItem)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
+ AbstractPanelMenuGroup group = (AbstractPanelMenuGroup) component;
+
+ boolean isClientMode = group.getMode() == PanelMenuMode.client;
+
+ if (isClientMode || group.isExpanded()) {
+ renderChildren(context, component);
+ } else {
+ String activeItem = group.getPanelMenu().getActiveItem();
+ if (!Strings.isNullOrEmpty(activeItem) &&
containsActiveItem(component, activeItem)) {
+ writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
+ writer.writeAttribute(HtmlConstants.TYPE_ATTR,
HtmlConstants.TEXT_JAVASCRIPT_TYPE, null);
+ writer.writeText(ScriptUtils.toScript(new
JSFunction("RichFaces.$", component.getClientId(context))) +
".__restoreSelection();", null);
+ writer.endElement(HtmlConstants.SCRIPT_ELEM);
+ }
+ }
+ }
}
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-01-26
20:08:44 UTC (rev 21250)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js 2011-01-26
23:27:29 UTC (rev 21251)
@@ -43,7 +43,7 @@
* */
init : function (componentId, options) {
$super.constructor.call(this, componentId);
- this.items = [];
+ this.items = {};
this.attachToDom();
this.options = $.extend(this.options, __DEFAULT_OPTIONS, options || {});
@@ -63,22 +63,22 @@
});
}
- if (menuGroup.activeItem) {
- this.__panelMenu().ready(function () {
- var item = menuGroup.items[menuGroup.activeItem];
- item.__select();
- item.__fireSelect();
- })
- }
-
this.__addUserEventHandler("collapse");
this.__addUserEventHandler("expand");
},
- getItems: function () {
- return this.items;
+ addItem: function(item) {
+ this.items[item.itemName] = item;
},
+
+ deleteItem: function(item) {
+ delete this.items[item.itemName];
+ },
+ getSelectedItem: function() {
+ return this.getItem(this.selectedItem());
+ },
+
getItem: function (name) {
return this.items[name];
},
@@ -113,6 +113,13 @@
this.activeItem = id;
valueInput.value = id;
+ for (var itemName in this.items) {
+ var item = this.items[itemName];
+ if (item.__isSelected()) {
+ item.__unselect();
+ }
+ }
+
return prevActiveItem;
} else {
return this.activeItem;
@@ -196,6 +203,10 @@
}
},
+ __isActiveItem: function(item) {
+ return item.itemName == this.activeItem;
+ },
+
destroy: function () {
rf.Event.unbindById(this.id, "."+this.namespace);
$super.destroy.call(this);
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js 2011-01-26
20:08:44 UTC (rev 21250)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js 2011-01-26
23:27:29 UTC (rev 21251)
@@ -90,11 +90,13 @@
* */
execClient : function (item) {
var panelMenu = item.__rfPanelMenu();
- if (panelMenu.selectedItem()) {
- panelMenu.getItems()[panelMenu.selectedItem()].unselect();
- }
- panelMenu.selectedItem(item.itemName);
+ var prevItem = panelMenu.getSelectedItem();
+ if (prevItem) {
+ prevItem.unselect();
+ }
+ panelMenu.selectedItem(item.itemName);
+
item.__select();
return item.__fireSelect();
@@ -122,18 +124,23 @@
* */
init : function (componentId, options) {
$super.constructor.call(this, componentId);
- this.attachToDom();
+ var rootElt = $(this.attachToDom());
this.options = $.extend(this.options, __DEFAULT_OPTIONS, options || {});
this.mode = this.options.mode;
this.itemName = this.options.name;
- this.__rfPanelMenu().getItems()[this.itemName] = this;
+ var panelMenu = this.__rfPanelMenu();
+ panelMenu.addItem(this);
// todo move it
this.selectionClass = this.options.stylePrefix + "-sel";
this.hoverClass = this.options.stylePrefix + "-hov";
-
+
+ if (panelMenu.__isActiveItem(this)) {
+ rootElt.ready($.proxy(this.__restoreSelection, this));
+ }
+
if (!this.options.disabled) {
var item = this;
if (this.options.highlight) {
@@ -276,6 +283,15 @@
return this.__item();
},
+ __restoreSelection: function() {
+ this.__select();
+ this.__fireSelect();
+ },
+
+ __isSelected: function() {
+ return this.__header().hasClass(this.selectionClass);
+ },
+
__select: function () {
this.__header().addClass(this.selectionClass);
},
@@ -314,8 +330,8 @@
destroy: function () {
var panelMenu = this.__rfPanelMenu();
- if (panelMenu && panelMenu.getItems &&
panelMenu.getItems()[this.itemName]) {
- delete panelMenu.getItems()[this.itemName];
+ if (panelMenu) {
+ panelMenu.deleteItem(this);
}
$super.destroy.call(this);