forked from buddycloud/buddycloud-webclient-discontinuted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.coffee
77 lines (61 loc) · 2.31 KB
/
show.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
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
{ ChannelView } = require 'views/channel/show'
{ Channels } = require 'collections/channel'
{ Sidebar } = require 'views/sidebar/show'
class exports.HomeView extends Backbone.View
template: require 'templates/home/show'
initialize: ->
@el = $(@template())
@bind 'show', @show
@bind 'hide', @hide
@current = undefined
# sidebar entries
@views = {} # this contains the channelnode views
@channels = new Channels
app.users.current.channels.bind 'add', (channel) =>
@channels.update channel
app.users.current.channels.forEach (channel) =>
@channels.add channel
@new_channel_view channel
# Attempt to come up with a default channel:
if !@current? and (channel.get('id') is app.users.current.get('id'))
@setCurrentChannel channel
@channels.bind 'change', @new_channel_view
@channels.bind 'add', @new_channel_view
@channels.bind 'all', =>
app.debug "home CHEV-ALL", arguments
# if we already found a view in the cache
@current?.el.show()
@sidebar = new Sidebar(parent: this)
$('body').removeClass('start').append @el
$('.centerBox').remove() # FIXME ugly
@render()
@el.show()
new_channel_view: (channel) =>
unless (view = @views[channel.cid])
view = new ChannelView model:channel, parent:this
@views[channel.cid] = view
@el.append view.el
view.el.hide()
view
setCurrentChannel: (channel) =>
@current?.el.hide()
# Throw away if current user did not subscribe:
oldChannel = @current?.model
if oldChannel and !app.users.current.channels.get(oldChannel.get('id'))?
delete @views[oldChannel.cid]
unless (@current = @views[channel.cid])
@current = @new_channel_view channel
# Indicate url change without routing:
app.router.navigate @current.model.get('id'), false
@sidebar.setCurrentEntry channel
@current.el.show()
render: ->
@current?.render()
@sidebar.render()
show: =>
@render()
@sidebar.moveIn()
@current?.trigger 'show'
hide: =>
@sidebar.moveOut()
@current?.trigger 'hide'