... | ... |
@@ -23,18 +23,39 @@ class Xmpp.Collections.ContactsCollection extends Backbone.Collection |
23 | 23 |
|
24 | 24 |
initialize: -> |
25 | 25 |
_.bindAll(this) |
26 |
- @counter = 0 |
|
26 |
+ |
|
27 | 27 |
@friendsList = new Xmpp.Views.Contacts.ListView(collection: this, attributes: {title: 'chat.roster.friends', id: 'js-inactive-friends'}) |
28 |
-# @activeList = new Xmpp.Views.Contacts.ListView(collection: this, attributes: {title: 'chat.roster.chat-group', id: 'js-active-friends'}) |
|
28 |
+ @friendsList.createListContainer() |
|
29 |
+ |
|
30 |
+ @activeList = new Xmpp.Views.Contacts.ListView(collection: this, attributes: {title: 'chat.roster.chat-group', id: 'js-active-friends'}) |
|
31 |
+ @activeList.setAsActiveChatGroup() |
|
29 | 32 |
|
30 | 33 |
@on("add", @appendContact) |
31 | 34 |
|
32 | 35 |
appendContact: (contact) -> |
33 |
- @counter++ |
|
34 | 36 |
@friendsList.appendContact(contact) |
35 | 37 |
|
38 |
+ moveToActiveList: (contact) -> |
|
39 |
+ @_switchContactBelongingList(@get(contact), @friendsList, @activeList) |
|
40 |
+ |
|
41 |
+ moveToInactiveList: (contact) -> |
|
42 |
+ if contact == 'all' |
|
43 |
+ _.each(@activeList.contactViews, (view) => |
|
44 |
+ @_switchContactBelongingList(view.model, @activeList, @friendsList) |
|
45 |
+ ) |
|
46 |
+ else |
|
47 |
+ @_switchContactBelongingList(@get(contact), @activeList, @friendsList) |
|
48 |
+ |
|
36 | 49 |
updateStatus: (response) -> |
37 | 50 |
@get(response.jid).set(message: response.status.message, status: response.status.status) |
38 | 51 |
|
39 | 52 |
udpateVcard: (response) -> |
40 |
- @get(response.jid).set(name: response.vcard.name, avatar: response.vcard.avatar) |
|
41 | 53 |
\ No newline at end of file |
54 |
+ @get(response.jid).set(name: response.vcard.name, avatar: response.vcard.avatar) |
|
55 |
+ |
|
56 |
+ _switchContactBelongingList: (contact, fromList, toList) -> |
|
57 |
+ if !contact? |
|
58 |
+ false |
|
59 |
+ |
|
60 |
+ fromList.detachContact(contact) && toList.appendContact(contact) |
|
61 |
+ |
|
62 |
+ true |
|
42 | 63 |
\ No newline at end of file |
... | ... |
@@ -11,7 +11,7 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View |
11 | 11 |
initialize: () -> |
12 | 12 |
_.bindAll(this) |
13 | 13 |
|
14 |
- # Patrim nejakemu zoznamu |
|
14 |
+# Patrim nejakemu zoznamu |
|
15 | 15 |
@parentList = @attributes['listView'] |
16 | 16 |
|
17 | 17 |
@model.on('change', @updateContact, this) |
... | ... |
@@ -25,8 +25,14 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View |
25 | 25 |
$(@el).html(@template(contact)) |
26 | 26 |
return this |
27 | 27 |
|
28 |
+ belongsToActiveList: -> |
|
29 |
+ @parentList.activeGroup == true |
|
30 |
+ |
|
28 | 31 |
startChat: (event) -> |
29 |
- who = App.Models.me |
|
32 |
+ if @belongsToActiveList() |
|
33 |
+ return |
|
34 |
+ |
|
35 |
+ who = App.Models.me |
|
30 | 36 |
withWhom = @model |
31 | 37 |
|
32 | 38 |
App.debug ['opening chat with: ', who.get('jid'), withWhom.get('jid')] |
... | ... |
@@ -38,6 +44,8 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View |
38 | 38 |
App.Collections.chats.add(chat) |
39 | 39 |
|
40 | 40 |
App.Views.tabbar.addOrSelect(chat) |
41 |
+ App.Collections.contacts.moveToInactiveList('all') |
|
42 |
+ App.Collections.contacts.moveToActiveList(withWhom) |
|
41 | 43 |
# @openChat(chat) |
42 | 44 |
|
43 | 45 |
openChat: (chat) -> |
... | ... |
@@ -9,18 +9,43 @@ class Xmpp.Views.Contacts.ListView extends Backbone.View |
9 | 9 |
@el = '#' + @attributes['id'] |
10 | 10 |
@title = I18n.t(@attributes['title']) |
11 | 11 |
|
12 |
+ @titleClass = @listClass = '' |
|
13 |
+ @activeGroup = false |
|
12 | 14 |
@contactViews = [] |
13 | 15 |
|
14 |
- @createListContainer() |
|
15 |
- |
|
16 | 16 |
createListContainer: -> |
17 |
- $(@el).html(@template(title: @title)) |
|
17 |
+ $(@el).html(@template(title: @title, isActiveGroup: @activeGroup)) |
|
18 | 18 |
|
19 | 19 |
appendContact: (contact) -> |
20 |
+ if @hasContact(contact) |
|
21 |
+ return false |
|
22 |
+ |
|
23 |
+ if @contactViews.length == 0 |
|
24 |
+ @createListContainer() |
|
25 |
+ |
|
20 | 26 |
view = new Xmpp.Views.Contacts.ContactView(model: contact, attributes: {listView: this}) |
21 | 27 |
@contactViews.push view |
22 | 28 |
@render(view.render().el) |
23 | 29 |
|
30 |
+ detachContact: (contact) -> |
|
31 |
+ matchingView = @hasContact(contact) |
|
32 |
+ if matchingView |
|
33 |
+ @contactViews = _.without(@contactViews, matchingView) |
|
34 |
+ matchingView.remove() |
|
35 |
+ |
|
36 |
+ if @contactViews.length == 0 |
|
37 |
+ $(@el).html('') |
|
38 |
+ |
|
39 |
+ return !!matchingView |
|
40 |
+ |
|
41 |
+ hasContact: (contact) -> |
|
42 |
+ _.find(@contactViews, (view) -> |
|
43 |
+ view.model == contact |
|
44 |
+ ) |
|
45 |
+ |
|
46 |
+ setAsActiveChatGroup: -> |
|
47 |
+ @activeGroup = true |
|
48 |
+ |
|
24 | 49 |
render: (contactHtml) -> |
25 | 50 |
if (contactHtml?) |
26 | 51 |
$(@el).find('ul').append(contactHtml) |
... | ... |
@@ -29,6 +29,7 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View |
29 | 29 |
closeChat: -> |
30 | 30 |
App.Views.tabbar.removeTab(this) |
31 | 31 |
App.Collections.chats.removeChat(@model) |
32 |
+ App.Collections.contacts.moveToInactiveList(@model.get('withWhom')) |
|
32 | 33 |
@remove() |
33 | 34 |
|
34 | 35 |
hasParticipants: (who, withWhom) -> |
... | ... |
@@ -112,10 +112,14 @@ |
112 | 112 |
} |
113 | 113 |
|
114 | 114 |
.active-group { |
115 |
+ @extend .no-left-border; |
|
116 |
+ @extend .left-border; |
|
117 |
+ @extend .border; |
|
118 |
+ |
|
115 | 119 |
margin: 0 -16px 0 -5px; |
116 | 120 |
padding: 8px 10px; |
117 | 121 |
background: white; |
118 |
- border-right: 1px solid #fcfcfc; |
|
122 |
+ border-right: 0 !important; |
|
119 | 123 |
|
120 | 124 |
&::before { |
121 | 125 |
content: ''; |
... | ... |
@@ -15,30 +15,31 @@ |
15 | 15 |
.roster.border.no-top-border.top-border#height-setter-1 |
16 | 16 |
.my-info#js-me |
17 | 17 |
.friends |
18 |
- %h1.group-header.active Chat group |
|
19 |
- %ul.active-group.border.no-left-border.left-border#js-active-friends |
|
20 |
- %li.clear.user |
|
21 |
- .avatar |
|
22 |
- %img{src: 'assets/avatar.png', alt: t("chat.avatar_alt")} |
|
23 |
- %h1 |
|
24 |
- Adam Wolsky |
|
25 |
- %span.status.online.icon-record |
|
26 |
- %h2 co-founder |
|
27 |
- %span.action |
|
28 |
- %span.icon-x-full |
|
29 |
- %span kick |
|
30 |
- %li.clear.user |
|
31 |
- .avatar |
|
32 |
- %img{src: 'assets/avatar.png', alt: t("chat.avatar_alt")} |
|
33 |
- %h1 |
|
34 |
- John Savage |
|
35 |
- %span.status.away.icon-record |
|
36 |
- %h2 web & ui designer |
|
37 |
- %span.action |
|
38 |
- %span.icon-x-full |
|
39 |
- %span kick |
|
40 |
- %span.icon-bubbles |
|
41 |
- %span invite |
|
18 |
+ #js-active-friends |
|
19 |
+ -#%h1.group-header.active Chat group |
|
20 |
+ -#%ul.active-group |
|
21 |
+ -# %li.clear.user |
|
22 |
+ -# .avatar |
|
23 |
+ -# %img{src: 'assets/avatar.png', alt: t("chat.avatar_alt")} |
|
24 |
+ -# %h1 |
|
25 |
+ -# Adam Wolsky |
|
26 |
+ -# %span.status.online.icon-record |
|
27 |
+ -# %h2 co-founder |
|
28 |
+ -# %span.action |
|
29 |
+ -# %span.icon-x-full |
|
30 |
+ -# %span kick |
|
31 |
+ -# %li.clear.user |
|
32 |
+ -# .avatar |
|
33 |
+ -# %img{src: 'assets/avatar.png', alt: t("chat.avatar_alt")} |
|
34 |
+ -# %h1 |
|
35 |
+ -# John Savage |
|
36 |
+ -# %span.status.away.icon-record |
|
37 |
+ -# %h2 web & ui designer |
|
38 |
+ -# %span.action |
|
39 |
+ -# %span.icon-x-full |
|
40 |
+ -# %span kick |
|
41 |
+ -# %span.icon-bubbles |
|
42 |
+ -# %span invite |
|
42 | 43 |
#js-inactive-friends |
43 | 44 |
.toolbox |
44 | 45 |
%input{type: "search", placeholder: "Search contact"} |