Author: julien_viet
Date: 2010-01-20 11:37:29 -0500 (Wed, 20 Jan 2010)
New Revision: 1393
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/gadget/Gadget.java
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/ExoBasedUserPrefStore.js
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
Log:
GTNPORTAL-511 : userPref of gadgets are not sometime not saved correctly
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/gadget/Gadget.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/gadget/Gadget.java 2010-01-20
13:02:09 UTC (rev 1392)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/gadget/Gadget.java 2010-01-20
16:37:29 UTC (rev 1393)
@@ -20,7 +20,11 @@
package org.exoplatform.portal.pom.spi.gadget;
import org.gatein.mop.api.content.ContentType;
+import org.json.JSONException;
+import org.json.JSONObject;
+import java.util.Iterator;
+
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -43,4 +47,20 @@
{
this.userPref = userPref;
}
+
+ public void addUserPref(String addedUserPref) throws JSONException
+ {
+ JSONObject jsonUserPref = new JSONObject(userPref != null ? userPref :
"{}");
+
+ // Update the user Preferences with the new value. Replace the old ones if they
exist.
+ JSONObject addedJSONUserPref = new JSONObject(addedUserPref);
+ for (Iterator<String> i = addedJSONUserPref.keys();i.hasNext();)
+ {
+ String key = i.next();
+ jsonUserPref.put(key, addedJSONUserPref.get(key));
+ }
+
+ //
+ userPref = jsonUserPref.toString();
+ }
}
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 2010-01-20
13:02:09 UTC (rev 1392)
+++
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/ExoBasedUserPrefStore.js 2010-01-20
16:37:29 UTC (rev 1393)
@@ -28,9 +28,9 @@
return gadget.userPrefs_;
};
-gadgets.ExoBasedUserPrefStore.prototype.savePrefs = function(gadget) {
+gadgets.ExoBasedUserPrefStore.prototype.savePrefs = function(gadget, newPrefs) {
//TODO: dang.tung - sent event to portal
- var prefs = eXo.core.JSON.stringify(gadget.userPrefs_) ;
+ var prefs = eXo.core.JSON.stringify(newPrefs || gadget.userPrefs_);
var DOMUtil = eXo.core.DOMUtil;
var gadget = document.getElementById("gadget_" + gadget.id) ;
if(gadget != null ) {
Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js
===================================================================
---
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js 2010-01-20
13:02:09 UTC (rev 1392)
+++
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js 2010-01-20
16:37:29 UTC (rev 1393)
@@ -218,11 +218,11 @@
value) {
var id = gadgets.container.gadgetService.getGadgetIdFromModuleId(this.f);
var gadget = gadgets.container.getGadget(id);
- var prefs = gadget.getUserPrefs();
+ var new_prefs = {};
for (var i = 1, j = arguments.length; i < j; i += 2) {
- prefs[arguments[i]] = arguments[i + 1];
+ new_prefs[arguments[i]] = arguments[i + 1];
}
- gadget.setUserPrefs(prefs);
+ gadget.setUserPrefs(new_prefs);
};
/**
@@ -416,9 +416,11 @@
return this.userPrefs_;
};
-gadgets.Gadget.prototype.setUserPrefs = function(userPrefs) {
- this.userPrefs_ = userPrefs;
- gadgets.container.userPrefStore.savePrefs(this);
+gadgets.Gadget.prototype.setUserPrefs = function(newUserPrefs) {
+ for (var pref in newUserPrefs) {
+ this.userPrefs_[pref] = newUserPrefs[pref];
+ }
+ gadgets.container.userPrefStore.savePrefs(this, newUserPrefs);
};
gadgets.Gadget.prototype.getUserPref = function(name) {
@@ -427,7 +429,9 @@
gadgets.Gadget.prototype.setUserPref = function(name, value) {
this.userPrefs_[name] = value;
- gadgets.container.userPrefStore.savePrefs(this);
+ var newPref = {};
+ newPref[name] = value;
+ gadgets.container.userPrefStore.savePrefs(this, newPref);
};
gadgets.Gadget.prototype.render = function(chrome) {
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2010-01-20
13:02:09 UTC (rev 1392)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2010-01-20
16:37:29 UTC (rev 1393)
@@ -37,6 +37,7 @@
import org.json.JSONException;
import org.json.JSONObject;
+import java.util.Iterator;
import java.util.Random;
import java.util.UUID;
@@ -374,7 +375,6 @@
* Gets user preference of gadget application
*
* @return the string represents user preference of gadget application
- * @throws Exception
* @throws Exception when can't convert object to string
*/
public String getUserPref() throws Exception
@@ -384,21 +384,36 @@
return pp != null ? pp.getUserPref() : null;
}
+ public void addUserPref(String addedUserPref) throws Exception
+ {
+ DataStorage service = getApplicationComponent(DataStorage.class);
+ org.exoplatform.portal.pom.spi.gadget.Gadget gadget = service.load(state,
ApplicationType.GADGET);
+ if (gadget == null)
+ {
+ gadget = new org.exoplatform.portal.pom.spi.gadget.Gadget();
+ }
+
+ //
+ gadget.addUserPref(addedUserPref);
+
+ //
+ state = service.save(state, gadget);
+ }
+
/**
* Initializes a newly created <code>SaveUserPrefActionListener</code>
* object
- *
- * @throws Exception if can't initialize object
*/
static public class SaveUserPrefActionListener extends EventListener<UIGadget>
{
public void execute(Event<UIGadget> event) throws Exception
{
- String userPref =
event.getRequestContext().getRequestParameter("userPref");
- org.exoplatform.portal.pom.spi.gadget.Gadget gadget = new
org.exoplatform.portal.pom.spi.gadget.Gadget();
- gadget.setUserPref(userPref);
+ UIGadget uiGadget = event.getSource();
- UIGadget uiGadget = event.getSource();
+ //
+
uiGadget.addUserPref(event.getRequestContext().getRequestParameter("userPref"));
+
+ //
if (uiGadget.isLossData())
{
/*
@@ -409,8 +424,8 @@
*/
return;
}
- DataStorage service = uiGadget.getApplicationComponent(DataStorage.class);
- uiGadget.state = service.save(uiGadget.state, gadget);
+
+ //
event.getRequestContext().setResponseComplete(true);
}
}
Show replies by date