shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wood...@apache.org
Subject svn commit: r1146852 - in /shindig/trunk/content/samplecontainer/examples/conservcontainer: ./ ConServContainer.js index.html layout.js portlet.css sample-actions-voip.xml sample-selection-listener.xml viewController.js
Date Thu, 14 Jul 2011 19:07:39 GMT
Author: woodser
Date: Thu Jul 14 19:07:38 2011
New Revision: 1146852

URL: http://svn.apache.org/viewvc?rev=1146852&view=rev
Log:
Applying demo container for Actions+Selection: http://codereview.appspot.com/4645056/

Added:
    shindig/trunk/content/samplecontainer/examples/conservcontainer/
    shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js
    shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html
    shindig/trunk/content/samplecontainer/examples/conservcontainer/layout.js
    shindig/trunk/content/samplecontainer/examples/conservcontainer/portlet.css
    shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-voip.xml
    shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-selection-listener.xml
    shindig/trunk/content/samplecontainer/examples/conservcontainer/viewController.js

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js (added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/ConServContainer.js Thu
Jul 14 19:07:38 2011
@@ -0,0 +1,191 @@
+// Create the common container object.
+var CommonContainer = new osapi.container.Container({});
+
+// Wrapper function to set the gadget site/id and default width.
+CommonContainer.renderGadget = function(gadgetURL, gadgetId) {
+  // going to hardcode these values for width.
+  var el = document.getElementById("gadget-site-" + gadgetId);
+  var parms = {};
+  parms[osapi.container.RenderParam.WIDTH] = "100%";
+  var gadgetSite = CommonContainer.newGadgetSite(el);
+  CommonContainer.navigateGadget(gadgetSite, gadgetURL, {}, parms);
+  return gadgetSite;
+};
+
+// Function for pre-rendering gadgets.  Gadget pre-rendering
+// occurs when an action contributed by a pre-loaded gadget 
+// is executed.
+function preRenderGadget(gadgetUrl, opt_metadata) {
+  var gadgetId = getGadgetId(gadgetUrl);
+  var el = $("#gadget-site-" + gadgetId);
+  var gadgetSite = CommonContainer.renderGadget(gadgetUrl, gadgetId);
+  el.data("gadgetSite", gadgetSite);
+  return gadgetSite;
+};
+
+// Common container init function.
+CommonContainer.init = new function(){  
+  // Map needed for lazy loading of gadgets
+  urlsToGadgetIdMap = {};
+  
+  // 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);
+    
+    // Called when a action should be removed from the container
+    CommonContainer.actions.registerHideActionHandler(hideAction);
+    
+    // Called for actions contributed by pre-loaded gadgets (lazy load)
+    CommonContainer.actions.registerNavigateGadgetHandler(preRenderGadget);
+  }
+};
+
+// Support for lazy loading gadgets
+function getGadgetId(url) {
+  if (urlsToGadgetIdMap) {
+    return urlsToGadgetIdMap[url];
+  }
+}
+
+// Wrapper function to add gadgets to the page.
+CommonContainer.addGadgetToPage = function(gadgetURL, lazyLoad) {
+  addGadget(gadgetURL, lazyLoad);
+};
+
+// Wrapper function to expand a gadget
+CommonContainer.navigateView = function(gadgetSite, gadgetURL, view) {
+  var renderParms = {};
+  if (view === null || view === "") {
+    view = "default";
+  }
+  renderParms[osapi.container.RenderParam.WIDTH] = "100%";
+  renderParms['view'] = view;
+  CommonContainer.navigateGadget(gadgetSite, gadgetURL, {}, renderParms);
+};
+
+// see peoplehelpers.js
+osapi.people.getViewer = function(options) {
+  options = options || {};
+  options.userId = '@viewer';
+  options.groupId = '@self';
+  return osapi.people.get(options);
+};
+
+// see peoplehelpers.js
+osapi.people.getViewerFriends = function(options) {
+  options = options || {};
+  options.userId = '@viewer';
+  options.groupId = '@friends';
+  return osapi.people.get(options);
+};
+
+// Function to display actions 
+function showAction(itemObj) {  
+  if (!itemObj.path && !itemObj.dataType) {
+    // object is invalid!
+    return;
+  }
+  // bind the action to the specified data object type
+  if (itemObj.dataType) {
+    if (itemObj.dataType == "opensocial.Person") {
+      addPersonAction(itemObj);
+    }
+  }
+  // bind the action to the specified path (container UI elements)
+  if (itemObj.path && itemObj.path.length > 0) {
+    addContainerAction(itemObj);
+  }
+};
+
+// Adds the specified action to a person element.
+function addPersonAction(itemObj) {
+  // select all person elements
+  var personActionDiv = $(".personActions");
+  
+  // create a link and append it to each person element
+  var actionStr = '';
+  if (itemObj.icon && itemObj.icon.length > 0) {
+    actionStr += '<img src="'+itemObj.icon+'"/>';
+  }
+  actionStr += '<a name="person-action-'+itemObj.id+'" title="'+
+               itemObj.tooltip+'" href="#">'+itemObj.label+'</a>';
+  actionStr = '<span class="'+itemObj.id+'">'+actionStr+'</span>';
+  var actionLink = $(actionStr);
+  
+  // add a separator if needed
+  if (personActionDiv.children().length > 0) {
+    personActionDiv.append(" | ");
+  }  
+  
+  // select all links that were added and set the click handler
+  personActionDiv.append(actionLink);
+  $('a[name="person-action-'+itemObj.id+'"]').each(function(i) {
+    $(this).click(function() {
+      CommonContainer.actions.runAction(itemObj.id);
+    });
+  }); 
+};
+
+// Adds an action to the container UI
+function addContainerAction(itemObj) {
+  var pathParts = itemObj.path.split("/");
+  var pathType = pathParts.shift();
+  var pathScope = pathParts.shift();
+  var remainingPath = pathParts.join("/");
+  var contributionBar;
+  
+  // right now we support contributing to the global menubar
+  if (pathType == "container" && pathScope == "navigationLinks") {
+    contributionBar = $('#globalMenubar');
+    contributionBar.show();
+  }
+  
+  // create the action element
+  var actionStr = '';
+  if (itemObj.icon && itemObj.icon.length > 0) {
+    actionStr += '<img src="'+itemObj.icon+'"/>';
+  }
+  actionStr += '<a title="'+itemObj.tooltip+'" href="#">'
+               +itemObj.label+'</a>';
+  actionStr = '<span class="'+itemObj.id+'">'+actionStr+'</span>';
+  var actionLink = $(actionStr);
+  
+  // add a separator if needed
+  if (contributionBar.children().length > 0) {
+    contributionBar.append(" | ");
+  }
+  
+  // add the new action
+  contributionBar.append(actionLink);    
+  actionLink.click(function(){
+    CommonContainer.actions.runAction(itemObj.id);
+  });
+};
+
+// Function to hide actions 
+function hideAction(itemObj) {  
+  if (itemObj.path || itemObj.dataType) {
+    // remove the action from the specified data object type
+    if (itemObj.dataType && itemObj.dataType == "opensocial.Person") {
+      removePersonAction(itemObj);
+    }
+    // remove the action to the specified path (container UI elements)
+    if (itemObj.path && itemObj.path.length > 0) {
+      removeContainerAction(itemObj);
+    }
+  }
+};
+
+// Removes the specified action from a person element.
+function removePersonAction(itemObj) {
+  // hack - actions should be removed individually
+  $(".personActions").empty();
+};
+
+// Removes the specified action from the container UI
+function removeContainerAction(itemObj) {
+  // hack - actions should be removed individually
+  $('#globalMenubar').empty();
+  $('#globalMenubar').hide();
+};

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html (added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/index.html Thu Jul 14
19:07:38 2011
@@ -0,0 +1,199 @@
+<html>
+	<head>
+		<link rel="stylesheet" href="/container/gadgets.css">
+		<link rel="stylesheet" href="portlet.css">
+		<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
rel="stylesheet" type="text/css"/>
+		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
+  		<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
+		<script type="text/javascript" src="/gadgets/js/core:container:rpc:selection:actions.js?c=1&debug=1&container=default"></script>

+		<script type="text/javascript" src="ConServContainer.js"></script>
+		<script type="text/javascript" src="viewController.js"></script>
+		<script type="text/javascript" src="layout.js"></script>
+		<script type="text/javascript">
+			var my = {};
+			var base = 'http://' + window.location.host + '/samplecontainer/examples/conservcontainer/';
+			my.gadgetSpecUrls = [ base + 'sample-selection-listener.xml'];
+			my.renderGadgets = function() {
+				  // uncomment this to render gadgets specified in my.gadgetSpecUrls
+				  for (var i = 0; i < my.gadgetSpecUrls.length; ++i) {
+				    //var gadgetSite = CommonContainer.renderGadget(my.gadgetSpecUrls[i], "gadget-chrome-"+i);
+				    CommonContainer.addGadgetToPage(my.gadgetSpecUrls[i]);
+				  }
+			};
+			function onPreloadGadget() {
+				var gadgetSpecUrl = $(".gadgetUrl")[0].value;
+				CommonContainer.addGadgetToPage(gadgetSpecUrl, true);
+			}
+			function onAddGadget() {
+				var gadgetSpecUrl = $(".gadgetUrl")[0].value;
+				CommonContainer.addGadgetToPage(gadgetSpecUrl, false);
+			}
+			function log(message) {
+			  document.getElementById("output").innerHTML += gadgets.util.escapeString(message) +
"<br/>";
+			}
+			function setSelection(selection) {
+			  CommonContainer.selection.setSelection(selection);
+			}
+		</script>
+		
+		<style type="text/css">
+		     #helloworlds {
+		       margin: 20px;
+		       font-family: arial, sans-serif;
+		       width: 310px;
+		     }
+		     div.person img {
+		       margin-bottom: 10px;
+		     }
+		     div.bubble {
+		       background-image: url(/samplecontainer/examples/bubble.gif);
+		       background-repeat: no-repeat;
+		       width: 202px;
+		       height: 66px;
+		       padding: 12px 0px 0px 12px;
+		       font-weight: bold;
+		       font-size: 18px;
+		       float: right;
+		     }
+		     .c0 { color: #008000; }
+		     .c1 { color: #FF8A00; }
+		     .c2 { color: #7777CC; }
+		     .c3 { color: #008000; }
+		     .c4 { color: #CC0000; }
+		     .c5 { color: #73A6FF; }
+		     div.name, div.personAction {
+		       width: 150px;
+		       text-align: right;
+		       font-weight: normal;
+		       font-size: 12px;
+		       color: #999;
+		       position:relative;
+		       top: 10px;
+		       right: -35px;
+		       margin: 5px;
+		     }
+		     #globalMenubar {
+				font-family: Arial;
+				color: #666666;
+				text-align: right;
+				padding: 10px;
+			}
+		     
+	    </style>
+	
+	    <script type="text/javascript">
+		     var hellos = new Array('Hello World', 'Hallo Welt', 'Ciao a tutti', 'Hola mundo',
+		       '&#1055;&#1086;&#1103;&#1074;&#1083;&#1077;&#1085;&#1080;&#1077;
&#1085;&#1072; &#1089;&#1074;&#1077;&#1090;', 
+		       '&#12371;&#12435;&#12395;&#12385;&#12399;&#19990;&#30028;',

+		       '&#20320;&#22909;&#19990;&#30028;', 
+		       '&#50668;&#47084;&#48516;, &#50504;&#45397;&#54616;&#49464;&#50836;');
+		     var numberOfStyles = 6;
+		     var viewerCount;
+		     var allPeople, viewerFriendData;
+		     var selected_id = null;
+		     
+		     function highlight(id) {
+		     	if (selected_id == id) return;
+		     	element = document.getElementById("person_"+id);
+				element.style.background = "#73A6FF";
+		     }
+		     
+		     function unhighlight(id) {
+		     	if (selected_id == id) return;
+		     	element = document.getElementById("person_"+id);
+				element.style.background = "#FFF";
+		     }
+		     
+		     function select(id) {
+		     	if (selected_id != null) {
+		     		unselect = selected_id;
+		     		selected_id = null;
+		     		unhighlight(unselect);
+		     	}
+		     	selected_id = id;
+		     	element = document.getElementById("person_"+id);
+				element.style.background = "#CCC";
+				
+				// set selection
+				setSelection(allPeople[id]);
+		     }
+		     
+		     function render(data) {
+		       var viewer = data.viewer;
+		       allPeople = data.viewerFriends.list;
+		       if (viewer) {
+		         allPeople.push(viewer);
+		       }
+		
+		       var viewerData = data.viewerData;
+		       viewerCount = getCount(viewerData[viewer.id]);
+		
+		       viewerFriendData = data.viewerFriendData;
+		       viewerFriendData[viewer.id] = viewerData[viewer.id];
+		
+		       var html = '';
+		       for (var i = 0; i < allPeople.length; i++) {
+		         var count = getCount(viewerFriendData[allPeople[i].id]);
+		         if (count == 0) {
+		           //continue;
+		         }
+		         html += '<div class="personActions"></div>';
+		         html += '<div id="person_'+i+'" ';
+		         html += 'class="person" onMouseDown="select('+i+');" onMouseOver="highlight('+i+');"
onMouseOut="unhighlight('+i+');">';
+		         html += '<div id="bubble_'+i+'" class="bubble c' + count % numberOfStyles +
'">';
+		         html += hellos[count % hellos.length];
+		         html += '<div class="name">' + allPeople[i].name.formatted + ' (' + count
+ ') ' + allPeople[i].gender;
+		         html += '</div></div>';
+		
+		         if (allPeople[i].thumbnailUrl
+		             && allPeople[i].thumbnailUrl.indexOf('null') == -1) {
+		           html += '<img src="' + allPeople[i].thumbnailUrl + '"/>';
+		         } else {
+		           html += '<img src="/samplecontainer/examples/nophoto.gif"/>';
+		         }
+		         html += '<br style="clear:both"></div>';
+		       }
+		       document.getElementById('helloworlds').innerHTML = html;
+		     }
+		
+		     function getCount(data) {
+		       return data && data['count'] ? Number(data['count']) : 0;
+		     }
+		
+		     function initData() {
+		       var fields = ['id','age','name','gender','profileUrl','thumbnailUrl'];
+		       var batch = osapi.newBatch();
+		       batch.add('viewer', osapi.people.getViewer({sortBy:'name',fields:fields}));
+		       batch.add('viewerFriends', osapi.people.getViewerFriends({sortBy:'name',fields:fields}));
+		       batch.add('viewerData', osapi.appdata.get({keys:['count']}));
+		       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>	  		
+		<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 
+		   render the voip gadget and execute the selected action.  Finally, you can
+		   close the gadget by pressing the 'x' icon and the action will be removed.
+		   You can also use the Sample Selection Listener gadget to view the contents
+		   of the currently selected object.
+		<div id="helloworlds" style="margin: 4px; float: left;">
+		</div>
+		<div style="font-family:Arial">
+		Preload Gadget: <input type="text" class="gadgetUrl" value="http://localhost:8080/samplecontainer/examples/conservcontainer/sample-actions-voip.xml"
/>
+	  	<input type="submit" value="Preload" onclick="onPreloadGadget();"/>
+		<input type="submit" value="Add" onclick="onAddGadget();"/>
+		</div>
+	  	<div id="gadgetArea" class="column" style="float: left;"> 
+	  	</div>
+	</body>
+</html>
\ No newline at end of file

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/layout.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/layout.js?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/layout.js (added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/layout.js Thu Jul 14 19:07:38
2011
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+//  Setup the base container objects for managing layout, gadget, and container configuration
+$(function() {
+  // TODO: enable drag and drop with the portlet at some point
+  $(".column").sortable({
+    connectWith : '.column',
+    update : function(event, ui) {
+      // TODO: There is an issue with drag & drop
+    }
+  });
+
+  $(".portlet").addClass(
+      "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all").find(
+      ".portlet-header").addClass("ui-widget-header ui-corner-all").prepend(
+      '<span class="ui-icon ui-icon-minusthick"></span>').end().find(
+      ".portlet-content");
+  $(".portlet-header .ui-icon").click(function() {
+    $(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
+    $(this).parents(".portlet:first").find(".portlet-content").toggle();
+  });
+
+  $(".column").disableSelection();
+});

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/portlet.css
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/portlet.css?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/portlet.css (added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/portlet.css Thu Jul 14
19:07:38 2011
@@ -0,0 +1,32 @@
+.portlet {
+	width: 500px;
+}
+.portlet-header .ui-icon { 
+ 	float: right; 
+ }
+ 
+ #viewsDropdown, #viewsDropdown ul { 
+   list-style: none; margin: 10px;
+ }
+ #viewsDropdown, #viewsdropdown * {
+   padding: 0; margin: 0; 
+ }
+
+ #viewsDropdown li.li-header {
+   float: right; margin-left: -1px;
+ }
+ #viewsDropdown li.li-header a { 
+   display: block; font-size: small;
+ }
+
+ #viewsDropdown li.li-header ul { 
+   display: none; border: 1px black solid; text-align: left; 
+ }
+ 
+ #viewsDropdown li.li-header:hover ul { 
+   display: block; 
+ }
+
+ #viewsDropdown li.li-header ul li a { 
+   padding: 5px; height: 17px; font-size: small;
+ }
\ No newline at end of file

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-voip.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-voip.xml?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-voip.xml
(added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-actions-voip.xml
Thu Jul 14 19:07:38 2011
@@ -0,0 +1,83 @@
+<?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="VOIP Gadget"
+             height="250">
+<Require feature="selection"/>
+<Optional feature="actions">
+<Param name="action-contributions"><![CDATA[<actions>
+<action id="org.samplevoip.chatwithperson" dataType="opensocial.Person" 
+      		label="Chat" tooltip="Chat" view="DialByPerson" />
+<action id="org.samplevoip.callbyperson" dataType="opensocial.Person" 
+      		label="Call" tooltip="Call" view="DialByPerson" />
+<action id="org.samplevoip.navLink" path="container/navigationLinks" label="Call Person"
tooltip="Dial a Number"/>
+</actions>]]></Param>
+</Optional>
+</ModulePrefs>
+<Content type="html">
+<![CDATA[
+<script>
+var chat = function(selectedObj) {
+	var msgStr = 'Starting Chat';
+	if (selectedObj) {
+		msgStr += ' with '+ selectedObj["name"]["formatted"];
+	}
+	msgStr += "...";
+	
+	document.getElementById("output").innerHTML = msgStr;
+};
+var call = function(selectedObj) {
+	var msgStr = 'Dialing number';
+	if (selectedObj) {
+		msgStr += ' for '+ selectedObj["name"]["formatted"];
+	}
+	msgStr += "...";
+	
+	document.getElementById("output").innerHTML =msgStr;
+};
+if (gadgets.actions) {		
+	// add actions   
+    var chatAction = {
+    	id: "org.samplevoip.chatwithperson",
+    	callback: chat
+    };
+    gadgets.actions.updateAction(chatAction);
+	    
+    var callAction = {
+    	id: "org.samplevoip.callbyperson",
+    	callback: call
+    };
+    gadgets.actions.updateAction(callAction);
+	    
+    var callNavLinkAction = {
+    	id: "org.samplevoip.navLink",
+    	callback: call
+    };
+    gadgets.actions.updateAction(callNavLinkAction);
+}
+</script>
+<div>
+VOIP Status:
+</div>
+<div id="output">
+</div>
+]]>
+</Content>
+</Module>

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-selection-listener.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-selection-listener.xml?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-selection-listener.xml
(added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/sample-selection-listener.xml
Thu Jul 14 19:07:38 2011
@@ -0,0 +1,53 @@
+<?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 Selection Listener"
+             height="250">
+<Require feature="selection"></Require>
+</ModulePrefs>
+<Content type="html">
+<![CDATA[
+<script>
+
+function selectionListener(selection) {
+  document.getElementById("output").innerHTML =
+    "selection: " + gadgets.util.escapeString(JSON.stringify(selection) + "") + "<br/>";
+}
+
+function addSelectionListener() {
+  gadgets.selection.addSelectionListener(selectionListener);
+  document.getElementById("output").innerHTML = "Selection listener added...";
+}
+
+function removeSelectionListener() {
+  gadgets.selection.removeSelectionListener(selectionListener);
+  document.getElementById("output").innerHTML = "";
+}
+
+</script>
+<div>
+<input type="button" value="Add Selection Listener" onclick="addSelectionListener()"/>
+<input type="button" value="Remove Selection Listener" onclick="removeSelectionListener()"/>
+</div>
+<div id="output">
+</div>
+]]>
+</Content>
+</Module>

Added: shindig/trunk/content/samplecontainer/examples/conservcontainer/viewController.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/conservcontainer/viewController.js?rev=1146852&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/conservcontainer/viewController.js (added)
+++ shindig/trunk/content/samplecontainer/examples/conservcontainer/viewController.js Thu
Jul 14 19:07:38 2011
@@ -0,0 +1,101 @@
+$(function() {
+  
+  // Base html template that is used for the gadget wrapper and site
+  var gadgetTemplate ='<div class="portlet">' +
+                '<div class="portlet-header" id="portlet-id">' +
+                'sample to replace</div>' +
+                '<div id="gadget-site" class="portlet-content"></div>' +
+                '</div>';
+  
+  // Variable to keep track of gadget current view 
+  // for collapse and expand gadget actions.
+  var currentView="default";
+  
+  // ID used to associate gadget site
+  var curId = 0;
+  
+  // Navigate to the new view and save it as current view
+  navigateView = function(gadgetSite, gadgetURL, toView){
+    // Save the current view for collapse, expand gadget
+    currentView = toView;
+    CommonContainer.navigateView(gadgetSite,gadgetURL,toView); 
+  };
+    
+  // Handle gadget collapse, expand, and remove gadget actions
+  handleNavigateAction = function(portlet, gadgetSite, gadgetURL, actionId) {
+    // Remove button was click, remove the portlet/gadget
+    if (actionId === "remove") {
+      if (confirm('This gadget will be removed, ok?')) {
+        if (gadgetSite) {
+          CommonContainer.closeGadget(gadgetSite);
+        }
+        if (gadgetURL) {
+          CommonContainer.unloadGadget(gadgetURL);
+          urlsToGadgetIdMap[gadgetURL] = null;
+        }
+        portlet.remove();
+      }
+    } else if (actionId === "expand") {
+      // Navigate to currentView prior to collapse gadget
+      if (gadgetSite) {
+        CommonContainer.navigateView(gadgetSite, gadgetURL, currentView);
+      }
+      else {
+        preRenderGadget(gadgetURL);
+      }
+    } else if (actionId === "collapse") {
+      CommonContainer.closeGadget(gadgetSite);
+    }
+  };
+    
+  // Create a gadget with navigation tool bar header 
+  // enabling gadget collapse, expand and remove.
+  buildGadget = function(result,gadgetURL,lazyload) {
+    var gadgetSiteString="$(this).closest(\'.portlet\')." + 
+      "find(\'.portlet-content\').data(\'gadgetSite\')";  
+    var newGadgetSite = gadgetTemplate;
+    newGadgetSite = newGadgetSite.replace(/(portlet-id)/g,'$1-'+ curId);
+    newGadgetSite = newGadgetSite.replace(/(gadget-site)/g,'$1-'+ curId);
+    var gadgetSiteData = null;
+    $(newGadgetSite).appendTo($( '#gadgetArea' )).addClass(
+        "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
+        .find(".portlet-header")
+        .addClass("ui-widget-header ui-corner-all")
+        .text(result[gadgetURL]['modulePrefs'].title)
+    .append('<span id="remove" class="ui-icon ui-icon-closethick"></span>') 
       
+    .append('<span id="expand" class="ui-icon ui-icon-plusthick"></span>')
+    .append('<span id="collapse" class="ui-icon ui-icon-minusthick"></span>')
+    .end()
+      .find(".portlet-content")
+      .data("gadgetSite", lazyload ? null :
+        CommonContainer.renderGadget(gadgetURL, curId));
+     
+    // determine which button was clicked and handle the appropriate event.
+    $("#portlet-id-"+curId+" > .ui-icon").click(
+        function() {
+          handleNavigateAction(
+              $(this).closest('.portlet'), 
+              $(this).closest('.portlet').find(".portlet-content")
+                .data("gadgetSite"),
+              gadgetURL,this.id);
+        }
+    ); 
+   
+    var gadgetId = urlsToGadgetIdMap[gadgetURL];
+    if (!gadgetId) {
+      urlsToGadgetIdMap[gadgetURL] = curId;
+    }
+  };
+      
+  // Add single gadget 
+  addGadget=function(gadgetUrl, lazyload) {
+    CommonContainer.preloadGadget(gadgetUrl, function(result){    
+      for (var gadgetURL in result) {
+       buildGadget(result,gadgetURL, lazyload);
+       curId++;
+      }
+    });
+    return true; 
+  };
+  
+});
\ No newline at end of file



Mime
View raw message