You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by rb...@apache.org on 2011/08/21 02:16:36 UTC
svn commit: r1159925 - in /shindig/trunk:
content/samplecontainer/examples/conservcontainer/
features/src/main/javascript/features/actions/
features/src/test/javascript/features/actions/
Author: rbaxter85
Date: Sun Aug 21 00:16:35 2011
New Revision: 1159925
URL: http://svn.apache.org/viewvc?rev=1159925&view=rev
Log:
SHINDIG-1575
Committed For Matt Hatem
Align implementation of actions with the OpenSocial 2.0 spec.
Added:
shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-runner.xml
Modified:
shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js
shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html
shindig/trunk/features/src/main/javascript/features/actions/actions.js
shindig/trunk/features/src/main/javascript/features/actions/actions_container.js
shindig/trunk/features/src/main/javascript/features/actions/feature.xml
shindig/trunk/features/src/main/javascript/features/actions/taming.js
shindig/trunk/features/src/test/javascript/features/actions/actions_test.js
Modified: shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js (original)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js Sun Aug 21 00:16:35 2011
@@ -36,10 +36,10 @@ CommonContainer.init = new function() {
// Register our rendering functions with the action service
if (CommonContainer.actions) {
// Called when an action should be displayed in the container
- CommonContainer.actions.registerShowActionHandler(showAction);
+ CommonContainer.actions.registerShowActionsHandler(showActions);
// Called when a action should be removed from the container
- CommonContainer.actions.registerHideActionHandler(hideAction);
+ CommonContainer.actions.registerHideActionsHandler(hideActions);
// Called for actions contributed by pre-loaded gadgets (lazy load)
CommonContainer.actions.registerNavigateGadgetHandler(preRenderGadget);
@@ -86,7 +86,8 @@ osapi.people.getViewerFriends = function
};
// Function to display actions
-function showAction(itemObj) {
+function showActions(actions) {
+ var itemObj = actions[0];
if (!itemObj.path && !itemObj.dataType) {
// object is invalid!
return;
@@ -169,7 +170,8 @@ function addContainerAction(itemObj) {
}
// Function to hide actions
-function hideAction(itemObj) {
+function hideActions(actions) {
+ var itemObj = actions[0];
if (itemObj.path || itemObj.dataType) {
// remove the action from the specified data object type
if (itemObj.dataType && itemObj.dataType == 'opensocial.Person') {
@@ -194,3 +196,9 @@ function removeContainerAction(itemObj)
$('#globalMenubar').empty();
$('#globalMenubar').hide();
}
+
+// Runs the action specified in the action_id_field
+function runAction() {
+ id = document.getElementById('action_id_field').value;
+ CommonContainer.actions.runAction(id, CommonContainer.selection.getSelection());
+}
Modified: shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html (original)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html Sun Aug 21 00:16:35 2011
@@ -14,7 +14,8 @@
var urlBase = location.href.substr(0, location.href.indexOf('/samplecontainer/examples/conservcontainer/'));
var contextRoot = urlBase.substr(urlBase.indexOf(location.port) + location.port.length);
var base = 'http://' + window.location.host + '/'+ contextRoot + '/samplecontainer/examples/conservcontainer/';
- my.gadgetSpecUrls = [ base + 'sample-selection-listener.xml'];
+ my.gadgetSpecUrls = [ base + 'sample-selection-listener.xml',
+ base + 'sample-actions-runner.xml'];
my.renderGadgets = function() {
// uncomment this to render gadgets specified in my.gadgetSpecUrls
for (var i = 0; i < my.gadgetSpecUrls.length; ++i) {
@@ -170,16 +171,17 @@
batch.add('viewerFriendData', osapi.appdata.get({groupId:'@friends',keys:['count']}));
batch.execute(render);
}
-
gadgets.util.registerOnLoadHandler(initData);
</script>
-
+
</head>
-
+
<body onLoad="my.renderGadgets(); initData();">
- <div id="globalMenubar" width="100%"></div>
-
- <h2>Sample: Action+Selection Service</h2>
+ <div id="globalMenubar" width="100%">
+ <input type="text" id="action_id_field" value="org.samplevoip.chatwithperson"/>
+ <input type="button" value="Run Action" onclick="runAction()"/>
+ </div>
+ <h2>Sample: Action+Selection Service</h2>
<p>Press preload to preload the voip gadget. You will see actions appear that
have been contributed declaratively by the voip gadget. Select a person
object from the list and then select one of the actions. This will
Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-runner.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-runner.xml?rev=1159925&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-runner.xml (added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-runner.xml Sun Aug 21 00:16:35 2011
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<Module>
+<ModulePrefs title="Sample Action Runner"
+ height="250">
+<Require feature="actions"></Require>
+<Require feature="selection"></Require>
+</ModulePrefs>
+<Content type="html">
+<![CDATA[
+<script>
+var selection;
+gadgets.selection.addSelectionListener(
+ function(s){selection = s;}
+);
+
+function runAction() {
+ id = document.getElementById('action_id_field').value;
+ gadgets.actions.runAction(id, selection);
+}
+
+function showActions(actions) {
+ var a = document.createElement("a");
+ a.href="#";
+ a.onclick = function() {
+ gadgets.actions.runAction(actions[0].id);
+ };
+ var t = document.createTextNode(actions[0].label);
+ a.appendChild(t);
+ a.id = actions[0].id;
+ var m = document.getElementById("menu")
+ if (m.childNodes.length > 0) {
+ var s = document.createTextNode(" | ");
+ m.appendChild(s);
+ }
+ m.appendChild(a);
+}
+
+function hideActions(actions) {
+ var m = document.getElementById("menu");
+ while (m.childNodes.length > 0)
+ m.removeChild(m.childNodes[0]);
+}
+
+gadgets.actions.registerShowActionsListener(showActions);
+gadgets.actions.registerHideActionsListener(hideActions);
+
+</script>
+<div id="menu"></div>
+
+<div>
+<input type="text" id="action_id_field">
+<input type="button" value="Run Action" onclick="runAction()"/>
+</div>
+]]>
+</Content>
+</Module>
Modified: shindig/trunk/features/src/main/javascript/features/actions/actions.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/actions.js?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/actions/actions.js (original)
+++ shindig/trunk/features/src/main/javascript/features/actions/actions.js Sun Aug 21 00:16:35 2011
@@ -29,11 +29,11 @@ gadgets['actions'] = (function() {
* Example:
*
* <pre>
- * gadgets.actions.runAction(actionId);
+ * gadgets.actions.runAction(action);
* </pre>
*
- * @param {String}
- * actionId The action identifier.
+ * @param {Object}
+ * action The action object.
*
* @member gadgets.actions
*/
@@ -137,6 +137,23 @@ gadgets['actions'] = (function() {
},
/**
+ * Executes the action callback associated with the specified actionId
+ * in the context of the gadget which contributed that action. The
+ * gadget should call this method whenever an action is triggered by
+ * the user.
+ *
+ * @param {String, Object}
+ * actionId The id of the action to execute.
+ * opt_selection The current selection. This is optional.
+ *
+ * @member gadgets.actions
+ */
+ runAction: function(actionId, opt_selection) {
+ actionData = {"id" : actionId, "selection" : opt_selection};
+ gadgets.rpc.call('..', 'actions', null, 'runAction', actionData);
+ },
+
+ /**
* Removes the association of a callback function with an action id.
*
* Example:
@@ -207,6 +224,34 @@ gadgets['actions'] = (function() {
getActionsByDataType: function(dataType, callback) {
gadgets.rpc.call('..', 'actions', callback, 'getActionsByDataType',
dataType);
+ },
+
+ /**
+ * Registers a function to display actions in the gadget.
+ *
+ * @param {function}
+ * The gadget's function to render actions
+ * in its UI. The function takes the action object as
+ * a parameter.
+ */
+ registerShowActionsListener: function(listener) {
+ if (typeof listener === 'function') {
+ gadgets.rpc.call('..', 'actions', null, 'addShowActionListener', listener);
+ }
+ },
+
+ /**
+ * Registers a function to hide (remove) actions in the gadget
+ *
+ * @param {function}
+ * The gadget's function to hide (remove) actions
+ * in its UI. The function takes the action object as
+ * a parameter.
+ */
+ registerHideActionsListener: function(listener) {
+ if (typeof listener === 'function') {
+ gadgets.rpc.call('..', 'actions', null, 'addHideActionListener', listener);
+ }
}
};
})();
Modified: shindig/trunk/features/src/main/javascript/features/actions/actions_container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/actions_container.js?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/actions/actions_container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/actions/actions_container.js Sun Aug 21 00:16:35 2011
@@ -373,7 +373,7 @@
function addAction(actionObj, url) {
registry.addAction(actionObj, url);
// notify the container to display the action
- showActionHandler(actionObj);
+ showActionHandlerProxy([actionObj]);
};
/**
@@ -388,7 +388,7 @@
var actionObj = registry.getItemById(id);
registry.removeAction(id);
// notify the container to hide the action
- hideActionHandler(actionObj);
+ hideActionHandlerProxy([actionObj]);
};
/**
@@ -515,18 +515,26 @@
// Function to handle RPC calls from the gadgets side
function router(channel, object) {
- var actionObj = object;
switch (channel) {
case 'bindAction':
- bindAction(actionObj);
+ bindAction(object);
+ break;
+ case 'runAction':
+ container_.actions.runAction(object.id, object.selection);
break;
case 'removeAction':
- hideActionHandler(object);
+ hideActionHandlerProxy([object]);
break;
case 'getActionsByPath':
return container_.actions.getActionsByPath(object);
case 'getActionsByDataType':
return container_.actions.getActionsByDataType(object);
+ case 'addShowActionListener':
+ addShowActionListener(object);
+ break;
+ case 'addHideActionListener':
+ addHideActionListener(object);
+ break;
}
};
@@ -537,7 +545,21 @@
* actionObj The object with id, label, tooltip, icon and any other
* information for the container to use to render the action.
*/
- var showActionHandler = function(actionObj) {};
+ var showActionHandler = function(actions) {};
+ var showActionListeners = [];
+ var showActionHandlerProxy = function(actions) {
+ showActionHandler(actions);
+ for (var i in showActionListeners)
+ showActionListeners[i](actions);
+ };
+
+ /**
+ * Function that adds a listener to the list of listeners that will
+ * be notified of show action events.
+ */
+ function addShowActionListener(listener) {
+ showActionListeners.push(listener);
+ };
/**
* Function that hides actions from the container's UI
@@ -546,7 +568,21 @@
* actionObj The object with id, label, tooltip, icon and any other
* information for the container to use to render the action.
*/
- var hideActionHandler = function(actionObj) {};
+ var hideActionHandler = function(actions) {};
+ var hideActionListeners = [];
+ var hideActionHandlerProxy = function(actions) {
+ hideActionHandler(actions);
+ for (var i in hideActionListeners)
+ hideActionListeners[i](actions);
+ };
+
+ /**
+ * Function that adds a listener to the list of listeners that will
+ * be notified of hide action events.
+ */
+ function addHideActionListener(listener) {
+ hideActionListeners.push(listener);
+ };
/**
* Function that renders gadgets in container's UI
@@ -589,7 +625,7 @@
* in its UI. The function takes the action object as
* a parameter.
*/
- registerShowActionHandler: function(handler) {
+ registerShowActionsHandler: function(handler) {
if (typeof handler === 'function') {
showActionHandler = handler;
}
@@ -603,7 +639,7 @@
* in its UI. The function takes the action object as
* a parameter.
*/
- registerHideActionHandler: function(handler) {
+ registerHideActionsHandler: function(handler) {
if (typeof handler === 'function') {
hideActionHandler = handler;
}
@@ -632,10 +668,11 @@
/**
* Executes the action associated with the action id.
*
- * @param {String}
- * The action id.
+ * @param {String, Object}
+ * The id of the action to execute..
+ * The current selection. This is an optional parameter.
*/
- runAction: function(actionId) {
+ runAction: function(actionId, opt_selection) {
var action = registry.getItemById(actionId);
if (action) {
// if gadget site has not been registered yet
@@ -646,6 +683,13 @@
pendingActions[actionId] = {
selection: container_.selection.getSelection()
};
+
+ // set selection
+ if (opt_selection != null) {
+ pendingActions[actionId].selection = opt_selection;
+ }
+
+ // set optional params
var opt_params = {};
if (action.view) {
opt_params[osapi.container.actions.OptParam.VIEW] = action.view;
@@ -653,9 +697,11 @@
if (action.viewTarget) {
opt_params[osapi.container.actions.OptParam.VIEW_TARGET] = action.viewTarget;
}
+
+ // render the gadget
renderGadgetInContainer(gadgetUrl, opt_params);
} else {
- runAction(actionId);
+ runAction(actionId, opt_selection);
}
}
},
Modified: shindig/trunk/features/src/main/javascript/features/actions/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/feature.xml?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/actions/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/actions/feature.xml Sun Aug 21 00:16:35 2011
@@ -10,8 +10,11 @@
<exports type="js">gadgets.actions.addAction</exports>
<exports type="js">gadgets.actions.updateAction</exports>
<exports type="js">gadgets.actions.removeAction</exports>
+ <exports type="js">gadgets.actions.runAction</exports>
<exports type="js">gadgets.actions.getActionsByPath</exports>
<exports type="js">gadgets.actions.getActionsByDataType</exports>
+ <exports type="js">gadgets.actions.registerShowActionsListener</exports>
+ <exports type="js">gadgets.actions.registerHideActionsListener</exports>
<exports type="js">osapi.container.actions.OptParam.VIEW</exports>
<exports type="js">osapi.container.actions.OptParam.VIEW_TARGET</exports>
</api>
Modified: shindig/trunk/features/src/main/javascript/features/actions/taming.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/taming.js?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/actions/taming.js (original)
+++ shindig/trunk/features/src/main/javascript/features/actions/taming.js Sun Aug 21 00:16:35 2011
@@ -3,6 +3,9 @@ tamings___.push(function(imports) {
___.grantRead(gadgets.actions, 'addAction');
___.grantRead(gadgets.actions, 'updateAction');
___.grantRead(gadgets.actions, 'removeAction');
+ ___.grantRead(gadgets.actions, 'runAction');
___.grantRead(gadgets.actions, 'getActionsByPath');
___.grantRead(gadgets.actions, 'getActionsByDataType');
+ ___.grantRead(gadgets.actions, 'registerShowActionsListener');
+ ___.grantRead(gadgets.actions, 'registerHideActionsListener');
});
Modified: shindig/trunk/features/src/test/javascript/features/actions/actions_test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/actions/actions_test.js?rev=1159925&r1=1159924&r2=1159925&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/actions/actions_test.js (original)
+++ shindig/trunk/features/src/test/javascript/features/actions/actions_test.js Sun Aug 21 00:16:35 2011
@@ -68,10 +68,18 @@ DeclarativeActionsTest.prototype.testGad
DeclarativeActionsTest.prototype.testGadgetsRemoveAction = function() {
var actionId = "testAction";
gadgets.actions.removeAction(actionId);
- this.assertRpcCalled('..', 'actions', null,
+ this.assertRpcCalled('..', 'actions', null,
'removeAction', actionId);
};
+DeclarativeActionsTest.prototype.testGadgetsRunAction = function() {
+ var actionId = "testAction";
+ var opt_selection = "testSelection";
+ gadgets.actions.runAction(actionId, opt_selection);
+ this.assertRpcCalled('..', 'actions', null,
+ 'runAction', {"id":actionId, "selection":opt_selection});
+};
+
DeclarativeActionsTest.prototype.testContainerGetAction = function() {
var container = new osapi.container.Container({});