b27f285a |
Xmpp.Views.Contacts ||= {}
class Xmpp.Views.Contacts.ListView extends Backbone.View
template: JST["backbone/templates/contacts/contact_list"]
initialize: () ->
_.bindAll(this)
@el = '#' + @attributes['id'] |
619ceb7d |
@title = I18n.t(@attributes['title']) |
b27f285a |
|
e2e90aca |
@titleClass = @listClass = ''
@activeGroup = false |
52ef7688 |
@contactViews = [] |
b27f285a |
|
52ef7688 |
createListContainer: -> |
e2e90aca |
$(@el).html(@template(title: @title, isActiveGroup: @activeGroup)) |
b27f285a |
|
52ef7688 |
appendContact: (contact) -> |
e2e90aca |
if @hasContact(contact)
return false
if @contactViews.length == 0
@createListContainer()
|
52ef7688 |
view = new Xmpp.Views.Contacts.ContactView(model: contact, attributes: {listView: this})
@contactViews.push view
@render(view.render().el)
|
e2e90aca |
detachContact: (contact) ->
matchingView = @hasContact(contact)
if matchingView
@contactViews = _.without(@contactViews, matchingView)
matchingView.remove()
if @contactViews.length == 0
$(@el).html('')
return !!matchingView
hasContact: (contact) ->
_.find(@contactViews, (view) ->
view.model == contact
)
setAsActiveChatGroup: ->
@activeGroup = true
|
52ef7688 |
render: (contactHtml) ->
if (contactHtml?)
$(@el).find('ul').append(contactHtml)
else
_.each(@contactViews, (i, contact) =>
@render(contact.render().el)
)
return this |