1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
var Selector = View.extend({
el: "#selector",
template: $("#selector .template").html(),
events: {
"click .close": "hide",
"click .options div": "pick",
},
initialize: function(){
this.$options = this.$(".options")
},
lookup: null,
callback: null,
select: function(options, callback){
this.lookup = {}
this.callback = callback || function(item){ console.log(item) }
this.$options.empty()
options.forEach(function(opt){
this.lookup[String(opt.id)] = opt
var t = this.template.replace(/{{id}}/, opt.id)
.replace(/{{label}}/, opt.label)
this.$options.append(t)
}.bind(this))
this.$el.show()
app.curtain.show("white")
this.visible = true
},
hide: function(){
this.lookup = this.callback = null
this.$el.hide()
app.curtain.hide()
this.visible = false
},
pick: function(e){
var $option = $(e.currentTarget)
var id = String($option.data("id"))
var selection = this.lookup[id]
this.callback( selection )
this.hide()
},
})
|