Browse code

Pouzivanie eventov vo vacsej miere

Cinan Rakosnik authored on 27/03/2013 at 07:55:49
Showing 5 changed files
... ...
@@ -15,7 +15,10 @@ class Xmpp.Collections.ChatsCollection extends Backbone.Collection
15 15
   initialize: ->
16 16
     _.bindAll(this)
17 17
 
18
-    @on("add", @newChat)
18
+    @on('add', @newChat)
19
+    Backbone.Events.on('closeChat', (tab, chat) =>
20
+      @removeChat(chat)
21
+    )
19 22
 
20 23
   newChat: (chat) ->
21 24
 #    App.debug ['adding chat to chatCollection', chat]
... ...
@@ -30,7 +30,16 @@ class Xmpp.Collections.ContactsCollection extends Backbone.Collection
30 30
     @activeList  = new Xmpp.Views.Contacts.ListView(collection: this, attributes: {title: 'chat.roster.chat-group', id: 'js-active-friends'})
31 31
     @activeList.setAsActiveChatGroup()
32 32
 
33
-    @on("add", @appendContact)
33
+    @on('add', @appendContact)
34
+
35
+    Backbone.Events.on('openChat', (chat) =>
36
+      @moveToInactiveList('all')
37
+      @moveToActiveList(chat.get('withWhom'))
38
+    )
39
+
40
+    Backbone.Events.on('closeChat', (tab, chat) =>
41
+      @moveToInactiveList(chat.get('withWhom'))
42
+    )
34 43
 
35 44
   appendContact: (contact) ->
36 45
     @friendsList.appendContact(contact)
... ...
@@ -28,7 +28,7 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View
28 28
   belongsToActiveList: ->
29 29
     @parentList.activeGroup == true
30 30
 
31
-  startChat: (event) ->
31
+  startChat: ->
32 32
     if @belongsToActiveList()
33 33
       return
34 34
 
... ...
@@ -39,14 +39,9 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View
39 39
 
40 40
     chat = App.Collections.chats.find(who, withWhom)
41 41
     if (! chat)
42
-#      App.debug ['not found in opened chats, creating new', chat]
42
+      App.debug ['not found in opened chats, creating new']
43 43
       chat = new Xmpp.Models.Chat(who: who, withWhom: withWhom)
44 44
       App.Collections.chats.add(chat)
45 45
 
46
-    App.Views.tabbar.addOrSelect(chat)
47
-    App.Collections.contacts.moveToInactiveList('all')
48
-    App.Collections.contacts.moveToActiveList(withWhom)
49
-#    @openChat(chat)
50
-
51
-  openChat: (chat) ->
46
+    Backbone.Events.trigger('openChat', chat)
52 47
 
... ...
@@ -27,9 +27,7 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View
27 27
     return this
28 28
 
29 29
   closeChat: ->
30
-    App.Views.tabbar.removeTab(this)
31
-    App.Collections.chats.removeChat(@model)
32
-    App.Collections.contacts.moveToInactiveList(@model.get('withWhom'))
30
+    Backbone.Events.trigger('closeChat', this, @model)
33 31
     @remove()
34 32
 
35 33
   hasParticipants: (who, withWhom) ->
... ...
@@ -7,6 +7,9 @@ class Xmpp.Views.Tabbar.TabbarView extends Backbone.View
7 7
   initialize: () ->
8 8
     _.bindAll(this)
9 9
 
10
+    Backbone.Events.on('openChat', @addOrSelect)
11
+                   .on('closeChat', @removeTab)
12
+
10 13
     @tabs = []
11 14
     @render()
12 15