[gatein-commits] gatein SVN: r7737 - in portal/trunk: web/eXoResources/src/main/webapp/javascript/eXo/gadget and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 12 22:39:05 EDT 2011


Author: kien_nguyen
Date: 2011-10-12 22:39:04 -0400 (Wed, 12 Oct 2011)
New Revision: 7737

Modified:
   portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
   portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/ExoBasedUserPrefStore.js
Log:
GTNPORTAL-2110 Gadget Wrapper portlets default horoscope gadget doesnt work propertly

Modified: portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
===================================================================
--- portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java	2011-10-12 16:53:52 UTC (rev 7736)
+++ portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java	2011-10-13 02:39:04 UTC (rev 7737)
@@ -26,14 +26,18 @@
 import org.exoplatform.container.ExoContainerContext;
 import org.exoplatform.portal.webui.application.GadgetUtil;
 import org.exoplatform.portal.webui.application.UIGadget;
+import org.exoplatform.portal.webui.util.Util;
 import org.exoplatform.web.application.ApplicationMessage;
 import org.exoplatform.webui.application.WebuiApplication;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.application.portlet.PortletRequestContext;
 import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.config.annotation.EventConfig;
 import org.exoplatform.webui.core.UIApplication;
 import org.exoplatform.webui.core.UIPortletApplication;
 import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
+import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.EventListener;
 import org.gatein.common.logging.Logger;
 import org.gatein.common.logging.LoggerFactory;
 import org.json.JSONArray;
@@ -49,7 +53,8 @@
  *          tungcnw at gmail.com
  * June 27, 2008
  */
- at ComponentConfig(lifecycle = UIApplicationLifecycle.class, template = "app:/groovy/gadget/webui/component/UIGadgetPortlet.gtmpl")
+ at ComponentConfig(lifecycle = UIApplicationLifecycle.class, template = "app:/groovy/gadget/webui/component/UIGadgetPortlet.gtmpl", events = {
+   @EventConfig(listeners = UIGadgetPortlet.SaveUserPrefActionListener.class)})
 public class UIGadgetPortlet extends UIPortletApplication
 {
    final static public String LOCAL_STRING = "local://";
@@ -68,36 +73,12 @@
    {
       return userPref;
    }
-
-   @Override
-   public void processAction(WebuiRequestContext context) throws Exception
+   
+   public void setUserPref(String pref)
    {
-      super.processAction(context);
-
-      //
-      PortletRequest req = context.getRequest();
-
-      //
-      userPref = req.getParameter("userPref");
-      if (userPref != null && !userPref.isEmpty())
-      {
-         PortletPreferences prefs = req.getPreferences();
-         prefs.setValue("userPref", userPref);
-         prefs.store();
-      }
+      this.userPref = pref;
    }
 
-   @Override
-   public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception
-   {
-      PortletRequest req = context.getRequest();
-      PortletPreferences prefs = req.getPreferences();
-      userPref = prefs.getValue("userPref", null);
-
-      //
-      super.processRender(app, context);
-   }
-
    public String getUrl()
    {
       PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
@@ -162,4 +143,23 @@
       }
       return metadata_.toString();
    }
+   
+   static public class SaveUserPrefActionListener extends EventListener<UIGadgetPortlet>
+   {
+      public void execute(Event<UIGadgetPortlet> event) throws Exception
+      {
+         PortletRequest req = event.getRequestContext().getRequest();
+         String userPref = req.getParameter("userPref");
+         if (userPref != null && !userPref.isEmpty())
+         {
+            PortletPreferences prefs = req.getPreferences();
+            prefs.setValue("userPref", userPref);
+            prefs.store();
+            
+            UIGadgetPortlet gadgetPortlet = (UIGadgetPortlet) event.getSource();
+            gadgetPortlet.setUserPref(userPref);
+         }
+         Util.getPortalRequestContext().setResponseComplete(true);
+      }
+   }
 }

Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/ExoBasedUserPrefStore.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/ExoBasedUserPrefStore.js	2011-10-12 16:53:52 UTC (rev 7736)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/ExoBasedUserPrefStore.js	2011-10-13 02:39:04 UTC (rev 7737)
@@ -17,7 +17,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 gadgets.ExoBasedUserPrefStore = function() {
   gadgets.UserPrefStore.call(this);
 };
@@ -35,12 +34,16 @@
   var DOMUtil = eXo.core.DOMUtil;
 	var gadget = document.getElementById("gadget_" + gadget.id) ;
 	if(gadget != null ) {
+		var uicomponent = gadget.parentNode.id.replace(/^content-/,"");
 		var portletFragment = DOMUtil.findAncestorByClass(gadget, "PORTLET-FRAGMENT");
-		var uiGadget = gadget.parentNode;
+		var gadgetPortlet = DOMUtil.findAncestorByClass(gadget, "UIGadgetPortlet");
+		if(gadgetPortlet != null) {
+			uicomponent = gadgetPortlet.id;
+		}
 		if (portletFragment != null) {
 			var compId = portletFragment.parentNode.id;
 			var href = eXo.env.server.portalBaseURL + "?portal:componentId=" + compId;
-			href += "&portal:type=action&uicomponent=" + uiGadget.id.replace(/^content-/,"");
+			href += "&portal:type=action&uicomponent=" + uicomponent;
 			href += "&op=SaveUserPref";
 			href += "&ajaxRequest=true";
 			href += "&userPref=" + prefs;
@@ -49,11 +52,9 @@
 			var params = [
 			 {name : "userPref", value : prefs}
 			] ;
-			ajaxGet(eXo.env.server.createPortalURL(uiGadget.id.replace(/^content-/,""), "SaveUserPref", true, params),true) ;
+			ajaxGet(eXo.env.server.createPortalURL(uicomponent, "SaveUserPref", true, params),true) ;
 		}
 	}
 };
 
-gadgets.Container.prototype.userPrefStore =
-    new gadgets.ExoBasedUserPrefStore();
-//}
\ No newline at end of file
+gadgets.Container.prototype.userPrefStore = new gadgets.ExoBasedUserPrefStore();
\ No newline at end of file



More information about the gatein-commits mailing list