Browse code

FIX: spravne skryvanie tabov a preskupovanie ludi do aktivnej skupiny

Cinan Rakosnik authored on 23/05/2013 at 13:04:57
Showing 4 changed files
... ...
@@ -12,6 +12,7 @@ this.App =
12 12
 
13 13
   UI:
14 14
     setAutoHeight: ->
15
+      App.debug 'resizing'
15 16
       App.UI.resizeRoster()
16 17
       App.UI.resizeMessages()
17 18
 
... ...
@@ -53,10 +53,6 @@ class Xmpp.Collections.ContactsCollection extends Backbone.Collection
53 53
       Backbone.Events.trigger('resizeWorkspace')
54 54
     )
55 55
 
56
-    Backbone.Events.on('closeChat', (chat) =>
57
-      @moveToInactiveList('all')
58
-    )
59
-
60 56
   appendContact: (contact) ->
61 57
     App.debug ['apppend', contact]
62 58
     @friendsList.appendContact(contact)
... ...
@@ -6,21 +6,28 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View
6 6
   className: 'tab'
7 7
 
8 8
   events:
9
-    'click .js-close': 'fireCloseChatTrigger'
9
+    'click .js-close': 'closeChat'
10 10
     'click a div': 'switchChatWindow'
11 11
 
12 12
   initialize: () ->
13 13
     _.bindAll(this)
14 14
     @active = false
15
+    @isClosingTab = false
15 16
 
16 17
     Backbone.Events.on('closeChat', (chat) =>
17
-      if chat == @model
18
-        @destroy()
18
+      if not @isClosingTab
19
+        if chat == @model
20
+          @destroy()
19 21
     )
20 22
 
21 23
     @model.get('who').on('change:name', @render)
22 24
 
23
-  fireCloseChatTrigger: ->
25
+  closeChat: ->
26
+    # zatvorenie musi prebehnut ako prva akcia,
27
+    # lebo zavisi na poradi a eventy mi nezarucia spravne poradie
28
+    @destroy()
29
+
30
+    @isClosingTab = true
24 31
     Backbone.Events.trigger('closeChat', @model)
25 32
 
26 33
   setActive: ->
... ...
@@ -57,9 +64,10 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View
57 57
     @chatWindow.render()
58 58
 
59 59
   destroy: ->
60
-    App.debug 'destroy chatWindow and tab'
61 60
     if @active
61
+      App.debug 'destroy chatWindow'
62 62
       @chatWindow.remove()
63
+    App.debug 'destroy tab'
63 64
     @remove()
64 65
 
65 66
   hideChat: ->
... ...
@@ -17,7 +17,12 @@ class Xmpp.Views.Tabbar.TabbarView extends Backbone.View
17 17
         _tab.model == chat
18 18
       )
19 19
 
20
-      @closeTab(tab) if tab
20
+      if tab
21
+        @removeTab(tab)
22
+
23
+        if tab == @activeTab
24
+          App.Collections.contacts.moveToInactiveList('all')
25
+          @openFirstTab()
21 26
     )
22 27
 
23 28
     Backbone.Events.on('removeContact', (contact) =>
... ...
@@ -58,15 +63,9 @@ class Xmpp.Views.Tabbar.TabbarView extends Backbone.View
58 58
       App.debug 'zakryvam chat window'
59 59
       @activeTab.hideChat()
60 60
 
61
-  closeTab: (tab) ->
62
-    @removeTab(tab)
63
-
64
-    if tab == @activeTab
65
-      firstTab = @selectFirstTab()
66
-      if firstTab
67
-        App.debug 'fire openChat'
68
-        Backbone.Events.trigger('openChat', firstTab.model)
69
-    #TODO: vybrat naposledy pouzity tab
61
+  openFirstTab: ->
62
+    firstTab = @selectFirstTab()
63
+    Backbone.Events.trigger('openChat', firstTab.model) if firstTab
70 64
 
71 65
   removeTab: (tab) ->
72 66
     @tabs = _.without(@tabs, tab)
... ...
@@ -76,4 +75,7 @@ class Xmpp.Views.Tabbar.TabbarView extends Backbone.View
76 76
     return this
77 77
 
78 78
   selectFirstTab: ->
79
-    _.first(@tabs)
80 79
\ No newline at end of file
80
+    _.first(@tabs)
81
+
82
+  isEmpty: ->
83
+    _.isEmpty(@tabs)
81 84
\ No newline at end of file