Author: scottbw
Date: Thu Jan 12 11:14:32 2012
New Revision: 1230490
URL: http://svn.apache.org/viewvc?rev=1230490&view=rev
Log:
Several updates to the browse template: (1) Restored the difference between a
"list" and "detail" update with a parameter against the transform function that
selectively applies the collection template, and switches between "summary" and
"detail" item templates. (2) Item detail updates now only affect the specific
detail tag being viewed rather than all the detail tags in the widget. (3)
Escape search URLs when testing for their existence
Modified:
incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
incubator/wookie/trunk/widgets/templates/browse/template_build.xml
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=1230490&r1=1230489&r2=1230490&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
(original)
+++ incubator/wookie/trunk/widgets/templates/browse/default.widget.properties
Thu Jan 12 11:14:32 2012
@@ -14,6 +14,14 @@ browse.index.url="http://localhost:8080/
browse.collection.template = "<div id='results'
data-role='collapsible-set'>${ITEMS}</div>"
#
+# The template string to use for item summaries, representing a single record
but before
+# the item detail has been retrieved
+#
+# type: string
+#
+browse.item.summary.template = <div class='result' data-role='collapsible'
wid='${ID}'><h3>${TITLE}</h3><div class='detail'></div></div>
+
+#
# The name of the XML element that represents a single item
# type: string
#
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=1230490&r1=1230489&r2=1230490&view=diff
==============================================================================
---
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
(original)
+++
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
Thu Jan 12 11:14:32 2012
@@ -26,7 +26,7 @@ var ${widget.shortname}_browse_controlle
// the search panel
//
var query = "";
- var searchUrl = ${browse.search.url};
+ var searchUrl = '${browse.search.url}';
if(searchUrl === "") $("#searchPanel").hide();
${widget.shortname}_browse_controller.update();
${widget.shortname}_browse_controller.search()
@@ -84,7 +84,7 @@ var ${widget.shortname}_browse_controlle
*/
populate:function(sourceUrl) {
$('#results').remove();
- var html = ${widget.shortname}_browse_controller.transform(sourceUrl);
+ var html = ${widget.shortname}_browse_controller.transform(sourceUrl,
"list");
$('#content-primary').html(html).trigger("create");
$('.result:first').trigger('expand');
${widget.shortname}_browse_controller.update();
@@ -93,13 +93,26 @@ var ${widget.shortname}_browse_controlle
/**
* Retrieve the details of an item and display them in the detail section.
*/
- displaySummary:function(itemId){
- $(".detail").html("<p>Loading...</p>");
+ displaySummary:function(itemId){
+
+ /**
+ * Locate the detail element to update
+ */
+ var detailElement = $(".result[wid='"+itemId+"']").find(".detail");
+
+ /**
+ * Load the data, showing a loading message while waiting
+ */
+ detailElement.html("<p>Loading...</p>");
var sourceUrl = widget.proxify(${browse.get.detail.url});
$.mobile.showPageLoadingMsg();
- var html = ${widget.shortname}_browse_controller.transform(sourceUrl);
- $(".detail").html(html);
- $('.detail').click(function() {
+ var html = ${widget.shortname}_browse_controller.transform(sourceUrl,
"detail");
+ detailElement.html(html);
+
+ /**
+ * Add events
+ */
+ detailElement.click(function() {
var event = { widget: "${widget.shortname}", type: "clickItem",
itemId: itemId};
${widget.shortname}_controller.executeCallbacks(event);
});
@@ -129,8 +142,10 @@ $('div.result').live('expand', function(
/**
* load XML data and transform it into HTML
+ * @param src the URL to load
+ * @param type the type of data transform requested, either "detail" or "list"
*/
-${widget.shortname}_browse_controller.transform = function(src){
+${widget.shortname}_browse_controller.transform = function(src, type){
var output = "";
$.ajax({
@@ -138,7 +153,7 @@ ${widget.shortname}_browse_controller.tr
dataType: "xml",
async: false,
success: function(xml){
- output = ${widget.shortname}_browse_controller.transformXml(xml);
+ output = ${widget.shortname}_browse_controller.transformXml(xml, type);
}
});
@@ -148,7 +163,13 @@ ${widget.shortname}_browse_controller.tr
/**
* Transform data into HTML
*/
-${widget.shortname}_browse_controller.transformXml = function(xml){
+${widget.shortname}_browse_controller.transformXml = function(xml, type){
+
+ if (type === "detail"){
+ template = "${browse.item.detail.template}";
+ } else {
+ template = "${browse.item.summary.template}";
+ }
var output = "";
var items = "";
@@ -160,7 +181,7 @@ ${widget.shortname}_browse_controller.tr
*/
$(xml).find(${browse.item.name}).each(
function(){
- var item = "${browse.item.template}";
+ var item = template;
var elements = ${browse.item.elements}.split(",");
for (var i=0;i<elements.length;i++){
var element = elements[i];
@@ -177,6 +198,14 @@ ${widget.shortname}_browse_controller.tr
}
);
- output = ${browse.collection.template}.replace("${ITEMS}", items);
+ /**
+ * If we are returning a list, wrap the result in the collection template,
otherwise
+ * just return the item
+ */
+ if (type === "list"){
+ output = ${browse.collection.template}.replace("${ITEMS}", items);
+ } else {
+ output = 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=1230490&r1=1230489&r2=1230490&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/template_build.xml
(original)
+++ incubator/wookie/trunk/widgets/templates/browse/template_build.xml Thu Jan
12 11:14:32 2012
@@ -23,7 +23,7 @@
<echo message="+------------------------------------------"/>
- <loadfile property="browse.item.template"
+ <loadfile property="browse.item.detail.template"
srcFile="item_template.html"
failonerror="false">
<filterchain>
@@ -31,7 +31,7 @@
</filterchain>
</loadfile>
- <loadfile property="browse.item.template"
+ <loadfile property="browse.item.detail.template"
srcFile="../common/item_template.html"
failonerror="false">
<filterchain>
@@ -39,7 +39,7 @@
</filterchain>
</loadfile>
- <loadfile property="browse.item.template"
+ <loadfile property="browse.item.detail.template"
srcFile="${template.dir}/${template.name}/item_template.html"
failonerror="false">
<filterchain>