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: |
94bd8368 |
'click .invite': 'inviteToMultichat' |
aa2c1028 |
'click .kick': 'kickFromMultiChat' |
dc7e418a |
'click .multichat': 'newMultiChat' |
37ab3198 |
'click .make-owner': 'switchOwner' |
41661541 |
click: 'startChat'
mouseover: 'showIcons'
mouseleave: 'hideIcons' |
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 |
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 |
|
94bd8368 |
inviteToMultichat: (e) -> |
99070cca |
e.stopPropagation() |
94bd8368 |
App.debug 'iniviting to multichat' |
296dd1c6 |
multichat = App.Collections.chats.activeChat
if not multichat or not multichat.get('isMultiChat')
return
App.Com.inviteToChat(multichat, @model, App.Models.me.get('jid')) |
94bd8368 |
newMultiChat: (e) -> |
99070cca |
e.stopPropagation() |
94bd8368 |
App.debug 'new multichat'
|
b1c6b359 |
newChat = new Xmpp.Models.Chat(isMultiChat: true)
newChat.set('who', App.Models.me) |
94bd8368 |
|
b1c6b359 |
App.Collections.chats.add(newChat) |
296dd1c6 |
App.Com.openNewMultiChat(App.Models.me, @model, newChat) |
94bd8368 |
|
aa2c1028 |
kickFromMultiChat: (e) -> |
99070cca |
e.stopPropagation() |
aa2c1028 |
App.debug 'kick him from multichat!'
multichat = App.Collections.chats.activeChat |
37ab3198 |
if not multichat or (multichat and not multichat.get('isMultiChat')) |
aa2c1028 |
return
App.Com.kickFromMultichat(multichat.get('chatId'), App.Models.me.get('jid'), @model.get('jid'))
App.Collections.contacts.moveToInactiveList(@model)
|
37ab3198 |
switchOwner: (e) ->
e.stopPropagation()
App.debug 'make him new multichat owner'
multichat = App.Collections.chats.activeChat
if not multichat or (multichat and not multichat.get('isMultiChat'))
return
App.Com.switchMultiChatOwner(App.Models.me.get('jid'), @model.get('jid'), multichat.get('chatId'))
|
1f685c13 |
openChatById: (chatId) -> |
aa2c1028 |
App.Collections.chats.findById(chatId) |
41661541 |
showIcons: -> |
dc7e418a |
activeChat = App.Collections.chats.activeChat
|
37ab3198 |
$(@el).find('.action .multichat, .action .invite, .action .kick, .action .make-owner').hide() |
dc7e418a |
|
aa2c1028 |
if (@model.get('usingMyApp')) |
dc7e418a |
if not activeChat or not activeChat.get('isMultiChat')
$(@el).find('.action .multichat').show()
else if activeChat.get('isMultiChat') and activeChat.isMeOwner() and not activeChat.isAttending(@model)
$(@el).find('.action .invite').show()
else if activeChat.get('isMultiChat') and activeChat.isMeOwner()
$(@el).find('.action .kick').show() |
37ab3198 |
$(@el).find('.action .make-owner').show() |
dc7e418a |
|
41661541 |
hideIcons: -> |
37ab3198 |
$(@el).find('.action .multichat, .action .invite, .action .kick, .action .make-owner').hide() |