/
channel_tabs.js.coffee
41 lines (36 loc) · 1.06 KB
/
channel_tabs.js.coffee
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
class Kandan.Views.ChannelTabs extends Backbone.View
template: JST['channel_tabs']
tagName: 'ul'
render: ()->
$(@el).html @template({channels: @options.channels})
@
createChannel: (event)->
names = [
"A Dark Place",
"Discotheque",
"Dungeon",
"Garden",
"Lobby",
"Office",
"Palace",
"Park",
"Studio",
"Temple",
"War Room",
"Zork"]
# Inefficient random method but there are only a few names so it's
# not an issue
name = _.shuffle(names)[0]
channelName = prompt("What's the channel name?", name)
channelName = channelName.replace(/^\s+|\s+$/g, '')
if channelName
channel = new Kandan.Models.Channel({name: channelName})
channel.save({}, {
error: (model, response)->
_.each(JSON.parse(response.responseText), alert);
})
return false
deleteChannel: (event)->
channelIndex = $(event.target).parents('li').prevAll().length
Kandan.Helpers.Channels.deleteChannelByTabIndex(channelIndex) if channelIndex != 0
return false