Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 22104 invoked from network); 4 May 2007 19:26:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 May 2007 19:26:06 -0000 Received: (qmail 52434 invoked by uid 500); 4 May 2007 19:26:12 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 51891 invoked by uid 500); 4 May 2007 19:26:11 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 51882 invoked by uid 99); 4 May 2007 19:26:11 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 May 2007 12:26:10 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 May 2007 12:26:03 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 82BB21A9838; Fri, 4 May 2007 12:25:43 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r535360 - in /struts/struts2/trunk/plugins/dojo/src/main: java/org/apache/struts2/dojo/components/ java/org/apache/struts2/dojo/views/jsp/ui/ resources/org/apache/struts2/static/dojo/struts/widget/ resources/template/ajax/ Date: Fri, 04 May 2007 19:25:43 -0000 To: commits@struts.apache.org From: musachy@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070504192543.82BB21A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: musachy Date: Fri May 4 12:25:42 2007 New Revision: 535360 URL: http://svn.apache.org/viewvc?view=rev&rev=535360 Log: WW-1837 TabbedPanel selectedTab change event catch! Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java?view=diff&rev=535360&r1=535359&r2=535360 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java (original) +++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java Fri May 4 12:25:42 2007 @@ -41,23 +41,43 @@ * * The following is an example of a tabbedpanel and panel tag utilizing local and remote content.

* - *

+ * 
  * 
- * <s:tabbedpanel id="test" >
- *    <s:div id="one" label="one" theme="ajax" labelposition="top" >
+ * 
+ * <s:tabbedpanel id="test" >
+ *    <s:div id="one" label="one" theme="ajax" labelposition="top" >
  *        This is the first pane<br/>
  *        <s:form>
- *            <s:textfield name="tt" label="Test Text"/>  <br/>
- *            <s:textfield name="tt2" label="Test Text2"/>
+ *            <s:textfield name="tt" label="Test Text"/>  <br/>
+ *            <s:textfield name="tt2" label="Test Text2"/>
  *        </s:form>
  *    </s:div>
- *    <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" >
+ *    <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" >
  *        This is the remote tab
  *    </s:div>
  * </s:tabbedpanel>
+ * 
* + * + * + *

Use notify topics to prevent a tab from being selected

+ *
+ * <script type="text/javascript">
+ * dojo.event.topic.subscribe("/beforeSelect", function(tab, cancel){
+ *     cancel.cancel = true;
+ * });
+ * </script>
+ * 
+ * <s:tabbedpanel id="test" beforeSelectTabNotifyTopics="/beforeSelect">
+ *    <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" >
+ *        One Tab
+ *    </s:div>
+ *    <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" >
+ *        Another tab
+ *    </s:div>
+ * </s:tabbedpanel>
  * 
- * + * */ @StrutsTag(name="tabbedpanel", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TabbedPanelTag", description="Render a tabbedPanel widget.") public class TabbedPanel extends ClosingUIBean { @@ -69,7 +89,9 @@ protected String closeButton; protected String doLayout ; protected String templateCssPath; - + protected String beforeSelectTabNotifyTopics; + protected String afterSelectTabNotifyTopics; + public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } @@ -78,12 +100,12 @@ protected void evaluateExtraParams() { super.evaluateExtraParams(); - if(selectedTab != null) + if (selectedTab != null) addParameter("selectedTab", findString(selectedTab)); - if(closeButton != null) + if (closeButton != null) addParameter("closeButton", findString(closeButton)); addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) : Boolean.FALSE); - if(labelPosition != null) { + if (labelPosition != null) { //dojo has some weird name for label positions if(labelPosition.equalsIgnoreCase("left")) labelPosition = "left-h"; @@ -92,8 +114,13 @@ addParameter("labelPosition", null); addParameter("labelPosition", labelPosition); } - if(templateCssPath != null) + if (templateCssPath != null) addParameter("templateCssPath", findString(templateCssPath)); + if (beforeSelectTabNotifyTopics!= null) + addParameter("beforeSelectTabNotifyTopics", findString(beforeSelectTabNotifyTopics)); + if (afterSelectTabNotifyTopics!= null) + addParameter("afterSelectTabNotifyTopics", findString(afterSelectTabNotifyTopics)); + } @Override @@ -144,5 +171,19 @@ @StrutsTagAttribute(description="Template css path") public void setTemplateCssPath(String templateCssPath) { this.templateCssPath = templateCssPath; + } + + + @StrutsTagAttribute(description="Comma separated list of topics to be published when a tab is clicked on (before it is selected)" + + "The tab widget will be passed as the first argument to the topic. The event can be cancelled setting to 'true' the 'cancel' property " + + "of the second parameter passed to the topics.") + public void setBeforeSelectTabNotifyTopics(String selectedTabNotifyTopics) { + this.beforeSelectTabNotifyTopics = selectedTabNotifyTopics; + } + + @StrutsTagAttribute(description="Comma separated list of topics to be published when a tab is clicked on (after it is selected)." + + "The tab widget will be passed as the first argument to the topic.") + public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) { + this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics; } } Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java?view=diff&rev=535360&r1=535359&r2=535360 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java (original) +++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java Fri May 4 12:25:42 2007 @@ -40,7 +40,9 @@ private String closeButton; private String doLayout; private String templateCssPath; - + private String beforeSelectTabNotifyTopics; + private String afterSelectTabNotifyTopics; + public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new TabbedPanel(stack, req, res); } @@ -53,6 +55,8 @@ tabbedPanel.setDoLayout(doLayout); tabbedPanel.setLabelposition(labelPosition); tabbedPanel.setTemplateCssPath(templateCssPath); + tabbedPanel.setBeforeSelectTabNotifyTopics(beforeSelectTabNotifyTopics); + tabbedPanel.setAfterSelectTabNotifyTopics(afterSelectTabNotifyTopics); } public void setSelectedTab(String selectedTab) { @@ -69,5 +73,13 @@ public void setTemplateCssPath(String templateCssPath) { this.templateCssPath = templateCssPath; + } + + public void setBeforeSelectTabNotifyTopics(String beforeSelectTabNotifyTopics) { + this.beforeSelectTabNotifyTopics = beforeSelectTabNotifyTopics; + } + + public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) { + this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics; } } Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js?view=auto&rev=535360 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js Fri May 4 12:25:42 2007 @@ -0,0 +1,56 @@ +dojo.provide("struts.widget.StrutsTabContainer"); + +dojo.require("dojo.widget.TabContainer"); + +dojo.widget.defineWidget( + "struts.widget.StrutsTabContainer", + dojo.widget.TabContainer, { + widgetType : "StrutsTabContainer", + + afterSelectTabNotifyTopics : "", + afterSelectTabNotifyTopicsArray : null, + beforeSelectTabNotifyTopics : "", + beforeSelectTabNotifyTopicsArray : null, + + postCreate : function() { + struts.widget.StrutsTabContainer.superclass.postCreate.apply(this); + + //before topics + if(!dojo.string.isBlank(this.beforeSelectTabNotifyTopics)) { + this.beforeSelectTabNotifyTopicsArray = this.beforeSelectTabNotifyTopics.split(","); + } + + //after topics + if(!dojo.string.isBlank(this.afterSelectTabNotifyTopics)) { + this.afterSelectTabNotifyTopicsArray = this.afterSelectTabNotifyTopics.split(","); + } + }, + + selectChild: function (tab, callingWidget) { + var cancel = {"cancel" : false}; + + if(this.beforeSelectTabNotifyTopicsArray) { + dojo.lang.forEach(this.beforeSelectTabNotifyTopicsArray, function(topic) { + try { + dojo.event.topic.publish(topic, tab, cancel); + } catch(ex){ + dojo.debug(ex); + } + }); + } + + if(!cancel.cancel) { + struts.widget.StrutsTabContainer.superclass.selectChild.apply(this, [tab, callingWidget]); + + if(this.afterSelectTabNotifyTopicsArray) { + dojo.lang.forEach(this.afterSelectTabNotifyTopicsArray, function(topic) { + try { + dojo.event.topic.publish(topic, tab, cancel); + } catch(ex){ + dojo.debug(ex); + } + }); + } + } + } +}); Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js?view=diff&rev=535360&r1=535359&r2=535360 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js (original) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js Fri May 4 12:25:42 2007 @@ -6,6 +6,7 @@ "struts.widget.StrutsTimePicker", "struts.widget.StrutsDatePicker", "struts.widget.BindEvent", - "struts.widget.StrutsTreeSelector"] + "struts.widget.StrutsTreeSelector", + "struts.widget.StrutsTabContainer"] }); dojo.provide("struts.widget.*"); Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl?view=diff&rev=535360&r1=535359&r2=535360 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl (original) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl Fri May 4 12:25:42 2007 @@ -1,4 +1,4 @@ -
style="${parameters.cssStyle?html}"<#rt/> @@ -25,6 +25,12 @@ <#if parameters.templateCssPath?exists> templateCssPath="<@s.url value='${parameters.templateCssPath}' encode="false" includeParams='none'/>" + + <#if parameters.beforeSelectTabNotifyTopics?if_exists != ""> + beforeSelectTabNotifyTopics="${parameters.beforeSelectTabNotifyTopics?html}"<#rt/> + + <#if parameters.afterSelectTabNotifyTopics?if_exists != ""> + afterSelectTabNotifyTopics="${parameters.afterSelectTabNotifyTopics?html}"<#rt/> <#include "/${parameters.templateDir}/simple/scripting-events.ftl" /> <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />