app/assets/javascripts/_main.js.coffee
43b171a9
 this.App =
52ef7688
   debug: (msg) ->
     console.log msg
 
43b171a9
   UI:
1ec65f29
     setAutoHeight: ->
43b171a9
       height = $(window).height()
       $("#height-setter-1").css({height: height - 50})
       $("#height-setter-2").css({height: height - $('#tabbar').outerHeight() - $('#msg-writer').outerHeight() - 57})
ff94bdbf
 
43899b3a
     filterContacts: (searchTerm) ->
       App.Collections.contacts.filter(searchTerm)
 
ff94bdbf
   Com:
b27f285a
     connect: (callback) ->
       App._dispatcher = new WebSocketRails('www.xmpp.dev:3000/websocket')
       App._dispatcher.on_open = =>
         @_setupBackboneComponents()
1f685c13
         @_bindListeners()
b27f285a
         callback?()
ff94bdbf
 
191a317f
     trigger: (options) ->
b27f285a
       _.defaults(options, {data: {} })
ff94bdbf
       App._dispatcher.trigger(options.event, options.data, options.success, options.error)
b27f285a
 
52ef7688
     initRoster: ->
191a317f
       App.Com.trigger(
52ef7688
         event: 'app.roster.initRoster'
         success: (data) ->
6a6ccd01
           _.each(data.contacts, (contact) ->
             newContact = new Xmpp.Models.Contact(
               id: contact.jid
               jid: contact.jid
635339a3
               belongsTo: [contact.belongsTo]
6a6ccd01
             )
635339a3
             App.Collections.contacts.add(newContact, merge: true)
b27f285a
           )
52ef7688
       )
 
     startFetchingVcards: ->
191a317f
       App.Com.trigger(event: 'app.roster.startFetchingVcards')
52ef7688
 
     startPollingRoster: ->
191a317f
       App.Com.trigger(event: 'app.roster.startPolling')
b27f285a
 
1f685c13
     startPollingMessages: ->
       App.Com.trigger(event: 'app.chat.startPollingMessages')
 
43ad79fa
     setPresence: ->
191a317f
       App.Com.trigger(event: 'app.roster.setPresence')
43ad79fa
 
d4872cda
     getMe: ->
       App.Com.trigger(event: 'app.roster.myself', success: (response) ->
4b5bb9c5
         App.Models.me = new Xmpp.Models.Me(
           jid: response.jid
           name: response.vcard.name
           status: response.status
           avatar: response.vcard.avatar
         )
d4872cda
       )
 
31111b63
     sendMessage: (message, to, from, callbackOk, callbackFail) ->
       App.Com.trigger(event: 'app.chat.sendMessage', data: {message: message, to: to, from: from}, success: callbackOk, error: callbackFail)
 
24b129a9
     sendMultiMessage: (message, chatId, from, callbackOk, callbackFail) ->
00f00dbe
       App.Com.trigger(event: 'app.chat.sendMessage', data: {message: message, chatId: chatId, from: from}, success: callbackOk, error: callbackFail)
2a61cdcc
 
31111b63
     openNewMultiChatId: (chatOwner, attendant, chat) ->
       @trigger(event: 'app.chat.newMultiChatId', data: {chatOwner: chatOwner}, success: (response) =>
2a61cdcc
         chat.setChatId(response.id)
31111b63
         @trigger(event: 'app.chat.addToMultiChat', data: {chatOwner: chatOwner, chatId: response.id, jid: attendant} )
424fd46f
       )
 
24b129a9
     syncMultiChatContacts: (me, chatId) ->
       @trigger(event: 'app.chat.syncMultiChatContacts', data: {me: me, chatId: chatId}, success: (contacts) =>
         App.debug contacts
       )
 
c4a1e746
     updateMyStatus: (message, state)->
       App.Com.trigger(event: 'app.roster.updateMyStatus', data: {message: message, state: state})
 
635339a3
     removeContactRemote: (contact, client) ->
       App.Com.trigger(event: 'app.roster.removeContact', data: {jid: contact, client: client})
 
b27f285a
     _setupBackboneComponents: ->
6a6ccd01
       App.Collections.contacts = new Xmpp.Collections.ContactsCollection()
       App.Collections.chats = new Xmpp.Collections.ChatsCollection()
 
       App.Views.tabbar = new Xmpp.Views.Tabbar.TabbarView()
b27f285a
 
1f685c13
     _bindListeners: ->
52ef7688
       App._dispatcher.bind('app.roster.statusChanged', (result) ->
         App.debug 'change contact state'
6a6ccd01
         App.Collections.contacts.updateStatus(result)
52ef7688
       )
 
       App._dispatcher.bind('app.roster.vcard', (result) ->
         App.debug 'got vcard'
6a6ccd01
         App.Collections.contacts.udpateVcard(result)
52ef7688
       )
 
635339a3
       App._dispatcher.bind('app.roster.subscriptionChanged', (subscription) ->
         App.debug 'subscription changed'
         App.Collections.contacts.subscriptionChanged(subscription)
       )
 
1f685c13
       App._dispatcher.bind('app.chat.messageReceived', (result) ->
         App.debug 'message received'
 
         contact = App.Collections.contacts.findByJid(result.from)
 
         if contact
           contactView = App.Collections.contacts.friendsList.hasContact(contact) ||
             App.Collections.contacts.activeList.hasContact(contact)
         else
           contact = new Xmpp.Models.Contact(
             id: result.from
             jid: result.from
             belongsTo: [result.to]
           )
           App.Collections.contacts.add(contact, merge: true)
           contactView = App.Collections.contacts.friendsList.hasContact(contact)
 
         contactView.startChat()
 
         tab = _.find(App.Views.tabbar.tabs, (tab) ->
           tab.hasParticipants(App.Models.me, contact)
         )
 
         tab.chatWindow.appendMessage(contact, new Date(), result.message)
 
 #        if (result.chat_id)
 #          #todo otvorit chat podla chat_id. Spytat sa servera, kto vsetko je ucastnikom
 #          #chat = App.Collections.chats.findById(result.chat_id)
       )
 
d4872cda
   Models:
     me: null
 
b27f285a
   Collections:
6a6ccd01
     contacts: null
     chats: null
 
   Views:
     tabbar: null
     chat: null