Skip to content

Commit

Permalink
Adds Thingy template variable to permit Javascript visualisation of s…
Browse files Browse the repository at this point in the history
…earch results
  • Loading branch information
patspam committed Sep 21, 2010
1 parent 9809868 commit 093f7d6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -16,6 +16,7 @@
- fixed #11876: packing templates, snippets, headtags removes conditional CSS comments
- fixed #11877: Criteria Builder on "shortcut by alternate criteria" gets ugly with many checkbox items
- fixed #11878: Addons title not internationalized
- added Thingy template variable to permit Javascript visualisation of search results (Patrick Donelan, SDH Consulting Group)

7.10.0
- fixed #11812: Checking www_ajaxSave's response in the cart js, urlencoding post parameters
Expand Down
34 changes: 34 additions & 0 deletions docs/templates.txt
Expand Up @@ -26,4 +26,38 @@ templates, you will need to apply these changes manually to your copies.
</tmpl_unless>
<tmpl_loop story_loop>

* Thingy searchResults_json
This is a JSON-encoded version of searchResults_loop, which allows people to access Thingy search results
in Javascript/Flash/etc.. For example, you can use OpenFlashCharts2 (http://teethgrinder.co.uk/open-flash-chart-2)
and SWFObject to access the data and then display it as a pretty custom chart via the following:

<tmpl_if searchResult_loop>
<div id="chart-container">
<div id="chart">Loading..</div>
</div>
<script type="text/javascript">
function open_flash_chart_data() {
var data_json = "<tmpl_var searchResult_json ESCAPE=JS>";
var data = YAHOO.lang.JSON.parse(data_json);
var chart = {
elements: [
// populate dynamically from data object
]
};
return YAHOO.lang.JSON.stringify(chart);
}
// Embed the chart
swfobject.embedSWF(
'/path/to/open-flash-chart.swf', // url
'chart', // container element id
'100%', // width
'100%', // height
'9.0.0', // version
'/path/to/swfobject/expressInstall.swf', // expressInstall
{ loading: 'Loading...' }, // flashvars
{}, // params
{} // attributes
);
</script>
</tmpl_if>

4 changes: 4 additions & 0 deletions lib/WebGUI/Asset/Wobject/Thingy.pm
Expand Up @@ -3407,7 +3407,11 @@ sequenceNumber');
push(@searchResult_loop,\%templateVars);
}
$var->{searchResult_loop} = \@searchResult_loop;

# Also expose the search results in the template as a json-encoded string
# so that people can e.g. visualise the results via Javascript
$var->{searchResult_json} = JSON->new->encode(\@searchResult_loop);

$p->appendTemplateVars($var);

$var->{"form_start"} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl,method=>'GET'})
Expand Down
2 changes: 2 additions & 0 deletions lib/WebGUI/Help/Asset_Thingy.pm
Expand Up @@ -236,6 +236,8 @@ our $HELP = {
},
]
},
{ 'name' => 'searchResult_json',
},
],
related => [
{ tag => 'edit thing template',
Expand Down
6 changes: 6 additions & 0 deletions lib/WebGUI/i18n/English/Asset_Thingy.pm
Expand Up @@ -659,6 +659,12 @@ Simply replace "key1"/"value1" with your own name/value pairs},
context => q|Description of a tmpl_var for the template help.|,
},

'searchResult_json' => {
message => q|JSON-encoded version of searchResult_loop so that you can access the data in Javascript|,
lastUpdated => 1285094918,
context => q|Description of a tmpl_var for the template help.|,
},

'things_loop' => {
message => q|A loop containing the Things that are defined for this Thingy Asset, with links to management
functions for those Things|,
Expand Down

0 comments on commit 093f7d6

Please sign in to comment.