|
1 | 1 | var View = require('ampersand-view'); |
2 | 2 | var debug = require('debug')('scout-ui:home'); |
3 | | -var models = require('../models'); |
4 | 3 |
|
5 | | -var ListFilter = View.extend({ |
| 4 | +var CollectionFilterView = View.extend({ |
| 5 | + template: require('./collection-filter.jade'), |
6 | 6 | props: { |
7 | 7 | search: 'string' |
8 | 8 | }, |
9 | 9 | initialize: function() { |
10 | 10 | this.listenTo(this, 'change:search', this.applyFilter); |
11 | 11 | }, |
12 | | - template: require('./list-filter.jade'), |
| 12 | + events: { |
| 13 | + 'input [data-hook=search]': 'handleInputChanged' |
| 14 | + }, |
13 | 15 | render: function() { |
14 | 16 | this.renderWithTemplate(this); |
15 | | - this.input = this.queryByHook('search'); |
| 17 | + this.cacheElements({ |
| 18 | + 'input': '[data-hook=search]' |
| 19 | + }); |
16 | 20 | this.input.addEventListener('input', this.handleInputChanged.bind(this), false); |
17 | 21 | }, |
18 | 22 | handleInputChanged: function() { |
19 | 23 | this.search = this.input.value.trim(); |
20 | 24 | }, |
21 | 25 | applyFilter: function() { |
22 | | - debug('search is now', this.search); |
23 | | - this.parent.filter(this.search); |
| 26 | + this.parent.filterCollections(this.search); |
24 | 27 | } |
25 | 28 | }); |
26 | 29 |
|
27 | 30 | // @todo: Keyboard nav: up/down: change active item, right: -> show collection, left: -> hide collection |
28 | | -var CollectionsList = View.extend({ |
| 31 | +var CollectionListView = View.extend({ |
29 | 32 | template: '<ul class="list-group" data-hook="collections"></ul>', |
30 | 33 | ItemView: View.extend({ |
31 | 34 | bindings: { |
@@ -54,34 +57,60 @@ var CollectionsList = View.extend({ |
54 | 57 | } |
55 | 58 | }); |
56 | 59 |
|
| 60 | + |
| 61 | +var SidebarControlView = CollectionFilterView.extend({ |
| 62 | + template: require('./sidebar-controls.jade'), |
| 63 | + applyFilter: function() { |
| 64 | + this.parent.filterFields(this.search); |
| 65 | + } |
| 66 | +}); |
| 67 | + |
| 68 | + |
57 | 69 | module.exports = View.extend({ |
58 | | - filter: function(pattern) { |
59 | | - var re = new RegExp((pattern || '.*')); |
60 | | - this.collection.filter(function(model) { |
61 | | - return re.test(model.getId()); |
62 | | - }); |
63 | | - }, |
64 | 70 | template: require('./index.jade'), |
65 | 71 | subviews: { |
66 | 72 | collections_filter: { |
67 | | - hook: 'collections-filter', |
| 73 | + hook: 'collection-filter-subview', |
68 | 74 | prepareView: function(el) { |
69 | | - return new ListFilter({ |
| 75 | + return new CollectionFilterView({ |
70 | 76 | el: el, |
71 | 77 | parent: this |
72 | 78 | }); |
73 | 79 | } |
74 | 80 | }, |
75 | 81 | collections: { |
76 | | - hook: 'collections', |
| 82 | + hook: 'collection-list-subview', |
77 | 83 | prepareView: function(el) { |
78 | | - var view = new CollectionsList({ |
| 84 | + var view = new CollectionListView({ |
79 | 85 | el: el, |
80 | 86 | parent: this, |
81 | 87 | collection: this.collection |
82 | 88 | }); |
83 | 89 | return view; |
84 | 90 | } |
| 91 | + }, |
| 92 | + sidebar_control: { |
| 93 | + hook: 'sidebar-control-subview', |
| 94 | + prepareView: function(el) { |
| 95 | + var view = new SidebarControlView({ |
| 96 | + el: el, |
| 97 | + }); |
| 98 | + return view; |
| 99 | + } |
85 | 100 | } |
| 101 | + }, |
| 102 | + filterCollections: function(pattern) { |
| 103 | + var re = new RegExp((pattern || '.*')); |
| 104 | + this.collection.filter(function(model) { |
| 105 | + return re.test(model.getId()); |
| 106 | + }); |
| 107 | + }, |
| 108 | + filterFields: function(pattern) { |
| 109 | + var re = new RegExp((pattern || '.*')); |
| 110 | + // get current field list view |
| 111 | + var fieldListView = this.parent.currentCollectionView.fieldListView; |
| 112 | + fieldListView.collection.filter(function(model) { |
| 113 | + return re.test(model.getId()); |
| 114 | + }); |
86 | 115 | } |
87 | 116 | }); |
0 commit comments