OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 | 3 |
4 /** | 4 /** |
5 * Provides searching functionality for the charm browser. | 5 * Provides searching functionality for the charm browser. |
6 * | 6 * |
7 * @namespace juju | 7 * @namespace juju |
8 * @module browser | 8 * @module browser |
9 * @submodule views | 9 * @submodule views |
10 */ | 10 */ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 @method _updateActive | 54 @method _updateActive |
55 @param {Node} clickTarget the charm-token clicked on to activate. | 55 @param {Node} clickTarget the charm-token clicked on to activate. |
56 | 56 |
57 */ | 57 */ |
58 _updateActive: function(clickTarget) { | 58 _updateActive: function(clickTarget) { |
59 // Remove the active class from any nodes that have it. | 59 // Remove the active class from any nodes that have it. |
60 Y.all('.yui3-charmtoken.active').removeClass('active'); | 60 Y.all('.yui3-charmtoken.active').removeClass('active'); |
61 | 61 |
62 // Add it to the current node. | 62 // Add it to the current node. |
63 clickTarget.ancestor('.yui3-charmtoken').addClass('active'); | 63 if (clickTarget) { |
| 64 clickTarget.ancestor('.yui3-charmtoken').addClass('active'); |
| 65 } |
64 }, | 66 }, |
65 | 67 |
66 /** | 68 /** |
67 * Renders the search results from the the store query. | 69 * Renders the search results from the the store query. |
68 * | 70 * |
69 * @method _renderSearchResults | 71 * @method _renderSearchResults |
70 * @param {Y.Node} container Optional container to render results to. | 72 * @param {Y.Node} container Optional container to render results to. |
71 */ | 73 */ |
72 _renderSearchResults: function(results) { | 74 _renderSearchResults: function(results) { |
73 var target = this.get('renderTo'), | 75 var target = this.get('renderTo'), |
(...skipping 17 matching lines...) Expand all Loading... |
91 * @method apiFailure | 93 * @method apiFailure |
92 * @param {Object} data the json decoded response text. | 94 * @param {Object} data the json decoded response text. |
93 * @param {Object} request the original io_request object for debugging. | 95 * @param {Object} request the original io_request object for debugging. |
94 * | 96 * |
95 */ | 97 */ |
96 apiFailure: function(data, request) { | 98 apiFailure: function(data, request) { |
97 this._apiFailure(data, request, 'Failed to load search results.'); | 99 this._apiFailure(data, request, 'Failed to load search results.'); |
98 }, | 100 }, |
99 | 101 |
100 /** | 102 /** |
| 103 * General YUI initializer. |
| 104 * |
| 105 * @method initializer |
| 106 * @param {Object} cfg configuration object. |
| 107 * |
| 108 */ |
| 109 initializer: function(cfg) { |
| 110 this.on('activeIDChange', function(ev) { |
| 111 var id = ev.newVal; |
| 112 if (id) { |
| 113 id = this.get('container').one( |
| 114 '.charm-token[data-charmid="' + id + '"]'); |
| 115 } |
| 116 this._updateActive(id); |
| 117 }); |
| 118 }, |
| 119 |
| 120 /** |
101 * Renders the searchview, rendering search results for the view's search | 121 * Renders the searchview, rendering search results for the view's search |
102 * text. | 122 * text. |
103 * | 123 * |
104 * @method render | 124 * @method render |
105 */ | 125 */ |
106 render: function() { | 126 render: function() { |
107 var text = this.get('text'); | 127 var text = this.get('text'); |
108 this.get('store').search(text, { | 128 this.get('store').search(text, { |
109 'success': function(data) { | 129 'success': function(data) { |
110 var results = this.get('store').resultsToCharmlist(data.result); | 130 var results = this.get('store').resultsToCharmlist(data.result); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 }, '0.1.0', { | 169 }, '0.1.0', { |
150 requires: [ | 170 requires: [ |
151 'base-build', | 171 'base-build', |
152 'browser-charm-token', | 172 'browser-charm-token', |
153 'browser-overlay-indicator', | 173 'browser-overlay-indicator', |
154 'event-tracker', | 174 'event-tracker', |
155 'juju-view-utils', | 175 'juju-view-utils', |
156 'view' | 176 'view' |
157 ] | 177 ] |
158 }); | 178 }); |
OLD | NEW |