Author: mfranklin
Date: Sat Sep 14 01:01:31 2013
New Revision: 1523169

URL: http://svn.apache.org/r1523169
Log:
Added container actions for widget title bar (RAVE-1056

Modified:
    rave/trunk/rave-demo-gadgets/src/main/webapp/actions_contributions.xml
    rave/trunk/rave-portal-resources/src/main/webapp/static/css/rave-css.less
    
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_action_manager.js
    
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_opensocial.js
    
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js

Modified: rave/trunk/rave-demo-gadgets/src/main/webapp/actions_contributions.xml
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-demo-gadgets/src/main/webapp/actions_contributions.xml?rev=1523169&r1=1523168&r2=1523169&view=diff
==============================================================================
--- rave/trunk/rave-demo-gadgets/src/main/webapp/actions_contributions.xml 
(original)
+++ rave/trunk/rave-demo-gadgets/src/main/webapp/actions_contributions.xml Sat 
Sep 14 01:01:31 2013
@@ -32,12 +32,13 @@
           <script 
src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
           <script type="text/x-handlebars-template" id="template">
             {{#each_entry this}}
-                <h3>{{key}}</h3>
+                <h4>{{key}}</h4>
                 <ul>
                 {{#each 
value}}<li><b>{{id}}:</b><span>{{description}}</span></li>{{/each}}
                 </ul>
             {{/each_entry}}
           </script>
+          <h3>Actions by Path</h3>
           <div id="render"></div>
           <script>
               Handlebars.registerHelper("each_entry", function(obj, options) {
@@ -61,8 +62,8 @@
                     tooltip: "This is a warning",
                     label: "Take Warning",
                     icon: "css:icon-warning-sign",
-                    callback: actionCallback,
-                    path: "/gadget/toolbar",
+                    callback: function() { actionCallback("warning"); },
+                    path: "gadget/toolbar",
                     moduleId: moduleId,
                     description: "Toolbar action as an image that when clicked 
fires the action"
                 };
@@ -74,8 +75,8 @@
                     tooltip: "This is a folder open",
                     label: "Open File",
                     icon: "css:icon-folder-open",
-                    callback: actionCallback,
-                    path: "/gadget/toolbar",
+                    callback: function() { actionCallback("open file"); },
+                    path: "gadget/toolbar",
                     moduleId: moduleId,
                     description: "Toolbar action as an image that when clicked 
fires the action"
                 };

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/css/rave-css.less
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/css/rave-css.less?rev=1523169&r1=1523168&r2=1523169&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/static/css/rave-css.less 
(original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/static/css/rave-css.less 
Sat Sep 14 01:01:31 2013
@@ -669,6 +669,10 @@ ul.storeItems .widgetCategories {
   cursor: pointer;
 }
 
+.widget-titlebar-action {
+  margin-right: 5px;
+}
+
 /* form fields */
 fieldset {
   margin: 0;

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_action_manager.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_action_manager.js?rev=1523169&r1=1523168&r2=1523169&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_action_manager.js
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_action_manager.js
 Sat Sep 14 01:01:31 2013
@@ -34,18 +34,21 @@ define(['underscore'], function(_){
      * @param path {string} path to the action /gadget/toolbar, /gadget/menu, 
/container/menu, etc
      * @param widgetId {string} the id of the widget contributing the action
      * @param fnAction function to call when the action is selected
+     * @param tooltip
+     * @param image the image to display, either a relative path, URL or css 
class name in format of css:<css_type>:<className> eg. class:boostrap:icon-fun
+     * @param label the label of the action
+     * @param id unique ID of the action
      */
-    exports.createAction = function(path, widgetId, fnAction) {
-        _.invoke(actionHandlers, 'create', [path, widgetId, fnAction]);
+    exports.createAction = function(id, label, path, widgetId, image, tooltip, 
fnAction) {
+        _.invoke(actionHandlers, 'create', id, label, path, widgetId, image, 
tooltip, fnAction);
     }
 
     /**
      * Removes an action by calling all actionHandlers remove function
-     * @param {string} path to the action /gadget/toolbar, /gadget/menu, 
/container/menu, etc
-     * @param widgetId {string} the id of the widget contributing the action
+     * @param {string} id Unique identifier of the action
      */
-    exports.removeAction = function(path, widgetId) {
-        _.invoke(actionHandlers, 'remove', [path, widgetId]);
+    exports.removeAction = function(id) {
+        _.invoke(actionHandlers, 'remove', id);
     }
 
     /**

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_opensocial.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_opensocial.js?rev=1523169&r1=1523168&r2=1523169&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_opensocial.js
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/core/rave_opensocial.js
 Sat Sep 14 01:01:31 2013
@@ -28,7 +28,8 @@
  */
 define(['underscore', 'core/rave_view_manager', 'core/rave_api', 
'core/rave_openajax_hub', 'core/rave_log', 'core/rave_state_manager', 
'core/rave_action_manager', 'osapi'],
     function (_, viewManager, api, managedHub, log, stateManager, 
actionManager) {
-        var exports = {};
+        //Due to the shindig bug in container actions, we have to keep a map 
of sites by widgetId
+        var exports = {}, siteByWidgetId = {};
 
         var container;
 
@@ -117,15 +118,20 @@ define(['underscore', 'core/rave_view_ma
         function implementActions() {
             container.actions.registerShowActionsHandler(function(actions) {
                 _.each(actions, function(action){
-                    actionManager.createAction(action.path, action.moduleId, 
function() {
-                        container.actions.runAction(action.id);
+                    //TODO: There is a bug in the shindig code where the 
action is assumed to launch a new gadget.  This works around the issue
+                    actionManager.createAction(action.id, action.label, 
action.path, action.moduleId, action.icon, action.tooltip, function() {
+                        var site = siteByWidgetId[action.moduleId];
+                        var holder = site.getActiveSiteHolder();
+                        if (holder) {
+                            gadgets.rpc.call(holder.getIframeId(), 
'actions.runAction', null, action.id, null);
+                        }
                     })
                 })
             });
 
             container.actions.registerHideActionsHandler(function (actions){
                 _.each(actions, function(action){
-                    actionManager.removeAction(action.path, action.moduleId);
+                    actionManager.removeAction(action.id);
                 })
             });
         }
@@ -214,6 +220,7 @@ define(['underscore', 'core/rave_view_ma
             site._widget = widget;
             site.moduleId_ = widget.regionWidgetId;
             widget._site = site;
+            siteByWidgetId[widget.regionWidgetId] = site;
 
             var renderParams = {};
             renderParams[osapi.container.RenderParam.VIEW] = opts.view || 
stateManager.getDefaultView();

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js?rev=1523169&r1=1523168&r2=1523169&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js
 Sat Sep 14 01:01:31 2013
@@ -958,6 +958,48 @@ define(["jquery", "underscore", "rave",
             });
         }
 
+        function getActionElement(label, image, tooltip) {
+            var elem;
+            if(image) {
+                if(image.indexOf("css") === 0) {
+                    elem = '<i class="' + image.replace("css:","") + '" ></i>';
+                } else {
+                    elem = '<img src="' + image + '" />';
+                }
+            } else {
+                elem = "<a>" + label + "</a>";
+            }
+            return $(elem).attr("tooltip", tooltip);
+        }
+
+        function insertWidgetToolbarAction(widgetId, label, image, tooltip, 
id, onSelected) {
+            var $toolbar = $("#widget-" + widgetId + "-wrapper 
.widget-title-bar");
+            var $action = $('<div class="widget-titlebar-action 
widget-toolbar" ></div>').append(getActionElement(label, image, tooltip));
+            $action.attr("id", id).on('click', onSelected);
+            $toolbar.append($action);
+            return $action;
+        }
+
+        function registerActionsHandler() {
+            var actions = {};
+            rave.registerActionHandler({
+                create: function(id, label, path, widgetId, image, tooltip, 
onSelected) {
+                    if(!actions[id]) {
+                        var segments = path.split("/");
+                        //TODO Implement more paths and a better path routing 
system
+                        if (segments.length === 2 && segments[0] === "gadget" 
&& segments[1] === "toolbar") {
+                            actions[id] = insertWidgetToolbarAction(widgetId, 
label, image, tooltip, id, onSelected);
+                        } else {
+                            rave.log("Unsupported action path: '" + path + "'")
+                        }
+                    }
+                },
+                remove: function(id) {
+                    if(actions[id]) actions[id].remove();
+                }
+            });
+        }
+
         function init() {
             initializePageSharing();
             registerPreferencesView();
@@ -966,6 +1008,7 @@ define(["jquery", "underscore", "rave",
             registerPopups();
             showEmptyDisplay();
             setupDragAndDrop();
+            registerActionsHandler();
         }
 
         rave.registerOnInitHandler(init);


Reply via email to