app/assets/javascripts/backbone/views/tabbar/tab.js.coffee
6a6ccd01
 Xmpp.Views.Tabbar ||= {}
 
 class Xmpp.Views.Tabbar.TabView extends Backbone.View
   template: JST["backbone/templates/tabbar/tab"]
   tagName: 'div'
   className: 'tab'
 
   events:
aaf9bd82
     'click .js-close': 'closeChat'
d5ab0abf
     'click a div': 'switchChatWindow'
6a6ccd01
 
   initialize: () ->
     _.bindAll(this)
bdf5dc64
     @active = false
aaf9bd82
     @isClosingTab = false
6a6ccd01
 
aa2c1028
     Backbone.Events.on('closeChat', (chat) =>
aaf9bd82
       if not @isClosingTab
         if chat == @model
           @destroy()
aa2c1028
     )
 
56a05761
     @model.get('who').on('change:name', @render)
 
aaf9bd82
   closeChat: ->
     # zatvorenie musi prebehnut ako prva akcia,
     # lebo zavisi na poradi a eventy mi nezarucia spravne poradie
     @destroy()
 
     @isClosingTab = true
aa2c1028
     Backbone.Events.trigger('closeChat', @model)
 
6a6ccd01
   setActive: ->
     $(@el).addClass('active')
bdf5dc64
     @active = true
6a6ccd01
     @render()
 
   setInactive: ->
     $(@el).removeClass('active')
bdf5dc64
     @active = false
6a6ccd01
     @render()
 
   render: ->
94bd8368
     if (@model.get('isMultiChat'))
       $(@el).html(@template(
         who:       @model.get('who').firstname(),
         multiChat: true
       ))
     else
       $(@el).html(@template(
         who:       @model.get('who').firstname(),
         withWhom:  @model.get('withWhom').firstname(),
         multiChat: false
       ))
6a6ccd01
     return this
 
b933b434
   showChat: ->
     if !@chatWindow
       @chatWindow = new Xmpp.Views.Chat.WindowView(attributes: {tab: this})
       App.debug 'zobrazujem NOVY chat window'
     else
       App.debug 'zobrazujem EXISTUJUCI chat window'
 
     @chatWindow.render()
8f97ca90
     Backbone.Events.trigger('resizeWorkspace')
b933b434
 
   destroy: ->
bdf5dc64
     if @active
aaf9bd82
       App.debug 'destroy chatWindow'
bdf5dc64
       @chatWindow.remove()
aaf9bd82
     App.debug 'destroy tab'
b933b434
     @remove()
 
   hideChat: ->
     if @chatWindow
       @chatWindow.hide();
 
6a6ccd01
   hasParticipants: (who, withWhom) ->
     @model && @model.get('who') == who && @model.get('withWhom') == withWhom
d5ab0abf
 
   switchChatWindow: ->
424fd46f
     Backbone.Events.trigger('openChat', @model)
e1b7175e
     Backbone.Events.trigger('resizeWorkspace')
424fd46f
 
   getOwner: ->
2a61cdcc
     @model.get('who')
 
   getChatId: ->
31111b63
     @model.get('chatId')
 
   getAttendant: ->
     @model.get('withWhom')