You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2007/05/05 20:45:03 UTC

svn commit: r535556 [1/3] - 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/ resources/org/apache/struts2/static/dojo/ resources/org...

Author: musachy
Date: Sat May  5 11:45:02 2007
New Revision: 535556

URL: http://svn.apache.org/viewvc?view=rev&rev=535556
Log:
WW-1909 User should be able to enable/disable tabs in the tabbedpanel tag

Added:
    struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/TabbedPanel.css
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/BindDiv.js
    struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js
    struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js
    struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js.uncompressed.js
    struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/div.ftl
    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=535556&r1=535555&r2=535556
==============================================================================
--- 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 Sat May  5 11:45:02 2007
@@ -63,7 +63,7 @@
  * <p>Use notify topics to prevent a tab from being selected</p>
  * <pre>
  * &lt;script type="text/javascript"&gt;
- * dojo.event.topic.subscribe("/beforeSelect", function(tab, cancel){
+ * dojo.event.topic.subscribe("/beforeSelect", function(tabContainer, tab, cancel){
  *     cancel.cancel = true;
  * });
  * &lt;/script&gt;
@@ -91,6 +91,7 @@
     protected String templateCssPath;
     protected String beforeSelectTabNotifyTopics;
     protected String afterSelectTabNotifyTopics;
+    protected String disabledTabCssClass; 
     
     public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
         super(stack, request, response);
@@ -120,6 +121,8 @@
             addParameter("beforeSelectTabNotifyTopics", findString(beforeSelectTabNotifyTopics));
         if (afterSelectTabNotifyTopics!= null)
             addParameter("afterSelectTabNotifyTopics", findString(afterSelectTabNotifyTopics));
+        if (disabledTabCssClass!= null)
+            addParameter("disabledTabCssClass", findString(disabledTabCssClass));
         
     }
 
@@ -175,15 +178,21 @@
 
 
     @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.")
+    		"The tab container widget will be passed as the first argument to the topic. The second parameter is the tab widget." +
+    		"The event can be cancelled setting to 'true' the 'cancel' property " +
+    		"of the third 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.")
+        "The tab container widget will be passed as the first argument to the topic. The second parameter is the tab widget.")
     public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) {
         this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics;
+    }
+
+    @StrutsTagAttribute(description="Css class to be applied to the tab button of disabled tabs", defaultValue="strutsDisabledTab")
+    public void setDisabledTabCssClass(String disabledTabCssClass) {
+        this.disabledTabCssClass = disabledTabCssClass;
     }
 }

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=535556&r1=535555&r2=535556
==============================================================================
--- 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 Sat May  5 11:45:02 2007
@@ -42,6 +42,7 @@
     private String templateCssPath;
     private String beforeSelectTabNotifyTopics;
     private String afterSelectTabNotifyTopics;
+    protected String disabledTabCssClass; 
     
     public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
         return new TabbedPanel(stack, req, res);
@@ -57,6 +58,7 @@
         tabbedPanel.setTemplateCssPath(templateCssPath);
         tabbedPanel.setBeforeSelectTabNotifyTopics(beforeSelectTabNotifyTopics);
         tabbedPanel.setAfterSelectTabNotifyTopics(afterSelectTabNotifyTopics);
+        tabbedPanel.setDisabledTabCssClass(disabledTabCssClass);
     }
 
     public void setSelectedTab(String selectedTab) {
@@ -81,5 +83,9 @@
 
     public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) {
         this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics;
+    }
+
+    public void setDisabledTabCssClass(String disabledTabCssClass) {
+        this.disabledTabCssClass = disabledTabCssClass;
     }
 }

Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/TabbedPanel.css
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/TabbedPanel.css?view=auto&rev=535556
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/TabbedPanel.css (added)
+++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/TabbedPanel.css Sat May  5 11:45:02 2007
@@ -0,0 +1,4 @@
+.strutsDisabledTab div span {
+    font-style: italic;
+    color: #7986A1
+}
\ No newline at end of file

Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js?view=diff&rev=535556&r1=535555&r2=535556
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js (original)
+++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js Sat May  5 11:45:02 2007
@@ -59,6 +59,9 @@
     highlightColor : "",
     highlightDuration : 2000,
     
+    //only used when inside a tabbedpanel
+    disabled : false,
+    
     onDownloadStart : function(event) {
       if(!this.showLoading) {
         event.returnValue = false;

Modified: 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=diff&rev=535556&r1=535555&r2=535556
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js (original)
+++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsTabContainer.js Sat May  5 11:45:02 2007
@@ -12,6 +12,8 @@
   beforeSelectTabNotifyTopics : "",
   beforeSelectTabNotifyTopicsArray : null,
 
+  disabledTabCssClass : "strutsDisabledTab",
+  
   postCreate : function() {
     struts.widget.StrutsTabContainer.superclass.postCreate.apply(this);
     
@@ -24,33 +26,71 @@
     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);
+    // add disabled class to disabled tabs
+    if(this.disabledTabCssClass) {
+      dojo.lang.forEach(this.children, function(div){
+        if(div.disabled) {
+          this.disableTab(div);
         }
-      });   
+      });
     }
-    
-    if(!cancel.cancel) {
-      struts.widget.StrutsTabContainer.superclass.selectChild.apply(this, [tab, callingWidget]);
+  },
+   
+  selectChild: function (tab, callingWidget)  {
+    if(!tab.disabled) {
+      var cancel = {"cancel" : false};
       
-      if(this.afterSelectTabNotifyTopicsArray) {
-        dojo.lang.forEach(this.afterSelectTabNotifyTopicsArray, function(topic) {
+      if(this.beforeSelectTabNotifyTopicsArray) {
+        var self = this;
+        dojo.lang.forEach(this.beforeSelectTabNotifyTopicsArray, function(topic) {
           try {
-            dojo.event.topic.publish(topic, tab, cancel);
+            dojo.event.topic.publish(topic, self, tab, cancel);
           } catch(ex){
             dojo.debug(ex);
           }
         });   
       }
-    }  
+      
+      if(!cancel.cancel) {
+        struts.widget.StrutsTabContainer.superclass.selectChild.apply(this, [tab, callingWidget]);
+        
+        if(this.afterSelectTabNotifyTopicsArray) {
+          var self = this;
+          dojo.lang.forEach(this.afterSelectTabNotifyTopicsArray, function(topic) {
+            try {
+              dojo.event.topic.publish(topic, self, tab, cancel);
+            } catch(ex){
+              dojo.debug(ex);
+            }
+          });   
+        }
+      } 
+    } 
+  },
+  
+  disableTab : function(t) {
+    var tabWidget = this.getTabWidget(t);
+    tabWidget.disabled = true;
+    dojo.html.addClass(tabWidget.controlButton.domNode, this.disabledTabCssClass);
+  },
+  
+  enableTab : function(t) {
+    var tabWidget = this.getTabWidget(t);
+    tabWidget.disabled = false;
+    dojo.html.removeClass(tabWidget.controlButton.domNode, this.disabledTabCssClass);
+  },
+  
+  getTabWidget : function(t) {
+    if(dojo.lang.isNumber(t)) {
+      //tab index
+      return this.children[t];
+    } else if(dojo.lang.isString(t)) {
+      //tab id
+      return dojo.widget.byId(t);
+    } else {
+      //tab widget?
+      return t;
+    }
   }
 });