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:
     'click .js-close': 'closeChat'
 
   initialize: () ->
     _.bindAll(this)
bdf5dc64
     @active = false
6a6ccd01
 
   setActive: ->
     $(@el).addClass('active')
bdf5dc64
     @active = true
6a6ccd01
     @render()
 
   setInactive: ->
     $(@el).removeClass('active')
bdf5dc64
     @active = false
6a6ccd01
     @render()
 
   render: ->
     $(@el).html(@template(
       who:      @model.get('who').firstname(),
       withWhom: @model.get('withWhom').firstname()
     ))
     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
   closeChat: ->
b933b434
     @destroy()
bdf5dc64
     Backbone.Events.trigger('closeChat', this, @model)
6a6ccd01
 
   hasParticipants: (who, withWhom) ->
     @model && @model.get('who') == who && @model.get('withWhom') == withWhom