Author: abelevich
Date: 2007-11-19 12:32:54 -0500 (Mon, 19 Nov 2007)
New Revision: 4093
Modified:
trunk/ui/simpleTogglePanel/src/main/config/component/simpleTogglePanel.xml
trunk/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java
trunk/ui/simpleTogglePanel/src/main/resources/org/richfaces/renderkit/html/scripts/simpleTogglePanel.js
trunk/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx
Log:
add onexpand oncollapse client Event (in the context of the RF-256)
Modified: trunk/ui/simpleTogglePanel/src/main/config/component/simpleTogglePanel.xml
===================================================================
--- trunk/ui/simpleTogglePanel/src/main/config/component/simpleTogglePanel.xml 2007-11-19
17:05:18 UTC (rev 4092)
+++ trunk/ui/simpleTogglePanel/src/main/config/component/simpleTogglePanel.xml 2007-11-19
17:32:54 UTC (rev 4093)
@@ -97,7 +97,20 @@
</description>
<defaultvalue>true</defaultvalue>
</property>
-
-
+
+ <property>
+ <name>onexpand</name>
+ <classname>java.lang.String</classname>
+ <description> Event must occurs on befor panel expanded</description>
+ <defaultvalue><![CDATA[""]]></defaultvalue>
+ </property>
+
+ <property>
+ <name>oncollapse</name>
+ <classname>java.lang.String</classname>
+ <description> Event must occurs on befor panel collapsed</description>
+ <defaultvalue><![CDATA[""]]></defaultvalue>
+ </property>
</component>
+
</components>
Modified:
trunk/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java
===================================================================
---
trunk/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java 2007-11-19
17:05:18 UTC (rev 4092)
+++
trunk/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java 2007-11-19
17:32:54 UTC (rev 4093)
@@ -24,7 +24,11 @@
*/
package org.richfaces.renderkit.html;
+import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UISimpleTogglePanel;
import org.richfaces.event.SimpleToggleEvent;
@@ -114,10 +118,6 @@
}
}
-
-
-
-
}
public String getdivdisplay(FacesContext context, UIComponent component) {
@@ -136,6 +136,9 @@
String switchType = tgComp.getSwitchType();
StringBuffer onClick = new StringBuffer();
+ JSReference eventRef = new JSReference("event");
+ String panelId = tgComp.getClientId(context);
+
//String userOnClick =
(String)component.getAttributes().get("onclick");
//if(userOnClick!=null) {
// onClick.append(userOnClick);
@@ -144,28 +147,41 @@
// }
//}
-
- if (UISimpleTogglePanel.CLIENT_SWITCH_TYPE.equals(switchType)) {
+ if (UISimpleTogglePanel.CLIENT_SWITCH_TYPE.equals(switchType)) {
// Client
- String panelId = tgComp.getClientId(context);
- onClick.append("SimpleTogglePanelManager.toggleOnClient('")
- .append(panelId)
- .append("');");
+ JSFunction function = new
JSFunction("SimpleTogglePanelManager.toggleOnClient");
+ function.addParameter(eventRef);
+ function.addParameter(panelId);
+ function.appendScript(onClick);
+ onClick.append(";");
+
} else if (UISimpleTogglePanel.AJAX_SWITCH_TYPE.equals(switchType)) {
- // Ajax
- //
writer.writeAttribute(HTML.onclick_ATTRIBUTE,AjaxRendererUtils.buildOnClick(tab,context),"ajaxOnclick");
- onClick.append(AjaxRendererUtils.buildOnClick(component, context));
- //return super.getOnClick(context, component);
+// Ajax
+
+ JSFunction function = new
JSFunction("SimpleTogglePanelManager.toggleOnAjax");
+ function.addParameter(eventRef);
+ function.addParameter(panelId);
+ function.appendScript(onClick);
+ onClick.append(";");
+
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(tgComp, context);
+ ajaxFunction.addParameter(AjaxRendererUtils.buildEventOptions(context,
tgComp));
+ ajaxFunction.appendScript(onClick);
+
+ if (tgComp instanceof AjaxSupport) {
+ AjaxSupport support = (AjaxSupport) tgComp;
+ if (support.isDisableDefault()) {
+ onClick.append("; return false;");
+ }
+ }
+
} else {
// Server
-
-
- onClick.append("SimpleTogglePanelManager.toggleOnServer('")
- .append(component.getClientId(context))
- .append("'")
-
-
- .append(");");
+ JSFunction function = new
JSFunction("SimpleTogglePanelManager.toggleOnServer");
+ function.addParameter(eventRef);
+ function.addParameter(panelId);
+ function.appendScript(onClick);
+ onClick.append(";");
//.append(tgComp.getSwitch()==null?"'0'":"'"
+ tgComp.getSwitch() + "'")
//.append("")
}
Modified:
trunk/ui/simpleTogglePanel/src/main/resources/org/richfaces/renderkit/html/scripts/simpleTogglePanel.js
===================================================================
---
trunk/ui/simpleTogglePanel/src/main/resources/org/richfaces/renderkit/html/scripts/simpleTogglePanel.js 2007-11-19
17:05:18 UTC (rev 4092)
+++
trunk/ui/simpleTogglePanel/src/main/resources/org/richfaces/renderkit/html/scripts/simpleTogglePanel.js 2007-11-19
17:32:54 UTC (rev 4093)
@@ -2,15 +2,28 @@
SimpleTogglePanel = Class.create();
SimpleTogglePanel.prototype = {
- initialize: function(panelId, status) {
+ initialize: function(panelId, status, options) {
this.panelId = panelId;
- this.panelId_head = panelId+"_header";
- this.status = status;
- if (!this.status){
- this.status="true";
- }
-
+ this.panelId_head = panelId+"_header";
+ this.options = options;
+ this.status = status;
+
+ if (!this.status) {
+ this.status="true";
+ }
+
+ var onexpand = this.options.onexpand;
+ var oncollapse = this.options.oncollapse
+
+ if (oncollapse) {
+ this.onCollapseEvent = new
Function("event",oncollapse).bindAsEventListener(this);
+ }
+
+ if (onexpand) {
+ this.onExpandEvent = new
Function("event",onexpand).bindAsEventListener(this);
+ }
+
// this.timer = setTimeout(this.windowOnLoad.bind(this), 100);
},
@@ -28,13 +41,14 @@
},
*/
- toggleToState: function() {
+ toggleToState: function(event) {
var body = $(this.panelId+"_body");
var switch_on = $(this.panelId+"_switch_on");
var switch_off = $(this.panelId+"_switch_off");
if (this.status=="false"){
Element.show(body);
this.status="true";
+ this.onExpandEvent(event);
switch_off.style.display="none";
switch_on.style.display="";
// this.timer = setTimeout(this.windowOnLoad.bind(this), 100);
@@ -43,6 +57,7 @@
Element.hide(body);
body.firstChild.style.width="100%";
this.status="false";
+ this.onCollapseEvent(event);
switch_on.style.display="none";
switch_off.style.display="";
@@ -66,7 +81,7 @@
this.panels=this.panels.merge(tmp);
}
-SimpleTogglePanelManager.toggleOnServer = function (clientId) {
+SimpleTogglePanelManager.toggleOnServer = function (event,clientId) {
var parentForm = A4J.findForm($(clientId + "_header"));
if(!parentForm || !parentForm.appendChild /* findForm returns surrogate form object */)
return;
@@ -78,11 +93,18 @@
parentForm.appendChild(fInput);
}
- if (this.panels[clientId].status==0){
- this.panels[clientId].status=1;
- }
- else{
- this.panels[clientId].status=0;
+ if (this.panels[clientId].status == "true"){
+ this.panels[clientId].status="false";
+ if(this.panels[clientId].options.oncollapse){
+ this.panels[clientId].onCollapseEvent(event);
+ }
+
+
+ } else {
+ this.panels[clientId].status="true";
+ if(this.panels[clientId].options.onexpand){
+ this.panels[clientId].onExpandEvent(event);
+ }
}
fInput.value = this.panels[clientId].status;
@@ -90,7 +112,21 @@
return false;
}
-SimpleTogglePanelManager.toggleOnClient = function (panelId) {
- this.panels[panelId].toggleToState();
+SimpleTogglePanelManager.toggleOnClient = function (event,panelId) {
+ this.panels[panelId].toggleToState(event);
return false;
}
+
+SimpleTogglePanelManager.toggleOnAjax = function(event,panelId) {
+ if (this.panels[panelId].status == "true") {
+ if(this.panels[panelId].options.oncollapse){
+ this.panels[panelId].onCollapseEvent(event);
+ }
+ } else {
+ if (this.panels[panelId].options.onexpand) {
+ this.panels[panelId].onExpandEvent(event);
+ }
+ }
+}
+
+
Modified: trunk/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx
===================================================================
--- trunk/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx 2007-11-19
17:05:18 UTC (rev 4092)
+++ trunk/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx 2007-11-19
17:32:54 UTC (rev 4093)
@@ -25,7 +25,7 @@
style="width: #{component.attributes['width']};
#{component.attributes['style']};">
<script type="text/javascript">
- SimpleTogglePanelManager.add(new SimpleTogglePanel("#{clientId}",
"#{component.attributes['opened']}"));
+ SimpleTogglePanelManager.add(new SimpleTogglePanel("#{clientId}",
"#{component.attributes['opened']}", {onexpand:
"#{component.attributes['onexpand']}",oncollapse:
"#{component.attributes['oncollapse']}"}));
</script>
<f:call name="utils.encodeBeginFormIfNessesary"/>