app/assets/javascripts/backbone/views/contacts/contact.js.coffee
b27f285a
 Xmpp.Views.Contacts ||= {}
 
 class Xmpp.Views.Contacts.ContactView extends Backbone.View
   template: JST["backbone/templates/contacts/contact"]
52ef7688
   tagName: 'li'
   className: 'clear user'
b27f285a
 
6a6ccd01
   events:
6723d1f9
     click: 'startChat'
b27f285a
 
   initialize: () ->
     _.bindAll(this)
 
e2e90aca
 #    Patrim nejakemu zoznamu
52ef7688
     @parentList = @attributes['listView']
b27f285a
 
6723d1f9
     @model.on('change', @updateContact)
c4a05fed
     @model.on('change:status', => @parentList.reOrder())
52ef7688
 
   updateContact: (contact) ->
     @model = contact
b27f285a
     @render()
 
43899b3a
   hide: ->
     $(@el).hide()
 
   unhide: ->
     $(@el).show()
 
b27f285a
   render: ->
     contact = @model.toJSON()
52ef7688
     $(@el).html(@template(contact))
6a6ccd01
     return this
 
e2e90aca
   belongsToActiveList: ->
     @parentList.activeGroup == true
 
bcce524b
   startChat: ->
e2e90aca
     if @belongsToActiveList()
       return
 
     who      = App.Models.me
6a6ccd01
     withWhom = @model
 
     App.debug ['opening chat with: ', who.get('jid'), withWhom.get('jid')]
 
     chat = App.Collections.chats.find(who, withWhom)
     if (! chat)
bcce524b
       App.debug ['not found in opened chats, creating new']
6a6ccd01
       chat = new Xmpp.Models.Chat(who: who, withWhom: withWhom)
       App.Collections.chats.add(chat)
 
bcce524b
     Backbone.Events.trigger('openChat', chat)
6a6ccd01