@@ -10,12 +10,40 @@ window.Kandan =
10
10
Collections : {}
11
11
Views : {}
12
12
Routers : {}
13
+ Broadcasters : {}
13
14
init : ->
14
- # new Kandan.Routers.Main()
15
15
# Backbone.history.start({pushState: true})
16
- chat_area = new Kandan.Views.ChatArea ()
17
- $ (' .container' ).html (chat_area .render ().el )
18
- # $('.container').append(chat_box)
16
+ channels = new Kandan.Collections.Channels ()
17
+ channels .fetch ({success : ()=>
18
+
19
+ chat_area = new Kandan.Views.ChatArea ({channels : channels})
20
+ $ (' .container' ).html (chat_area .render ().el )
21
+
22
+ chatbox = new Kandan.Views.Chatbox ()
23
+ $ (' .container' ).append (chatbox .render ().el )
24
+
25
+ # TODO move this to a helper
26
+ # can also be done by checking the active tab in the post event in the Chatbox view
27
+ $ (' #channels' ).tabs ({
28
+ select : (event , ui )->
29
+ channel_id = $ (" #channels .ui-tabs-panel" ).eq (" #{ ui .index } " ).data (' channel_id' )
30
+ console .log " set channelID to" , channel_id
31
+ # TODO move setting current channel ID to a seperate helper
32
+ $ (' .chatbox' ).data (' active_channel_id' , channel_id)
33
+ })
34
+
35
+ # TODO move broadcast subscription to a helper
36
+ # TODO change this to use the broadcaster from the settings
37
+ # TODO set as global to debug. remove later.
38
+ window .broadcaster = new Kandan.Broadcasters.FayeBroadcaster ()
39
+ for channel in channels .models
40
+ window .broadcaster .subscribe " /channels/#{ channel .get (' id' )} "
41
+
42
+ # TODO move this to a helper
43
+ $ (' .chatbox' ).data (' active_channel_id' ,
44
+ $ (" #channels .ui-tabs-panel" ).eq ($ (' #channels' ).tabs (' option' , ' selected' )).data (' channel_id' ))
45
+ })
46
+
19
47
20
48
$ (document ).ready ->
21
49
Kandan .init ()
0 commit comments