-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maurice Fonk
committed
Feb 6, 2011
1 parent
e1d5549
commit 46f036a
Showing
6 changed files
with
166 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
namespace 'views.menu' | |||
|
|||
# Single channel's view in the list of channels | |||
views.menu.Channel = Backbone.View.extend | |||
|
|||
# Event hash | |||
events: | |||
'click': 'makeActive' | |||
|
|||
# Initialize | |||
initialize: () -> | |||
@unread = 0 | |||
|
|||
# Track active state | |||
@model.bind 'change:active', () => | |||
if @model.get 'active' | |||
do @hideMessageCount | |||
$(@el).addClass 'active' | |||
else | |||
$(@el).removeClass 'active' | |||
|
|||
# Track unread messages | |||
@model.messageList.bind 'add', () => | |||
if not (@model.get 'active') | |||
@unread++ | |||
do @showUnread | |||
|
|||
# Make our model active if it isn't already | |||
makeActive: () -> | |||
if not @model.get 'active' | |||
@model.set active: true | |||
|
|||
# Hide the message counter, and reset | |||
hideMessageCount: () -> | |||
@unread = 0 | |||
@messageCountEl.text @unread | |||
do @messageCountEl.hide | |||
|
|||
# Update and show unread message count | |||
showUnread: () -> | |||
return if @model.get 'active' | |||
|
|||
@messageCountEl.text @unread | |||
do @messageCountEl.show | |||
|
|||
# Render | |||
render: () -> | |||
# Replace our element with a rendered one | |||
dom = $(Template::renderTemplate 'channelListChannel') | |||
@el = dom | |||
do @delegateEvents | |||
|
|||
nameEl = @el.find '.name' | |||
nameEl.text @model.get 'name' | |||
|
|||
# Find and hide the message count, we'll show once there are messages | |||
@messageCountEl = @el.find '.message-count' | |||
do @hideMessageCount | |||
|
|||
this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
namespace 'views.menu.channels' | |||
|
|||
# View for the channel list | |||
views.menu.channels.List = Backbone.View.extend | |||
|
|||
# Init | |||
initialize: () -> | |||
# @model.bind 'add', @render | |||
@model.bind 'refresh', () => | |||
do @render | |||
|
|||
# Change conversation | |||
changeConversation: (e) -> | |||
do e.preventDefault | |||
|
|||
li = $(e.target).closest 'li' | |||
|
|||
# Remove active from all | |||
all = @$ '.conversations li' | |||
all.removeClass 'active' | |||
|
|||
# Add it to our target | |||
li.addClass 'active' | |||
|
|||
render: () -> | |||
dom = $(Template::renderTemplate 'channelList') | |||
|
|||
list = dom.find 'ul' | |||
|
|||
# Render each channel separately | |||
@model.each (channel) -> | |||
|
|||
# Create the channel's view if it doesn't exist already | |||
if not channel.view? | |||
ChannelView = use 'views.menu.Channel' | |||
channel.view = new ChannelView | |||
model: channel | |||
|
|||
# Render | |||
do channel.view.render | |||
|
|||
# Append the rendered element to the list | |||
list.append channel.view.el | |||
|
|||
@el.html dom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.