You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ca...@apache.org on 2011/07/28 18:14:42 UTC
svn commit: r1151908 - in /incubator/rave/trunk/rave-portal/src:
main/webapp/script/rave_api.js main/webapp/script/rave_opensocial.js
test/javascript/raveApiSpec.js
Author: carlucci
Date: Thu Jul 28 16:14:41 2011
New Revision: 1151908
URL: http://svn.apache.org/viewvc?rev=1151908&view=rev
Log:
RAVE-113: Implement container side support for set_pref gadgets.rpc call. OpenSocial Gadgets can now use the Prefs.set() and Prefs.setArray() functions to persist preferences from within the gadget code. This was a sub task of RAVE-27: implement user prefs
https://issues.apache.org/jira/browse/RAVE-113
Modified:
incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js
incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js
Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js?rev=1151908&r1=1151907&r2=1151908&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js Thu Jul 28 16:14:41 2011
@@ -50,9 +50,26 @@ rave.api = rave.api || (function() {
error: handleError
});
}
+
+ function saveWidgetPreference(args) {
+ $.ajax({
+ type: 'PUT',
+ url: rave.getContext() + path + "regionWidgets/" + args.regionWidgetId + "/preferences/" + args.userPref.prefName,
+ data: JSON.stringify({"name":args.userPref.prefName, "value": args.userPref.prefValue}),
+ contentType: 'application/json',
+ dataType: 'json',
+ success: function(result) {
+ if (typeof args.successCallback == 'function') {
+ args.successCallback();
+ }
+ },
+ error: handleError
+ });
+ }
return {
- saveWidgetPreferences : saveWidgetPreferences
+ saveWidgetPreferences : saveWidgetPreferences,
+ saveWidgetPreference : saveWidgetPreference
};
})();
Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js?rev=1151908&r1=1151907&r2=1151908&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_opensocial.js Thu Jul 28 16:14:41 2011
@@ -69,7 +69,7 @@ rave.opensocial = rave.opensocial || (fu
container.rpcRegister('resize_iframe', resizeIframe);
container.rpcRegister('set_title', setTitle);
container.rpcRegister('requestNavigateTo', requestNavigateTo);
- //container.rpcRegister('set_pref', null);
+ container.rpcRegister('set_pref', setPref);
//container.rpcRegister('pubsub', null);
}
@@ -205,6 +205,23 @@ rave.opensocial = rave.opensocial || (fu
}
}
+
+ /**
+ * Saves a userPref for the widget
+ *
+ * @param args RPC event args
+ * @param editToken this is an old deprecated parameter but still needs to be in the signature for proper binding
+ * @param prefName the userpref name
+ * @param prefValue the userpref value
+ */
+ function setPref(args, editToken, prefName, prefValue) {
+ var widgetId = rave.getObjectIdFromDomId(args.gs.getActiveGadgetHolder().getElement().id);
+ var regionWidget = rave.getWidgetById(widgetId);
+ // update the memory prefs object
+ regionWidget.userPrefs[prefName] = prefValue;
+ // persist it to database
+ rave.api.rest.saveWidgetPreference({regionWidgetId: widgetId, userPref: {prefName: prefName, prefValue: prefValue}});
+ }
/**
* Re-renders the gadget in the requested view with the parameters
@@ -223,7 +240,7 @@ rave.opensocial = rave.opensocial || (fu
function isArray(o) {
return Object.prototype.toString.call(o) == "[object Array]";
}
-
+
/**
* Exposed public API calls
*/
Modified: incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js?rev=1151908&r1=1151907&r2=1151908&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js (original)
+++ incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js Thu Jul 28 16:14:41 2011
@@ -61,6 +61,33 @@ describe("Rave API", function() {
expect(callbackCalled).toBeTruthy();
});
});
+
+ describe("saveWidgetPreference", function() {
+ it("PUTs correct values to the REST service for saving one widget preference", function() {
+ $.ajax = function(args) {
+ expect(args.url).toEqual("api/rest/regionWidgets/1/preferences/firstname");
+ var userPref = JSON.parse(args.data);
+ expect(userPref.name).toEqual("firstname");
+ expect(userPref.value).toEqual("Tony");
+
+ expect(typeof(callback)).toEqual("function");
+ callback({error:false});
+ return {
+ error: function(a, b, c) {
+ }
+ }
+ };
+
+ var callbackCalled = false;
+ var callback = function() {
+ callbackCalled = true
+ };
+
+ rave.api.rest.saveWidgetPreference({regionWidgetId: 1, userPref: {prefName: "firstname", prefValue: "Tony"},
+ successCallback: callback});
+ expect(callbackCalled).toBeTruthy();
+ });
+ });
});
describe("rpc", function() {