Files
Lentolaskuri/app/scripts/views/leginput.js
2013-05-13 11:43:34 +03:00

40 lines
869 B
JavaScript

'use strict';
define([
'backbone',
'models/leg',
'views/dropdown',
'libs/airports',
'Template'
], function (Backbone, Leg, Dropdown, airports, Template) {
var LegInput = Backbone.View.extend({
el: '.legInputWidget',
events: {
'click button': 'openDropdown'
},
initialize: function () {
this.dropdown = new Dropdown({
el: this.$el.find('input'),
select2: {
initSelection: airports.airportById,
formatResult: Template.choice,
formatSelection: Template.choice,
minimumInputLength: 1,
ajax: airports.ajax
}
});
this.dropdown.bind('new-leg', this.newLeg, this);
},
openDropdown: function () {
this.dropdown.open();
},
newLeg: function (data) {
this.collection.push(new Leg(data));
}
});
return LegInput;
});