Permalink
Browse files

A lot of shuffling around; add status window & set as default on conn…

…ection.
  • Loading branch information...
1 parent 940ae3c commit 0ae5358b43a4cd683831dbe1f8663488d2413d0a @akavlie akavlie committed Dec 30, 2011
@@ -112,7 +112,7 @@
-ms-box-sizing: border-box; // for IE8
}
-#chat_bar, #users_bar{
+#chat-bar, #user-bar{
height: 5%;
background: whiteSmoke;
border-bottom: 1px solid #DDD;
View
@@ -16,23 +16,25 @@ window.irc = {
connected: false
};
-var ChatApplicationRouter = Backbone.Router.extend({
- initialize: function(options) {
- this.view = new ChatApplicationView;
- }
-});
+// This isn't doing us any favors yet.
+// var ChatApplicationRouter = Backbone.Router.extend({
+// initialize: function(options) {
+// this.view = new ChatApplicationView;
+// }
+// });
$(function() {
- window.app = new ChatApplicationRouter;
+ // window.app = new ChatApplicationRouter;
+ irc.appView = new ChatApplicationView;
- // EVENTS //
+ // EVENTS //
// Registration (server joined)
irc.socket.on('registered', function(data) {
irc.connected = true;
- app.view.render();
+ irc.appView.render();
irc.chatWindows.add({name: 'status', type: 'status'});
irc.chatWindows.getByName('status').stream.add({sender: '', raw: data.message});
});
@@ -5,33 +5,42 @@ var Stream = Backbone.Collection.extend({
// All channels/private message chats a user has open
var WindowList = Backbone.Collection.extend({
- model: ChatWindow,
-
- getByName: function(name) {
- return this.detect(function(frame) {
- return frame.get('name') == name;
- });
- },
-
- getActive: function() {
- return this.detect(function(frame) {
- return frame.get('active') == true;
- });
- },
-
- setActive: function(frame) {
- this.each(function(frm) {
- frm.set({active: false});
- });
-
- frame.set({active: true});
- },
-
- getChannels: function() {
- return this.filter(function(frame) {
- return frame.get('type') == 'channel';
- });
- }
+ model: ChatWindow,
+
+ initialize: function() {
+ var self = this;
+ this.bind('add', function(chat) {
+ self.setActive(chat);
+ });
+
+ },
+
+ getByName: function(name) {
+ return this.detect(function(chat) {
+ return chat.get('name') === name;
+ });
+ },
+
+ getActive: function() {
+ return this.detect(function(chat) {
+ return chat.get('active') === true;
+ });
+ },
+
+ setActive: function(selected) {
+ console.log(selected.get('name') + ' set as active chat!');
+ this.each(function(chat) {
+ chat.set({active: false});
+ });
+
+ selected.set({active: true});
+ },
+
+ getChannels: function() {
+ return this.filter(function(chat) {
+ return chat.get('type') === 'channel';
+ });
+ }
});
View
@@ -56,8 +56,8 @@ var ChatWindow = Backbone.Model.extend({
// expected properties:
// - name
defaults: {
- 'type': 'channel',
- 'active': true
+ type: 'channel',
+ active: true
},
initialize: function() {
@@ -1,10 +0,0 @@
-var ChannelView = Backbone.View.extend({
- initialize: function(name) {
- this.model = new ChatWindow({name: name, view: this});
- },
-
- render: function() {
- $('.channels').append(this.model.name);
- return this;
- }
-});
@@ -0,0 +1,12 @@
+var ChannelListView = Backbone.View.extend({
+ el: $('#channels'),
+
+ initialize: function() {
+ irc.chatWindows.bind('add', this.addChannel, this);
+ },
+
+ addChannel: function(chat) {
+ $(this.el).append(ich.channel({name: chat.name}));
+ }
+
+});
@@ -8,9 +8,9 @@ var ChatApplicationView = Backbone.View.extend({
render: function() {
$('body').html($(this.el).html(ich.chat_application()));
if (!irc.connected) {
- var overview = new OverviewView();
+ var overview = new OverviewView;
} else {
- var chatview = new ChatView();
+ var chat = new ChatView;
}
return this;
}
View
@@ -26,10 +26,10 @@ script(id="overview_connection", type="text/html")
script(id="overview_home", type="text/html")
ul
li.overview_button#connection
- img(src="/assets/images/connection.svg")
+ img(src="/assets/images/connection.svg")
span New Connection
li.overview_button#settings
- img(src="/assets/images/settings.svg")
+ img(src="/assets/images/settings.svg")
span Settings
script(id="overview", type="text/html")
@@ -46,21 +46,21 @@ script(id="titlebar", type="text/html")
script(id="chat", type="text/html")
#chat-window
- #chat_bar
+ #chat-bar
#chat-contents
#input-container
.input
input(id="chat_input")
a(id="chat_button", class="btn disabled") Send
- #users_window
- #users_bar
+ #user-window
+ #user-bar
.titlebar
span(class='window_title') User List
- #users_list
+ #user-list
script(id="channel", type="text/html")
.channel
- span(class="channel_name") {{channelName}}
+ span(class="channel-name") {{name}}
script(id="unread", type="text/html")
span(class="unread", title="Unread Messages") {{unread}}
@@ -99,5 +99,5 @@ script(id="message", type="text/html")
span {{rendered_time}}
.chat_message
span
- b {{user}}:
+ b {{user}}:
span {{content}}

0 comments on commit 0ae5358

Please sign in to comment.