Changed chat to use logged in user.

This commit is contained in:
fergal.moran
2012-09-24 14:54:25 +01:00
parent 237297b24f
commit 1bf35d9f4f
3 changed files with 20 additions and 12 deletions

View File

@@ -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({

View File

@@ -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(
'<tr><td style="color:' + color + '">' + author + '</td> <td>@ ' + +(dt.getHours() < 10 ? '0' + dt.getHours() : dt.getHours()) + ':'
+ (dt.getMinutes() < 10 ? '0' + dt.getMinutes() : dt.getMinutes()) + "</td></tr>"
+ '<tr><td colspan="2">' + message + '</td></tr>');
+ (dt.getMinutes() < 10 ? '0' + dt.getMinutes() : dt.getMinutes()) + "</td></tr>"
+ '<tr><td colspan="2">' + message + '</td></tr>');
}
}

View File

@@ -1,8 +1,11 @@
<div id="chat-area">
<span id="status">Connecting...</span>
<input type="text" id="input" disabled="disabled"/>
</div>
<table id="chat-messages" class="table table-striped table-condensed table-hover">
</table>
{% if user.is_authenticated %}
<div id="chat-area">
<span id="status">Connecting...</span>
<input type="text" id="input" disabled="disabled"/>
</div>
<table id="chat-messages" class="table table-striped table-condensed table-hover">
</table>
{% else %}
<h3>Please <a href="/accounts/login/">login</a> to chat..</h3>
{% endif %}