5
* Provides searching functionality for the charm browser.
11
YUI.add('subapp-browser-searchview', function(Y) {
12
var ns = Y.namespace('juju.browser.views'),
13
views = Y.namespace('juju.views'),
14
widgets = Y.namespace('juju.widgets'),
15
models = Y.namespace('juju.models');
17
ns.BrowserSearchView = Y.Base.create('browser-view-searchview', Y.View, [
18
views.utils.apiFailingView
20
template: views.Templates.search,
22
* Renders the search results from the the store query.
24
* @method _renderSearchResults
25
* @param {Y.Node} container Optional container to render results to.
27
_renderSearchResults: function(results) {
28
var target = this.get('renderTo'),
29
tpl = this.template({count: results.size()}),
30
tplNode = Y.Node.create(tpl),
31
container = tplNode.one('.search-results');
33
results.map(function(charm) {
34
var ct = new widgets.browser.CharmToken(charm.getAttrs());
37
target.setHTML(tplNode);
41
* Generates a message to the user based on a bad api call.
44
* @param {Object} data the json decoded response text.
45
* @param {Object} request the original io_request object for debugging.
48
apiFailure: function(data, request) {
49
this._apiFailure(data, request, 'Failed to load search results.');
53
* Renders the searchview, rendering search results for the view's search
59
var text = this.get('text');
60
this.get('store').search(text, {
61
'success': function(data) {
62
var results = this.get('store').resultsToCharmlist(data.result);
63
this._renderSearchResults(results);
65
'failure': this.apiFailure
71
* The container node the view is rendering to.
80
* An instance of the Charmworld API object to hit for any data that
91
* The text being searched on
104
'browser-charm-token',
105
'browser-overlay-indicator',