From ed8e6bb33bce9762b7d6955856bb0cc074f410a1 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Tue, 16 Oct 2012 21:13:44 +0100 Subject: [PATCH] [#180,demos/search][s]: tweak text and refactor js and document it. --- demos/search/app.js | 64 +++++++++++++++++++++++------------------ demos/search/index.html | 7 +++-- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/demos/search/app.js b/demos/search/app.js index 1a9929ea..8e176330 100644 --- a/demos/search/app.js +++ b/demos/search/app.js @@ -1,37 +1,17 @@ jQuery(function($) { - window.dataExplorer = null; - window.explorerDiv = $('.search-here'); + var $el = $('.search-here'); // var url = 'http://openspending.org/api/search'; // var url = 'http://localhost:9200/tmp/sfpd-last-month'; + + // Crate our Recline Dataset + // Here we are just using the local data var dataset = new recline.Model.Dataset({ records: simpleData }); - createSearch(dataset); -}); - -var createSearch = function(dataset, state) { - // remove existing data explorer view - var $el = $('
'); - $el.appendTo(window.explorerDiv); - var template = ' \ - {{#records}} \ -
\ -

\ - {{title}} by {{Author}} \ -

\ -

{{description}}

\ -

${{price}}

\ -
\ - {{/records}} \ - '; - - window.dataExplorer = new SearchView({ - el: $el, - model: dataset, - template: template - }); + // Optional + // Let's configure the initial query a bit and set up facets dataset.queryState.set({ size: 10 }, @@ -39,13 +19,23 @@ var createSearch = function(dataset, state) { ); dataset.queryState.addFacet('Author'); dataset.query(); -} + + // The search view allows us to customize the template used to render the + // list of results + var template = getTemplate(); + var searchView = new SearchView({ + el: $el, + model: dataset, + template: template + }); + searchView.render(); +}); // Simple Search View // // Pulls together various Recline UI components and the central Dataset and Query (state) object // -// Plus support for customization e.g. of item template +// Plus support for customization e.g. of template for list of results var SearchView = Backbone.View.extend({ initialize: function(options) { this.el = $(this.el); @@ -95,6 +85,24 @@ var SearchView = Backbone.View.extend({ } }); +// -------------------------------------------------------- +// Stuff specific to this demo + +function getTemplate() { + template = ' \ + {{#records}} \ +
\ +

\ + {{title}} by {{Author}} \ +

\ +

{{description}}

\ +

${{price}}

\ +
\ + {{/records}} \ + '; + return template; +} + var simpleData = [ { title: 'War and Peace', diff --git a/demos/search/index.html b/demos/search/index.html index e7fc1138..3eb25414 100644 --- a/demos/search/index.html +++ b/demos/search/index.html @@ -7,7 +7,7 @@ root: ../../