6a6ccd01 |
Xmpp.Views.Tabbar ||= {}
class Xmpp.Views.Tabbar.TabbarView extends Backbone.View
template: JST["backbone/templates/tabbar/tabbar"]
el: $('#js-tabbar')
initialize: () ->
_.bindAll(this)
|
b933b434 |
Backbone.Events.on('openChat', (chat) =>
@hideCurrentChatWindow()
@addOrSelect(chat)
)
Backbone.Events.on('closeChat', @removeTab) |
bcce524b |
|
6a6ccd01 |
@tabs = [] |
b933b434 |
@activeTab = null |
6a6ccd01 |
@render()
addOrSelect: (chat) ->
tab = _.find(@tabs, (tab) ->
tab.hasParticipants(chat.get('who'), chat.get('withWhom'))
)
if (!! tab)
App.debug 'selecting existing tab'
else
App.debug 'adding new tab'
tab = new Xmpp.Views.Tabbar.TabView(model: chat)
@tabs.push tab
$(@el).append(tab.render().el)
_.each(@tabs, (tab) ->
tab.setInactive()
)
|
b933b434 |
@activeTab = tab
@activeTab.setActive()
@activeTab.showChat()
# App.debug ['aktivny tab: ', @activeTab]
hideCurrentChatWindow: ->
if @activeTab
App.debug 'zakryvam chat window'
@activeTab.hideChat() |
6a6ccd01 |
removeTab: (tab) -> |
b933b434 |
# if @activeTab && @activeTab == tab
# App.debug 'nicim tab aj chat window'
# @activeTab.destroy()
|
6a6ccd01 |
@tabs = _.without(@tabs, tab)
render: -> |
b933b434 |
$(@el).html(@template()) |
6a6ccd01 |
return this |