forked from maccman/holla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.js
More file actions
96 lines (75 loc) · 1.87 KB
/
Copy pathsettings.js
File metadata and controls
96 lines (75 loc) · 1.87 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function($){
var Channels = Spine.Controller.create({
tag: "li",
proxied: ["render", "remove"],
events: {
"click .destroy": "destroy",
"dblclick .view": "edit",
"keypress input": "blurOnEnter",
"blur input": "close"
},
elements: {
"input": "input"
},
init: function(){
this.item.bind("update", this.render);
this.item.bind("destroy", this.remove);
},
template: function(data){
return($("#editChannelTemplate").tmpl(data));
},
render: function(){
this.el.html(this.template(this.item));
this.refreshElements();
return this;
},
edit: function(){
this.el.addClass("editing");
this.input.focus();
},
blurOnEnter: function(e) {
if (e.keyCode == 13) e.target.blur();
},
close: function(){
this.el.removeClass("editing");
this.item.updateAttributes({name: this.input.val()});
},
remove: function(){
this.el.remove();
},
destroy: function(){
if (confirm("Are you sure you want to delete this channel?"))
this.item.destroy();
}
});
window.Settings = Spine.Controller.create({
elements: {
".channels": "channelsEl",
".createChannel input": "input"
},
events: {
"submit .createChannel form": "create"
},
proxied: ["addAll", "addOne", "active"],
init: function(){
Channel.bind("refresh", this.addAll);
Channel.bind("create", this.addOne);
this.App.bind("change:settings", this.active);
},
addOne: function(item){
var channel = Channels.init({item: item});
this.channelsEl.append(channel.render().el);
},
addAll: function(){
this.channelsEl.empty();
Channel.each(this.addOne);
},
create: function(){
var value = this.input.val();
if ( !value ) return false;
Channel.create({name: value});
this.input.val("");
return false;
}
});
})(jQuery);