editor: disable drop draft link when there is no draft loaded
[fnpeditor.git] / src / editor / views / openSelect / openSelect.js
1 define(function(require) {
2     
3 'use strict';
4
5 var _ = require('libs/underscore'),
6     $ = require('libs/jquery'),
7     Backbone = require('libs/backbone'),
8     template = require('libs/text!./template.html'),
9     itemTemplate = require('libs/text!./itemTemplate.html');
10
11
12 var OpenSelect = Backbone.View.extend({
13     className: 'openSelect',
14     events: {
15         'click a': 'onSelection',
16     },
17     initialize: function() {
18         this.$el.css('position', 'relative');
19         this.$el.append(_.template(template)({value: this.options.value || ''}));
20         this.$('.toggle').dropdown();
21         this.menu = this.$('.dropdown-menu');
22         if(this.options.inputTemplate) {
23             this.input = $(this.options.inputTemplate);
24             this.$('.input-wrapper').append(this.input);
25         }
26     },
27     addItem: function(value) {
28         this.menu.append(_.template(itemTemplate)({value: value}));
29     },
30     onSelection: function(e) {
31         var val = $(e.target).text();
32         if(this.options.setInput) {
33             this.options.setInput(this.input, val);
34         }
35         this.trigger('itemSelected', this.input.val());
36     }
37 });
38
39 return OpenSelect;
40
41 });