From 1bf35d9f4ffc070e1e7ec2bc94e851dec1b5f0f4 Mon Sep 17 00:00:00 2001 From: "fergal.moran" Date: Mon, 24 Sep 2012 14:54:25 +0100 Subject: [PATCH] Changed chat to use logged in user. --- static/js/app/app.js | 2 +- static/js/app/chat.js | 13 +++++++++---- templates/inc/chat.html | 17 ++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/static/js/app/app.js b/static/js/app/app.js index 17bcca0..d70a10c 100644 --- a/static/js/app/app.js +++ b/static/js/app/app.js @@ -49,7 +49,7 @@ var AppRouter = Backbone.Router.extend({ $('#site-content-fill').html(''); this.sidebarView = new SidebarView(); $('#sidebar').html(this.sidebarView.el); - startChat($('#chat-messages', this.sidebarView.el), $('#input', this.sidebarView.el), $('#status', this.sidebarView.el)); + startChat($('#chat-messages', this.sidebarView.el), $('#input', this.sidebarView.el), $('#status', this.sidebarView.el), "Fergal Moran"); var data = type != undefined ? $.param({sort:type}) : null; mixList.fetch({ diff --git a/static/js/app/chat.js b/static/js/app/chat.js index c4546c2..0f3f2a2 100644 --- a/static/js/app/chat.js +++ b/static/js/app/chat.js @@ -1,4 +1,4 @@ -function startChat(content, input, status) { +function startChat(content, input, status, user) { "use strict"; // for better performance - to avoid searching in DOM @@ -24,7 +24,12 @@ function startChat(content, input, status) { connection.onopen = function () { // first we want users to enter their names input.removeAttr('disabled'); - status.text('Choose name:'); + if (user) { + myName = user; + connection.send(user); + } else { + status.text('Choose name:'); + } }; connection.onerror = function (error) { @@ -109,7 +114,7 @@ function startChat(content, input, status) { function addMessage(author, message, color, dt) { content.append( '' + author + ' @ ' + +(dt.getHours() < 10 ? '0' + dt.getHours() : dt.getHours()) + ':' - + (dt.getMinutes() < 10 ? '0' + dt.getMinutes() : dt.getMinutes()) + "" - + '' + message + ''); + + (dt.getMinutes() < 10 ? '0' + dt.getMinutes() : dt.getMinutes()) + "" + + '' + message + ''); } } \ No newline at end of file diff --git a/templates/inc/chat.html b/templates/inc/chat.html index 2dbccf9..0bdd7da 100644 --- a/templates/inc/chat.html +++ b/templates/inc/chat.html @@ -1,8 +1,11 @@ -
- Connecting... - -
- - -
+{% if user.is_authenticated %} +
+ Connecting... + +
+ +
+{% else %} +

Please login to chat..

+{% endif %}