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:
aa2c1028
     'click .js-close': 'fireCloseChatTrigger'
d5ab0abf
     'click a div': 'switchChatWindow'
6a6ccd01
 
   initialize: () ->
     _.bindAll(this)
bdf5dc64
     @active = false
6a6ccd01
 
aa2c1028
     Backbone.Events.on('closeChat', (chat) =>
       if chat == @model
         @destroy()
     )
 
56a05761
     @model.get('who').on('change:name', @render)
 
aa2c1028
   fireCloseChatTrigger: ->
     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()
 
   destroy: ->
     App.debug 'destroy chatWindow and tab'
bdf5dc64
     if @active
       @chatWindow.remove()
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')