Author: scottbw
Date: Wed Jan 11 13:18:52 2012
New Revision: 1230001
URL: http://svn.apache.org/viewvc?rev=1230001&view=rev
Log:
Removed XSL transformation from the Browse template, and updated the Widget
Browser example. I replaced the XSL transformation with simple token
replacement using a HTML file as the detail template that the designer edits,
and a list of elements and attributes in the widget properties file to use for
replacing the tokens in the template. This is a lot less sophisticated than
using XSL, but overcomes the issue of browser compatibility (See WOOKIE-297).
For more complex replacement, the widget designer could override the actual
JavaScript and put in some of their own rules. Note that the ItemDetail
template still uses XSLT.
Added:
incubator/wookie/trunk/widgets/templates/browse/item_template.html
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/item_template.html
Removed:
incubator/wookie/trunk/widgets/templates/browse/detail2html.xsl
incubator/wookie/trunk/widgets/templates/browse/index2html.xsl
incubator/wookie/trunk/widgets/templates/browse/legal/XSLTransform_license.txt
incubator/wookie/trunk/widgets/templates/browse/lib/XSLTransform.js
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/detail2html.xsl
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/index2html.xsl
Modified:
incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
incubator/wookie/trunk/widgets/templates/browse/index.html
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
incubator/wookie/trunk/widgets/templates/browse/template_build.xml
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/widget.properties
Modified:
incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/default.widget.properties?rev=1230001&r1=1230000&r2=1230001&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
(original)
+++ incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
Wed Jan 11 13:18:52 2012
@@ -5,10 +5,31 @@
# order = the sort order for APIs that support it
browse.index.url="http://localhost:8080/wookie/widgets?all=true"
-# URL of the stylesheet for transforming the index file returned from
browse.index.url into html
#
+# The template string to use for the collection of items to browse. This is
used to hold
+# the set of items to display.
+#
+# type: string
+#
+browse.collection.template = "<div id='results'
data-role='collapsible-set'>${ITEMS}</div>"
+
+#
+# The name of the XML element that represents a single item
# type: string
-browse.index.xsl.url="index2html.xsl"
+#
+browse.item.name = "widget"
+
+#
+# The names of the elements to map into the template placeholders. E.g. if it
contains "title", then $TITLE in the template
+# would be replaced by the content of the <title> element in the XML data
+#
+browse.item.elements = "description,title"
+
+#
+# The names of the attributes to map into the template placeholders. E.g. if
it contains "id", then $ID in the template
+# would be replaced by the content of the id attribute of the item XML element
in the XML data
+#
+browse.item.attributes = "id"
# The URL from which to retrieve search data
#
@@ -26,10 +47,4 @@ browse.sort=updated
#
# type: string
# variables: itemId is the ID of the item to display
-browse.get.detail.url="http://localhost:8080/wookie/widgets/" + itemId
-
-# URL of the stylesheet for transforming a record detail
-# into HTML for display in the expanded index section
-#
-# type: string
-browse.detail.xsl.url="detail2html.xsl"
\ No newline at end of file
+browse.get.detail.url="http://localhost:8080/wookie/widgets/" + itemId
\ No newline at end of file
Modified: incubator/wookie/trunk/widgets/templates/browse/index.html
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/index.html?rev=1230001&r1=1230000&r2=1230001&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/index.html (original)
+++ incubator/wookie/trunk/widgets/templates/browse/index.html Wed Jan 11
13:18:52 2012
@@ -28,7 +28,6 @@
${content.scripts}
-<script type="text/javascript" src="lib/XSLTransform.js"></script>
<script type="text/javascript" src="scripts/controller.js"></script>
<title>${widget.name}</title>
Added: incubator/wookie/trunk/widgets/templates/browse/item_template.html
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/item_template.html?rev=1230001&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/item_template.html (added)
+++ incubator/wookie/trunk/widgets/templates/browse/item_template.html Wed Jan
11 13:18:52 2012
@@ -0,0 +1,6 @@
+<div class='result' data-role='collapsible' wid='${ID}'>
+ <h3>${TITLE}</h3>
+ <div class='detail'>
+ <p>${DESCRIPTION}</p>
+ </div>
+</div>
Modified:
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js?rev=1230001&r1=1230000&r2=1230001&view=diff
==============================================================================
---
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
(original)
+++
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
Wed Jan 11 13:18:52 2012
@@ -78,14 +78,11 @@ var ${widget.shortname}_browse_controlle
},
/**
- * 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 from a given URL.
*/
populate:function(sourceUrl) {
- $('#results').remove();
- var html = $.XSLTransform({
- xmlurl:sourceUrl,
- xslurl:${browse.index.xsl.url}
- });
+ $('#results').remove();
+ var html = ${widget.shortname}_browse_controller.transform(sourceUrl);
$('#content-primary').html(html).trigger("create");
$('.result:first').trigger('expand');
${widget.shortname}_browse_controller.update();
@@ -98,10 +95,7 @@ var ${widget.shortname}_browse_controlle
$(".detail").html("<p>Loading...</p>");
var sourceUrl = widget.proxify(${browse.get.detail.url});
$.mobile.showPageLoadingMsg();
- var html = $.XSLTransform({
- xmlurl:sourceUrl,
- xslurl:${browse.detail.xsl.url}
- });
+ var html = ${widget.shortname}_browse_controller.transform(sourceUrl);
$(".detail").html(html);
$('.detail').click(function() {
var event = { widget: "${widget.shortname}", type: "clickItem",
itemId: itemId};
@@ -128,4 +122,57 @@ $('div.result').live('expand', function(
var itemId = wid.substr(wid.indexOf("id=")+3);
var event = { widget: "${widget.shortname}", type: "expandItem", itemId:
itemId};
${widget.shortname}_controller.executeCallbacks(event );
-});
\ No newline at end of file
+});
+
+
+/**
+ * load XML data and transform it into HTML
+ */
+${widget.shortname}_browse_controller.transform = function(src){
+ var output = "";
+
+ $.ajax({
+ url: src,
+ dataType: "xml",
+ async: false,
+ success: function(xml){
+ output = ${widget.shortname}_browse_controller.transformXml(xml);
+ }
+ });
+
+ return output;
+}
+
+/**
+ * Transform data into HTML
+ */
+${widget.shortname}_browse_controller.transformXml = function(xml){
+
+ var output = "";
+ var items = "";
+
+ /**
+ * For each element that matches itemName, create a new ItemTemplate and
+ * replace placeholders in the template with values from the XML using the
ItemElements
+ * and ItemAttrobutes lists
+ */
+ $(xml).find(${browse.item.name}).each(
+ function(){
+ var item = "${browse.item.template}";
+ var elements = ${browse.item.elements}.split(",");
+ for (var i=0;i<elements.length;i++){
+ var element = elements[i];
+ item = item.replace("${"+element.toUpperCase()+"}",
$(this).find(element).text());
+ }
+ var attributes = ${browse.item.attributes}.split(",");
+ for (var i=0;i<attributes.length;i++){
+ var attribute = attributes[i];
+ item = item.replace("${"+attribute.toUpperCase()+"}",
$(this).attr(attribute));
+ }
+ items += item;
+ }
+ );
+
+ output = ${browse.collection.template}.replace("${ITEMS}", items);
+ return output;
+}
\ No newline at end of file
Modified: incubator/wookie/trunk/widgets/templates/browse/template_build.xml
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/template_build.xml?rev=1230001&r1=1230000&r2=1230001&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/template_build.xml
(original)
+++ incubator/wookie/trunk/widgets/templates/browse/template_build.xml Wed Jan
11 13:18:52 2012
@@ -22,6 +22,31 @@
<echo message="| Initialising template properties"/>
<echo message="+------------------------------------------"/>
+
+ <loadfile property="browse.item.template"
+ srcFile="item_template.html"
+ failonerror="false">
+ <filterchain>
+ <striplinebreaks/>
+ </filterchain>
+ </loadfile>
+
+ <loadfile property="browse.item.template"
+ srcFile="../common/item_template.html"
+ failonerror="false">
+ <filterchain>
+ <striplinebreaks/>
+ </filterchain>
+ </loadfile>
+
+ <loadfile property="browse.item.template"
+ srcFile="${template.dir}/${template.name}/item_template.html"
+ failonerror="false">
+ <filterchain>
+ <striplinebreaks/>
+ </filterchain>
+ </loadfile>
+
<loadfile property="content.scripts"
srcFile="content_scripts.html"
failonerror="false">
Added:
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/item_template.html
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/item_template.html?rev=1230001&view=auto
==============================================================================
---
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/item_template.html
(added)
+++
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/item_template.html
Wed Jan 11 13:18:52 2012
@@ -0,0 +1,8 @@
+<div class='result' data-role='collapsible' wid='${ID}'>
+ <h3>${TITLE}</h3>
+ <div class='detail'>
+ <img width=32 height=32 alt='icon' src='${ICON}'/>
+ <p>${DESCRIPTION}</p>
+ <p>Author: ${AUTHOR}</p>
+ </div>
+</div>
Modified:
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/widget.properties
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/widget.properties?rev=1230001&r1=1230000&r2=1230001&view=diff
==============================================================================
---
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/widget.properties
(original)
+++
incubator/wookie/trunk/widgets/templates/widgets/adminWidgets/widgetBrowse/widget.properties
Wed Jan 11 13:18:52 2012
@@ -11,33 +11,29 @@ wookie.url=http://localhost:8080/wookie
# type: string
# variables: sort = the sort term for APIs that support it
# order = the sort order for APIs that support it
-browse.index.url="${wookie.url}/widgets?all=true"
+browse.index.url="http://localhost:8080/wookie/widgets?all=true"
-# URL of the stylesheet for transforming the index file returned from
browse.index.url into html
#
+# The name of the XML element that represents a single item
# type: string
-browse.index.xsl.url="index2html.xsl"
+#
+browse.item.name = "widget"
-# The URL from which to retrieve search data
#
-# type: string
-# variables: query = query string entered into the search form
-# sort = the sort term for APIs that support it
-# order = the sort order for APIs that support it
-browse.search.url=
+# The names of the elements to map into the template placeholders. E.g. if it
contains "title", then ${TITLE} in the template
+# would be replaced by the content of the <title> element in the XML data
+#
+browse.item.elements = "description,title,icon,author"
-# Default sort parameter for APIs that support sorting of the results
-browse.sort=updated
+#
+# The names of the attributes to map into the template placeholders. E.g. if
it contains "id", then ${ID} in the template
+# would be replaced by the content of the id attribute of the item XML element
in the XML data
+#
+browse.item.attributes = "id"
# The URL from which to retrieve detailed
# information about an item
#
# type: string
# variables: itemId is the ID of the item to display
-browse.get.detail.url="${wookie.url}/widgets/" + itemId
-
-# URL of the stylesheet for transforming a record detail
-# into HTML for display in the expanded index section
-#
-# type: string
-browse.detail.xsl.url="detail2html.xsl"
\ No newline at end of file
+browse.get.detail.url="http://localhost:8080/wookie/widgets/" + itemId
\ No newline at end of file