Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor complete

  • Loading branch information...
commit 46f036acaadca26478aee4143452588e3ee317d7 1 parent e1d5549
@naneau authored
View
2  Cakefile
@@ -22,7 +22,7 @@ compileApp = () ->
if not err?
# Move the temp "concatenation.js" file to outputFile
exec 'mv static/js/concatenation.js static/js/app.js', (err, stdOut, stdIn) ->
- console.log 'Error compiling browser app' if err?
+ console.log ('Error compiling browser app: ' + err) if err?
console.log 'Compiled browser app' if not err?
# Compile the templates
View
2  browser/app/views/app.coffee
@@ -64,7 +64,7 @@ views.App = Backbone.View.extend
@channelWrapper = @$ '#channel'
# Channel List
- ChannelListView = use 'views.menu.Channels'
+ ChannelListView = use 'views.menu.channels.List'
@channelListView = new ChannelListView
el: (dom.find '#channel-list'),
model: @channelList
View
60 browser/app/views/menu/channel.coffee
@@ -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
View
45 browser/app/views/menu/channel/list.coffee
@@ -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
View
4 irc.coffee
@@ -59,8 +59,8 @@ socket.on 'connection', (client) ->
sys.puts 'socket.io client connected'
client.on 'message', (data) ->
- if data.message is 'channelMessage'
- ircClient.say data.channel, data.text
+ # if data.message is 'channelMessage'
+ # ircClient.say data.channel, data.text
# Send the channel list
client.send
View
114 static/js/app.js
@@ -211,7 +211,7 @@
this.right = dom.find('#right');
this.left = dom.find('#left');
this.channelWrapper = this.$('#channel');
- ChannelListView = use('views.menu.Channels');
+ ChannelListView = use('views.menu.channels.List');
this.channelListView = new ChannelListView({
el: dom.find('#channel-list'),
model: this.channelList
@@ -220,59 +220,6 @@
return this.resize();
}
});
- namespace('views');
- views.Channel = Backbone.View.extend({
- events: {
- 'click': 'makeActive'
- },
- initialize: function() {
- this.unread = 0;
- this.model.bind('change:active', __bind(function() {
- if (this.model.get('active')) {
- this.hideMessageCount();
- return $(this.el).addClass('active');
- } else {
- return $(this.el).removeClass('active');
- }
- }, this));
- return this.model.messageList.bind('add', __bind(function() {
- if (!(this.model.get('active'))) {
- this.unread++;
- return this.showUnread();
- }
- }, this));
- },
- makeActive: function() {
- if (!this.model.get('active')) {
- return this.model.set({
- active: true
- });
- }
- },
- hideMessageCount: function() {
- this.unread = 0;
- this.messageCountEl.text(this.unread);
- return this.messageCountEl.hide();
- },
- showUnread: function() {
- if (this.model.get('active')) {
- return;
- }
- this.messageCountEl.text(this.unread);
- return this.messageCountEl.show();
- },
- render: function() {
- var dom, nameEl;
- dom = $(Template.prototype.renderTemplate('channelListChannel'));
- this.el = dom;
- this.delegateEvents();
- nameEl = this.el.find('.name');
- nameEl.text(this.model.get('name'));
- this.messageCountEl = this.el.find('.message-count');
- this.hideMessageCount();
- return this;
- }
- });
namespace('views.chat');
views.chat.Message = Backbone.View.extend({
initialize: function(options) {
@@ -353,8 +300,8 @@
return this;
}
});
- namespace('views.menu');
- views.menu.Channels = Backbone.View.extend({
+ namespace('views.menu.channels');
+ views.menu.channels.List = Backbone.View.extend({
initialize: function() {
return this.model.bind('refresh', __bind(function() {
return this.render();
@@ -375,7 +322,7 @@
this.model.each(function(channel) {
var ChannelView;
if (!(channel.view != null)) {
- ChannelView = use('views.Channel');
+ ChannelView = use('views.menu.Channel');
channel.view = new ChannelView({
model: channel
});
@@ -386,4 +333,57 @@
return this.el.html(dom);
}
});
+ namespace('views.menu');
+ views.menu.Channel = Backbone.View.extend({
+ events: {
+ 'click': 'makeActive'
+ },
+ initialize: function() {
+ this.unread = 0;
+ this.model.bind('change:active', __bind(function() {
+ if (this.model.get('active')) {
+ this.hideMessageCount();
+ return $(this.el).addClass('active');
+ } else {
+ return $(this.el).removeClass('active');
+ }
+ }, this));
+ return this.model.messageList.bind('add', __bind(function() {
+ if (!(this.model.get('active'))) {
+ this.unread++;
+ return this.showUnread();
+ }
+ }, this));
+ },
+ makeActive: function() {
+ if (!this.model.get('active')) {
+ return this.model.set({
+ active: true
+ });
+ }
+ },
+ hideMessageCount: function() {
+ this.unread = 0;
+ this.messageCountEl.text(this.unread);
+ return this.messageCountEl.hide();
+ },
+ showUnread: function() {
+ if (this.model.get('active')) {
+ return;
+ }
+ this.messageCountEl.text(this.unread);
+ return this.messageCountEl.show();
+ },
+ render: function() {
+ var dom, nameEl;
+ dom = $(Template.prototype.renderTemplate('channelListChannel'));
+ this.el = dom;
+ this.delegateEvents();
+ nameEl = this.el.find('.name');
+ nameEl.text(this.model.get('name'));
+ this.messageCountEl = this.el.find('.message-count');
+ this.hideMessageCount();
+ return this;
+ }
+ });
}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.