Author: hnguy
Date: Wed Jan 19 17:05:59 2011
New Revision: 1060867
URL: http://svn.apache.org/viewvc?rev=1060867&view=rev
Log:
SHINDIG-1490 | Added gadget views and few other features to the common test
container | patch from Han Nguyen
Added:
shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
shindig/trunk/content/samplecontainer/examples/commoncontainer/pubsub2.json
shindig/trunk/content/samplecontainer/examples/commoncontainer/sample-views.xml
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewsMenu.json
Removed:
shindig/trunk/content/samplecontainer/examples/commoncontainer/testContainer.js
shindig/trunk/content/samplecontainer/examples/commoncontainer/testGadgets.js
Modified:
shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
shindig/trunk/content/samplecontainer/examples/commoncontainer/layout.js
Added:
shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js?rev=1060867&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
(added)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
Wed Jan 19 17:05:59 2011
@@ -0,0 +1,114 @@
+/*
+ * 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.
+*/
+
+var testConfig = testConfig || {};
+testConfig[shindig.container.ServiceConfig.API_PATH] = '/rpc';
+testConfig[shindig.container.ContainerConfig.RENDER_DEBUG] = "1";
+
+//Default the security token for testing.
+shindig.auth.updateSecurityToken('john.doe:john.doe:appid:cont:url:0:default');
+
+
+// Create the new CommonContainer
+var CommonContainer = new shindig.container.Container(testConfig);
+
+// Need to pull these from values supplied in the dialog
+CommonContainer.init = function() {
+ //Create my new managed hub
+ CommonContainer.managedHub = new OpenAjax.hub.ManagedHub(
+ {
+ onSubscribe: function(topic, container) {
+ log(container.getClientID() + " subscribes to this topic '" + topic +
"'");
+ return true;
+ // return false to reject the request.
+ },
+ onUnsubscribe: function(topic, container) {
+ log(container.getClientID() + " unsubscribes from tthis topic '" +
topic + "'");
+ return true;
+ },
+ onPublish: function(topic, data, pcont, scont) {
+ log(pcont.getClientID() + " publishes '" + data + "' to topic '" +
topic + "' subscribed by " + scont.getClientID());
+ return true;
+ // return false to reject the request.
+ }
+});
+ // initialize managed hub for the Container
+ gadgets.pubsub2router.init(
+ {
+ hub: CommonContainer.managedHub
+ });
+
+ try {
+
+ // Connect to the ManagedHub
+ CommonContainer.inlineClient = new
OpenAjax.hub.InlineContainer(CommonContainer.managedHub, "container",
+ {
+ Container: {
+ onSecurityAlert: function(source, alertType) {
/* Handle client-side security alerts */ },
+ onConnect: function(container){ /* Called
when client connects */ },
+ onDisconnect: function(container){ /*
Called when client connects */ }
+ }
+ }
+ );
+ //connect to the inline client
+ CommonContainer.inlineClient.connect();
+
+
+ } catch(e) {
+ // TODO: error handling should be consistent with other OS gadget
initialization error handling
+ alert("ERROR creating or connecting InlineClient in
CommonContainer.managedHub [" + e.message + "]");
+ }
+
+};
+
+//Wrapper function to set the gadget site/id and default width. Currently
have some inconsistency with width actually being set. This
+//seems to be related to the pubsub2 feature.
+CommonContainer.renderGadget = function(gadgetURL, gadgetId) {
+ //going to hardcode these values for width.
+ var el = document.getElementById("gadget-site-" + gadgetId);
+ var parms ={};
+ parms[shindig.container.RenderParam.WIDTH]="100%";
+ var gadgetSite = CommonContainer.newGadgetSite(el);
+ CommonContainer.navigateGadget(gadgetSite, gadgetURL, {}, parms);
+ return gadgetSite;
+
+};
+//TODO: To be implemented. Identify where to hook this into the page (in the
gadget title bar/gadget management, etc)
+CommonContainer.navigateView = function(gadgetSite, gadgetURL, view) {
+ var renderParms ={};
+ if(view===null || view===""){
+ view="default";
+ }
+ //TODO Evaluate Parms based on configuration
+ renderParms[shindig.container.RenderParam.WIDTH]="100%";
+ renderParms['view']=view;
+
+ CommonContainer.navigateGadget(gadgetSite, gadgetURL, {}, renderParms);
+};
+
+//TODO: Add in UI controls in portlet header to remove gadget from the canvas
+CommonContainer.colapseGadget = function(gadgetSite) {
+ CommonContainer.closeGadget(gadgetSite);
+};
+
+//display the pubsub 2 event details
+function log(message) {
+ document.getElementById("output").innerHTML =
gadgets.util.escapeString(message) + "<br/>" +
document.getElementById("output").innerHTML;
+};
+
Modified:
shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html?rev=1060867&r1=1060866&r2=1060867&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
(original)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
Wed Jan 19 17:05:59 2011
@@ -20,42 +20,68 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
-<!-- My OpenSocial Beginnings -->
-<link rel="stylesheet" href="/container/gadgets.css">
-<script type="text/javascript"
-
src="/gadgets/js/container:rpc:pubsub-2.js?c=1&debug=1&container=default""></script>
-<script
-
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
-<script
-
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
-<link rel="stylesheet"
-
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/cupertino/jquery-ui.css"
- type="text/css" media="all" />
-<script type="text/javascript" src="./testContainer.js"></script>
-<script type="text/javascript" src="./testGadgets.js"></script>
-<script type="text/javascript" src="./layout.js"></script>
-
-<style>
-#content {
- display: table;
- width: 100%;
-}
-
-#testArea {
- display: table-cell;
- width: 75%;
- padding-left:22px;
-}
-
-#controlPanel {
- display: table-cell;
- width: 25%;
-}
-
-</style>
+ <!-- My OpenSocial Beginnings -->
+ <link rel="stylesheet" href="/container/gadgets.css">
+ <script type="text/javascript"
+
src="/gadgets/js/container:rpc:pubsub-2.js?c=1&debug=1&container=default""></script>
+ <script
+
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
+ <script
+
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
+ <link rel="stylesheet"
+
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/cupertino/jquery-ui.css"
+ type="text/css" media="all" />
+ <script type="text/javascript" src="./assembler.js"></script>
+ <script type="text/javascript" src="./viewController.js"></script>
+ <script type="text/javascript" src="./layout.js"></script>
+
+ <style>
+ .portlet-header .ui-icon { float: right; }
+ #content {
+ display: table;
+ width: 100%;
+ }
+
+ #testArea {
+ display: table-cell;
+ width: 75%;
+ padding-left:22px;
+ }
+
+ #controlPanel {
+ display: table-cell;
+ width: 25%;
+ }
+
+ #viewsDropdown, #viewsDropdown ul {
+ list-style: none;
+ }
+ #viewsDropdown, #viewsdropdown * {
+ padding: 0; margin: 0;
+ }
+
+ #viewsDropdown li.li-header {
+ float: right; margin-left: -1px;
+ }
+ #viewsDropdown li.li-header a {
+ display: block;
+ }
+
+ #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;
+ }
+
+ </style>
</head>
-
<body onLoad="CommonContainer.init();">
<!-- Need to add in an improved header with links to specification -->
<a href="http://www.opensocial.org/"><img alt="OpenSocial"
src="http://api.ning.com/files/chwE7fbkJ5D1q8NSzNCYJzzCqOiuo3xYyToZCsYuY0SViOKQ7EG-3UUv4KFSxOMACbIzs3oWtD076*cbEL-*ABd9hCO0p7Al/opensocialsitelogo1.png?width=288&height=70&xn_auth=no&type=png"></a><div
id="content">
@@ -86,6 +112,18 @@ Pick from one of the collections and sel
<select id="gadgetCollection"> </select> <button id="addGadgets">Add
Gadgets</button>
</div>
+<h3><a href="#">Container Events</a></h3>
+<div>
+Enter the event topic (ex. org.opensocial.container.event.sampleevent)
+<br/>
+<input type="text"name="eventTopic" id="eventTopic" class="text
ui-widget-content ui-corner-all" />
+<br/>
+Enter the event payload
+<br/>
+<textarea type="text"name="eventPayload" id="eventPayload" class="text
ui-widget-content ui-corner-all" > </textarea>
+<br/>
+<button id="pubEvent">Publish</button>
+</div>
</div>
<span class="ui-icon ui-icon-grip-dotted-horizontal"
style="margin: 2px auto;"></span>
Modified:
shindig/trunk/content/samplecontainer/examples/commoncontainer/layout.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/layout.js?rev=1060867&r1=1060866&r2=1060867&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/layout.js
(original)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/layout.js
Wed Jan 19 17:05:59 2011
@@ -34,7 +34,6 @@ $(function() {
.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();
Added:
shindig/trunk/content/samplecontainer/examples/commoncontainer/pubsub2.json
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/pubsub2.json?rev=1060867&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/pubsub2.json
(added)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/pubsub2.json
Wed Jan 19 17:05:59 2011
@@ -0,0 +1,8 @@
+{ "Events":
+ [
+ {"topic": "org.opensocial.event.social.person.selected", "value": "12345"},
+ {"topic": "org.opensocial.event.social.person.updtaed", "value": "12345"},
+ {"topic": "org.opensocial.event.container.ee.render", "value":
"someContext"},
+ {"topic": "org.opensocial.event.container.itemSelected", "value":
"ItemSelected"}
+ ]
+}
\ No newline at end of file
Added:
shindig/trunk/content/samplecontainer/examples/commoncontainer/sample-views.xml
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/sample-views.xml?rev=1060867&view=auto
==============================================================================
---
shindig/trunk/content/samplecontainer/examples/commoncontainer/sample-views.xml
(added)
+++
shindig/trunk/content/samplecontainer/examples/commoncontainer/sample-views.xml
Wed Jan 19 17:05:59 2011
@@ -0,0 +1,36 @@
+<?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 Views"
+ height="250">
+ <Require feature="views" />
+ </ModulePrefs>
+ <Content type="html" view="home,default">
+ <![CDATA[
+ <h1>Home view</h1>
+ ]]>
+ </Content>
+ <Content type="html" view="canvas">
+ <![CDATA[
+ <h1>Canvas view</h1>
+ ]]>
+ </Content>
+
+</Module>
Added:
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js?rev=1060867&view=auto
==============================================================================
---
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
(added)
+++
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
Wed Jan 19 17:05:59 2011
@@ -0,0 +1,152 @@
+$(function() {
+
+ // Input field that contains gadget urls added by the user manually
+ var newGadgetUrl= $( "#gadgetUrl" );
+
+ // Input fields for container event testing
+ var newEventTopic = $( "#eventTopic" );
+ var newEventPayload = $( "#eventPayload" );
+
+ // Base html template that is used for the gadget wrapper and site
+ var gadgetTemplate ='<div class="portlet">' +
+ '<div
class="portlet-header">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;
+
+ // Load the defaultl collections stored and update the options with
the collection name
+ $.ajax({
+ url: './gadgetCollections.json',
+ dataType: 'json',
+ success: function(data) {
+ $.each(data.collections, function(i,data){
+ var optionVal = [];
+ $.each(data.apps, function(i,data){
+ optionVal.push(data.url);
+ });
+ $('#gadgetCollection').append('<option value="'+
optionVal.toString() + '">' + data.name +'</option>');
+ });
+ }
+ });
+
+ $.ajax({
+ url: './viewsMenu.json',
+ dataType: 'json',
+ success: function(data) {
+ $.each(data.views, function(i,selection){
+ $('#viewOptions').append('<option value="'+
selection.value + '">' + selection.name +'</option>');
+ });
+ }
+ });
+
+ //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?')) {
+ portlet.remove();
+ }
+ }else if (actionId==="expand" ){
+ //navigate to currentView prior to colapse gadget
+
CommonContainer.navigateView(gadgetSite,gadgetURL,currentView);
+ }else if (actionId==="collapse"){
+ CommonContainer.colapseGadget(gadgetSite);
+ }
+ };
+
+ //create a gadget with navigation tool bar header enabling gadget
collapse, expand, remove, navigate to view actions.
+ buildGadget=function(result,gadgetURL){
+ var
gadgetSiteString="$(this).closest(\'.portlet\').find(\'.portlet-content\').data(\'gadgetSite\')";
+ var viewItems = "";
+ var gadgetViews = result[gadgetURL].views;
+ for(var aView in gadgetViews){
+ viewItems = viewItems+'<li><a href="#"
onclick="navigateView('+gadgetSiteString+','+'\''+gadgetURL+'\''+','+'\''+aView+'\''+');
return false;">'+aView+'</a></li>';
+ }
+ var newGadgetSite = gadgetTemplate;
+ newGadgetSite = newGadgetSite.replace(/(gadget-site)/g,'$1-'+ curId);
+ $(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('<ul id="viewsDropdown">'+
+ '<li class="li-header">'+
+ '<a href="#" class="hidden"><span
id="dropdownIcon" class="ui-icon ui-icon-triangle-1-s"></span></a>'+
+ '<ul>'+
+ viewItems +
+ '</ul>'+
+ '</li>'+
+ '</ul>')
+ .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", CommonContainer.renderGadget(gadgetURL, curId));
+
+ //determine which button was click and handle the appropriate
event.
+ $(".portlet-header .ui-icon").click(function(){
+
handleNavigateAction($(this).closest('.portlet'),$(this).closest('.portlet').find(".portlet-content").data("gadgetSite"),gadgetURL,this.id);
+ });
+ };
+
+ // Publish the container event
+ $( "#pubEvent" ).click(function() {
+ CommonContainer.inlineClient.publish(newEventTopic.val(),
newEventPayload.val());
+
+ //TODO: Need to add in some additional logic in the Container
to enable point to point for things like Embedded Experience...
+
+ //var ppcont =
CommonContainer.managedHub.getContainer("__gadget_1");
+ //CommonContainer.managedHub.publishForClient(ppcont,
newEventTopic.val(), newEventPayload.val());
+ //ppcont.sendToClient('org.apache.shindig.random-number',
'1111', ppcont.getClientID());
+ //clear values
+ newEventTopic.val( "" );
+ newEventPayload.val( "" );
+ return true;
+ });
+
+ // Load single gadgets entered by user
+ $( "#addGadget" ).click(function() {
+ CommonContainer.preloadGadget(newGadgetUrl.val(),
function(result){
+ for (var gadgetURL in result) {
+ buildGadget(result,gadgetURL);
+ curId++;
+ }
+
+ //Clear Values
+ newGadgetUrl.val( "" );
+ });
+
+ return true;
+ });
+
+ // Load the select collection of gadgets and render them the gadget
test area
+ $( "#addGadgets" ).click(function() {
+
+ //TODO: This just provides and example to load configurations
+ //var
testGadgets=["http://localhost:8080/container/sample-pubsub-2-publisher.xml","http://localhost:8080/container/sample-pubsub-2-subscriber.xml"];
+ var testGadgets = $('#gadgetCollection').val().split(",");
+ CommonContainer.preloadGadgets(testGadgets, function(result){
+ for (var gadgetURL in result) {
+ buildGadget(result,gadgetURL);
+ curId++;
+ }
+
+ });
+ return true;
+
+ });
+
+
+});
\ No newline at end of file
Added:
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewsMenu.json
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/viewsMenu.json?rev=1060867&view=auto
==============================================================================
---
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewsMenu.json
(added)
+++
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewsMenu.json
Wed Jan 19 17:05:59 2011
@@ -0,0 +1,7 @@
+{ "views":
+ [
+ {"name": "home", "value": "home", "height": "400px", "width": "450px"},
+ {"name": "canvas", "value": "canvas", "height": "500px", "width": "800px"},
+ {"name": "profile", "profile", "height": "500px", "width": "300px"}
+ ]
+}
\ No newline at end of file