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/31 00:47:26 UTC

svn commit: r1195282 - in /incubator/wookie/trunk/widgets/templates/itemDetail: default.widget.properties scripts/itemDetail_controller.js

Author: rgardler
Date: Sun Oct 30 23:47:25 2011
New Revision: 1195282

URL: http://svn.apache.org/viewvc?rev=1195282&view=rev
Log:
allow the item being displayed to be defined in the URL

Modified:
    incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties
    incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js

Modified: incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties?rev=1195282&r1=1195281&r2=1195282&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties (original)
+++ incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties Sun Oct 30 23:47:25 2011
@@ -4,7 +4,9 @@
 itemDetail.get.url="http://api.twitter.com/1/statuses/show.xml?id=" + itemId + "&include_entities=false"
 
 # The initial itemID to use if none has been set.
-# This value will be overwritten by calling Widget.preferences.getItem("itemId");
+# This value can be overwritten by setting Widget.preferences.getItem("itemId");
+# This value can be overwritten by passing a parameter "itemId" in the request URL
+# A value passed in the URL will take priority and set the widget preference value.
 itemDetail.default.itemId=129284508087357440
 
 # The XSL to transform the detail XML (from itemDetail.get.url) to HTML

Modified: incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js?rev=1195282&r1=1195281&r2=1195282&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js (original)
+++ incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js Sun Oct 30 23:47:25 2011
@@ -21,25 +21,42 @@
  */ 
 var ${widget.shortname}_browse_controller = {
     init:function() {
-    	var id = Widget.preferences.getItem("itemId");
+    	var id = ${widget.shortname}_browse_controller.get("itemId");
     	if (id === undefined) {
+	    id = Widget.preferences.getItem("itemId");
+	    if (id === undefined) {
     		id = ${itemDetail.default.itemId}
+	    }
     	}
-        ${widget.shortname}_browse_controller.populate(id);
+	Widget.preferences.setItem("itemId", id);
+        ${widget.shortname}_browse_controller.populate();
     },
     
    /**
-    * Populate the results list with data from a given URL. The data is transformed using the "index2html.xsl" stylesheet.
+    * Populate the results list with data for a given item.
+    * The id of the item is obtained from  Widget.preferences.getItem("itemId");. 
+    * The data is transformed using the stylesheet named in the itemDetail.xsl.url property.
     */
-    populate:function(itemId) {
-		var url = widget.proxify(${itemDetail.get.url});
+    populate:function() {
+	var itemId = Widget.preferences.getItem("itemId");
+	var url = widget.proxify(${itemDetail.get.url});
         $('#detail').remove();
         var html = $.XSLTransform({
             xmlurl:url,
             xslurl:${itemDetail.xsl.url}
         });
         $('#content-primary').html(html).trigger("create");
+    },
+
+    /**
+     * get a parameter from the URL
+     */
+    get:function(name){
+	if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
+	    return decodeURIComponent(name[1]);
     }
+
+
 }
 
 /**