You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by rg...@apache.org on 2011/10/28 16:31:06 UTC

svn commit: r1190354 - in /incubator/wookie/trunk/widgets/templates/composite: ./ scripts/ style/

Author: rgardler
Date: Fri Oct 28 14:31:05 2011
New Revision: 1190354

URL: http://svn.apache.org/viewvc?rev=1190354&view=rev
Log:
A basic composite widget that will display multiple widgets in one widget. This is useful for test purposes at this stage, but it may well grow into something more.

By default it displays the browse and detail widgets. 

Added:
    incubator/wookie/trunk/widgets/templates/composite/
    incubator/wookie/trunk/widgets/templates/composite/config.xml
    incubator/wookie/trunk/widgets/templates/composite/default.widget.properties
    incubator/wookie/trunk/widgets/templates/composite/index.html
    incubator/wookie/trunk/widgets/templates/composite/readme.txt
    incubator/wookie/trunk/widgets/templates/composite/scripts/
    incubator/wookie/trunk/widgets/templates/composite/scripts/composite_controller.js
    incubator/wookie/trunk/widgets/templates/composite/scripts/composite_picker.js
    incubator/wookie/trunk/widgets/templates/composite/scripts/composite_widgetLoader.js
    incubator/wookie/trunk/widgets/templates/composite/style/
    incubator/wookie/trunk/widgets/templates/composite/style/desktop.css
      - copied unchanged from r1189252, incubator/wookie/trunk/scratchpad/admin-ui/desktop.css
    incubator/wookie/trunk/widgets/templates/composite/style/screen.css.add
      - copied unchanged from r1189252, incubator/wookie/trunk/scratchpad/admin-ui/default.css
    incubator/wookie/trunk/widgets/templates/composite/template_build.xml

Added: incubator/wookie/trunk/widgets/templates/composite/config.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/config.xml?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/config.xml (added)
+++ incubator/wookie/trunk/widgets/templates/composite/config.xml Fri Oct 28 14:31:05 2011
@@ -0,0 +1,48 @@
+<!--
+  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.
+-->
+<widget xmlns="http://www.w3.org/ns/widgets"
+        id="http://wookie.apache.org/widgets/${widget.shortname}"
+        version="0.1"
+        width="320"
+        height="480"
+        >
+  <name>${widget.name}</name>
+  <description>${widget.description}</description>
+  <content src="index.html"/>
+  <icon src="images/icon.png"/>
+  <author>Apache Wookie (Incubating) Community</author>
+  <access origin="*"/>  
+  
+  <licence>Licensed to the University of Oxford 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.</licence>
+
+</widget>
+
+
+

Added: incubator/wookie/trunk/widgets/templates/composite/default.widget.properties
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/default.widget.properties?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/default.widget.properties (added)
+++ incubator/wookie/trunk/widgets/templates/composite/default.widget.properties Fri Oct 28 14:31:05 2011
@@ -0,0 +1,11 @@
+composite.wookie.domain=localhost
+composite.wookie.port=8080
+composite.wookie.path=wookie/
+
+composite.wookie.apikey=TEST
+composite.wookie.userid=testsuer
+composite.wookie.shareddatakey=mysharedkey
+
+# Array of widget ids to be included in the composite widget.
+composite.widgets=["http://wookie.apache.org/widgets/BrowseTestWidget", "http://wookie.apache.org/widgets/ItemDetailTestWidget"]
+

Added: incubator/wookie/trunk/widgets/templates/composite/index.html
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/index.html?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/index.html (added)
+++ incubator/wookie/trunk/widgets/templates/composite/index.html Fri Oct 28 14:31:05 2011
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<!--
+  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.
+-->
+<html>
+
+<head>
+<title>Wookie Admin Demo</title>
+<meta name="viewport" content="width=device-width, height=device-height" />
+<link rel="stylesheet" type="text/css"
+	href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css"
+	media="screen" />
+<link rel="stylesheet" type="text/css" href="style/all.css"
+	media="screen" />
+<link rel="stylesheet" type="text/css" href="style/desktop.css"
+	media="screen and (min-device-width:1024px)" />
+<!--[if lt IE 9]>
+    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
+    <![endif]-->
+<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
+<script src="scripts/composite_picker.js"></script>
+<script src="scripts/composite_widgetLoader.js"></script>
+<script src="scripts/controller.js"></script>
+
+</head>
+
+<body>
+
+	<header role="banner">
+		<h1>Composite</h1>
+	</header>
+
+	<nav role="navigation" class="ui-bar-e ui-header">
+		<h4 class="ui-title">
+			<a onClick="${widget.shortname}_Picker.prev()" href="#" title="left"
+				class="ui-btn ui-btn-left ui-btn-icon-notext ui-btn-corner-all ui-shadow ui-btn-hover-e ui-btn-down-e"><span
+				class="ui-btn-inner ui-btn-corner-all"><span
+					class="ui-btn-text">Left</span><span
+					class="ui-icon ui-icon-arrow-l ui-icon-shadow"></span></span></a> <span
+				id="current-widget-title">Workspace 1</span> <a
+				onClick="${widget.shortname}_Picker.next()" href="#" title="right"
+				class="ui-btn ui-btn-right ui-btn-icon-notext ui-btn-corner-all ui-shadow ui-btn-hover-e ui-btn-down-a"><span
+				class="ui-btn-inner ui-btn-corner-all"><span
+					class="ui-btn-text">Right</span><span
+					class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span></span></a>
+		</h4>
+	</nav>
+
+	<article role="main"></article>
+
+</body>
+</html>
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/templates/composite/readme.txt
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/readme.txt?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/readme.txt (added)
+++ incubator/wookie/trunk/widgets/templates/composite/readme.txt Fri Oct 28 14:31:05 2011
@@ -0,0 +1,18 @@
+This is a single widget used to display multiple widgets using a progressive enhancement technique to display 
+the widgets in a sensible way regardless of the screen size.
+
+* Configuration
+
+** Widget Server
+
+By default this widget tries to retrieve other widgets from "localhost:8080/wookie/", in a production environment 
+you will need to load widgets from a live server. Change the "composite.wookie.domain", "composite.wookie.port" and "composite.wookie.path" 
+accordingly.
+
+You will also need to set the API key information accordingly using "composite.wookie.apikey", "composite.wookie.userid" and "composite.wookie.shareddatakey"
+properties. By default these are set to the default test user credentials.
+
+* Further REading
+
+For more info on the progressive enhancement features 
+see http://scottbw.wordpress.com/2011/03/16/adventures-in-progressive-enhancement/
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/templates/composite/scripts/composite_controller.js
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/scripts/composite_controller.js?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/scripts/composite_controller.js (added)
+++ incubator/wookie/trunk/widgets/templates/composite/scripts/composite_controller.js Fri Oct 28 14:31:05 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+/**
+ * The ${widget.shortname}_composite_controller object
+ * This is used to wire up the view and model with actions
+ */ 
+var ${widget.shortname}_Controller = {
+    init:function() {
+    	var widgets = ${composite.widgets}; 
+        var properties = [{widget:"http://wookie.apache.org/widgets/freeder", key:"feedURL", value:"http://apache.markmail.org/atom/wookie-dev"}];
+        ${widget.shortname}_WidgetLoader.init(widgets,properties);
+    }
+}
+
+/**
+ * Initialise page layout
+ */
+$(window).load(function(event) {
+   ${widget.shortname}_Controller.init(); 
+});

Added: incubator/wookie/trunk/widgets/templates/composite/scripts/composite_picker.js
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/scripts/composite_picker.js?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/scripts/composite_picker.js (added)
+++ incubator/wookie/trunk/widgets/templates/composite/scripts/composite_picker.js Fri Oct 28 14:31:05 2011
@@ -0,0 +1,40 @@
+/*
+ * 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 ${widget.shortname}_Picker = {
+	curr : 0,
+
+	next : function() {
+		${widget.shortname}_Picker.curr++;
+		if (${widget.shortname}_Picker.curr >= ${widget.shortname}_${widget.shortname}_WidgetLoader.widgets.length)
+			${widget.shortname}_Picker.curr = 0;
+		${widget.shortname}_Picker.select(${widget.shortname}_Picker.curr);
+	},
+
+	prev : function() {
+		${widget.shortname}_Picker.curr--;
+		if (${widget.shortname}_Picker.curr < 0)
+			${widget.shortname}_Picker.curr = ${widget.shortname}_WidgetLoader.widgets.length - 1;
+		${widget.shortname}_Picker.select(${widget.shortname}_Picker.curr);
+	},
+
+	select : function(id) {
+		/* $("#current-widget-title").text(${widget.shortname}_WidgetLoader.widgets[id].title); */
+		$('.widget').hide();
+		$("#" + id).show();
+	},
+};
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/templates/composite/scripts/composite_widgetLoader.js
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/scripts/composite_widgetLoader.js?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/scripts/composite_widgetLoader.js (added)
+++ incubator/wookie/trunk/widgets/templates/composite/scripts/composite_widgetLoader.js Fri Oct 28 14:31:05 2011
@@ -0,0 +1,141 @@
+/*
+ * 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 ${widget.shortname}_WidgetLoader = {
+	baseURL : "http://${composite.wookie.domain}:${composite.wookie.port}/${composite.wookie.path}",
+
+	init : function(widgets, properties) {
+		${widget.shortname}_WidgetLoader.totalWidgets = widgets.length;
+		${widget.shortname}_WidgetLoader.properties = properties;
+		for ( var i in widgets) {
+			${widget.shortname}_WidgetLoader.getWidget(widgets[i]);
+		}
+	},
+
+	widgets : [],
+	id : 0,
+	properties : [],
+	propertiesSet : 0,
+
+	getWidget : function(widgetId) {
+		var userId = "${composite.wookie.userid}";
+		var sharedDataKey = "${composite.wookie.shareddatakey}";
+		var apiKey = "${composite.wookie.apikey}";
+		var instanceUrl = ${widget.shortname}_WidgetLoader.baseURL + "widgetinstances";
+		$.ajax({
+			type : 'POST',
+			url : instanceUrl,
+			data : {
+				"userid" : userId,
+				"shareddatakey" : sharedDataKey,
+				"api_key" : apiKey,
+				"widgetid" : widgetId
+			},
+			success : ${widget.shortname}_WidgetLoader.parseWidgetData,
+			error: function (xhr, ajaxOptions, thrownError){
+                alert("Error loading widget with id " + widgetId + " from " + instanceUrl + "\n\nStatus code is " + xhr.status);
+            },
+			dataType : "xml"
+		});
+	},
+
+	parseWidgetData : function(xml) {
+		$(xml).find("widgetdata").each(function() {
+			var widget = {};
+
+			widget.url = $(this).find('url').text();
+			widget.height = $(this).find('height').text();
+			widget.width = $(this).find('width').text();
+			widget.title = $(this).find('title').text();
+			widget.id = ${widget.shortname}_WidgetLoader.id;
+			${widget.shortname}_WidgetLoader.id++;
+			${widget.shortname}_WidgetLoader.addWidget(widget);
+		});
+	},
+
+	showWidget : function(xml) {
+		$(xml).find("widgetdata").each(
+				function() {
+					var url = $(this).find('url').text();
+					var height = $(this).find('height').text();
+					var width = $(this).find('width').text();
+
+					$("#workspace").append(
+							$("<iframe/>").attr("src", url).attr("height",
+									height).attr("width", width).attr("class",
+									"widget"))
+				});
+	},
+
+	addWidget : function(widget) {
+		${widget.shortname}_WidgetLoader.widgets.push(widget);
+		// Picker.add(widget);
+		if (${widget.shortname}_WidgetLoader.widgets.length == ${widget.shortname}_WidgetLoader.totalWidgets)
+			${widget.shortname}_WidgetLoader.setProperties();
+	},
+
+	setProperties : function() {
+		if (${widget.shortname}_WidgetLoader.properties.length == 0)
+			${widget.shortname}_WidgetLoader.showWidgets();
+		for (i in ${widget.shortname}_WidgetLoader.properties) {
+			var property = ${widget.shortname}_WidgetLoader.properties[i];
+			${widget.shortname}_WidgetLoader.setProperty(property);
+		}
+	},
+
+	setProperty : function(property) {
+		var userId = "admin";
+		var sharedDataKey = "admin";
+		var apiKey = "TEST";
+		$.ajax({
+			type : 'POST',
+			url : ${widget.shortname}_WidgetLoader.baseURL + "properties",
+			data : {
+				"userid" : userId,
+				"shareddatakey" : sharedDataKey,
+				"api_key" : apiKey,
+				"widgetid" : property.widget,
+				"propertyname" : property.key,
+				"propertyvalue" : property.value
+			},
+			success : ${widget.shortname}_WidgetLoader.propertySet(),
+			dataType : "xml"
+		});
+	},
+
+	propertySet : function() {
+		${widget.shortname}_WidgetLoader.propertiesSet++;
+		if (${widget.shortname}_WidgetLoader.propertiesSet == ${widget.shortname}_WidgetLoader.properties.length)
+			${widget.shortname}_WidgetLoader.showWidgets();
+	},
+
+	showWidgets : function() {
+		for ( var i in ${widget.shortname}_WidgetLoader.widgets) {
+			var widget = ${widget.shortname}_WidgetLoader.widgets[i];
+			$("article").append(
+					$("<iframe/>").attr("id", widget.id)
+							.attr("src", widget.url).attr("height",
+									widget.height).attr("width", widget.width)
+							.attr("class", "widget")
+							.attr("role", "application").attr("title",
+									widget.title))
+		}
+		// Make sure the first widget is visible
+		$("#0").show();
+		/* $("#current-widget-title").text(${widget.shortname}_WidgetLoader.widgets[0].title); */
+	}
+}

Added: incubator/wookie/trunk/widgets/templates/composite/template_build.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/composite/template_build.xml?rev=1190354&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/composite/template_build.xml (added)
+++ incubator/wookie/trunk/widgets/templates/composite/template_build.xml Fri Oct 28 14:31:05 2011
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<project basedir="." name="composite_template">
+
+  <target name="_init_template"
+          description="Define any template specifc properties">
+    <echo message="+------------------------------------------"/>
+    <echo message="|  Initialising template properties"/>
+    <echo message="+------------------------------------------"/>
+    
+    <echoproperties destfile="${widget.build.dir}/${widget.shortname}.properties" prefix=""/>
+  </target>
+
+  <target name="_generate_from_parent_templates">
+    <echo message="+------------------------------------------"/>
+    <echo message="|  ${template.name} has no parent templates"/>
+    <echo message="+------------------------------------------"/>
+
+  </target>
+</project>
\ No newline at end of file