3 var Marionette
= require('backbone.marionette');
4 var Typeahead
= require('../controls//typeahead');
5 var SimpleFilteredCollection
= require('gitter-realtime-client/lib/simple-filtered-collection');
7 var FilteredSelect
= Marionette
.ItemView
.extend({
14 initialize: function(options
) {
15 this.filter
= options
.filter
;
16 this.collection
= options
.collection
;
17 this.itemTemplate
= options
.itemTemplate
;
18 this.dropdownClass
= options
.dropdownClass
;
20 this.filteredCollection
= new SimpleFilteredCollection([], {
21 collection
: this.collection
23 this.refilter('', this.filteredCollection
);
25 this.typeahead
= new Typeahead({
27 disableShowOnAdd
: true,
28 disableListenToChange
: true,
31 collection
: this.filteredCollection
,
32 itemTemplate
: this.itemTemplate
,
33 dropdownClass
: this.dropdownClass
,
34 fetch
: this.refilter
.bind(this),
35 autoSelector: function(input
) {
36 return function(model
) {
37 this.filter(input
, model
);
42 this.listenTo(this.typeahead
, 'selected', this.selected
);
43 this.listenTo(this.collection
, 'add remove change reset sync', this.reset
);
46 getSelected: function() {
47 return this.selectedGroup
;
50 selected: function(item
) {
52 this.trigger('selected', item
);
55 onDestroy: function() {
56 this.typeahead
.destroy();
59 onActivate: function() {
67 this.typeahead
.show();
73 this.typeahead
.hide();
77 refilter: function(input
, collection
, success
) {
80 return this.filter(input
, model
);
84 if (success
) success();
88 module
.exports
= FilteredSelect
;