| ... | ... |
@@ -10,13 +10,16 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View |
| 10 | 10 |
|
| 11 | 11 |
initialize: () -> |
| 12 | 12 |
_.bindAll(this) |
| 13 |
+ @active = false |
|
| 13 | 14 |
|
| 14 | 15 |
setActive: -> |
| 15 | 16 |
$(@el).addClass('active')
|
| 17 |
+ @active = true |
|
| 16 | 18 |
@render() |
| 17 | 19 |
|
| 18 | 20 |
setInactive: -> |
| 19 | 21 |
$(@el).removeClass('active')
|
| 22 |
+ @active = false |
|
| 20 | 23 |
@render() |
| 21 | 24 |
|
| 22 | 25 |
render: -> |
| ... | ... |
@@ -37,7 +40,8 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View |
| 37 | 37 |
|
| 38 | 38 |
destroy: -> |
| 39 | 39 |
App.debug 'destroy chatWindow and tab' |
| 40 |
- @chatWindow.remove() |
|
| 40 |
+ if @active |
|
| 41 |
+ @chatWindow.remove() |
|
| 41 | 42 |
@remove() |
| 42 | 43 |
|
| 43 | 44 |
hideChat: -> |
| ... | ... |
@@ -45,8 +49,8 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View |
| 45 | 45 |
@chatWindow.hide(); |
| 46 | 46 |
|
| 47 | 47 |
closeChat: -> |
| 48 |
- Backbone.Events.trigger('closeChat', this, @model)
|
|
| 49 | 48 |
@destroy() |
| 49 |
+ Backbone.Events.trigger('closeChat', this, @model)
|
|
| 50 | 50 |
|
| 51 | 51 |
hasParticipants: (who, withWhom) -> |
| 52 | 52 |
@model && @model.get('who') == who && @model.get('withWhom') == withWhom
|
| ... | ... |
@@ -11,7 +11,16 @@ class Xmpp.Views.Tabbar.TabbarView extends Backbone.View |
| 11 | 11 |
@hideCurrentChatWindow() |
| 12 | 12 |
@addOrSelect(chat) |
| 13 | 13 |
) |
| 14 |
- Backbone.Events.on('closeChat', @removeTab)
|
|
| 14 |
+ Backbone.Events.on('closeChat', (tab, chatModel) =>
|
|
| 15 |
+ @removeTab(tab) |
|
| 16 |
+ |
|
| 17 |
+ if tab == @activeTab |
|
| 18 |
+ firstTab = @selectFirstTab() |
|
| 19 |
+ if firstTab |
|
| 20 |
+ App.debug 'fire openChat' |
|
| 21 |
+ Backbone.Events.trigger('openChat', firstTab.model)
|
|
| 22 |
+ #TODO: vybrat naposledy pouzity tab |
|
| 23 |
+ ) |
|
| 15 | 24 |
|
| 16 | 25 |
@tabs = [] |
| 17 | 26 |
@activeTab = null |
| ... | ... |
@@ -49,3 +58,6 @@ class Xmpp.Views.Tabbar.TabbarView extends Backbone.View |
| 49 | 49 |
render: -> |
| 50 | 50 |
$(@el).html(@template()) |
| 51 | 51 |
return this |
| 52 |
+ |
|
| 53 |
+ selectFirstTab: -> |
|
| 54 |
+ _.first(@tabs) |
|
| 52 | 55 |
\ No newline at end of file |