00f00dbe |
Xmpp.Views.Chat ||= {}
class Xmpp.Views.Chat.MessageView extends Backbone.View
template: JST["backbone/templates/chat/message"]
className: 'message-box'
initialize: (parts) ->
_.bindAll(this)
@user = parts.user |
aa33d796 |
@dateSent = parts.date |
14a337d8 |
@fromMe = parts.fromMe |
00f00dbe |
@message = parts.message
render: -> |
aa33d796 |
$(@el).html(@template(username: @user.get('name'), avatar: @user.get('avatar'), date: @formatTime(), message: @message)) |
14a337d8 |
if @fromMe
$(@el).addClass('me')
|
aa33d796 |
return this
formatTime: ->
nowDate = new Date() |
c39a094d |
if (nowDate.getDate() != @dateSent.getDate() ||
nowDate.getMonth() != @dateSent.getMonth() || |
aa33d796 |
nowDate.getFullYear() != @dateSent.getFullYear()) |
b227af8d |
return @dateSent.getFullYear() + '/' + @_padDate((@dateSent.getMonth()+1)) + '/' + @_padDate(@dateSent.getDate()) + |
c39a094d |
' ' + @_padDate(@dateSent.getHours()) + ':' + @_padDate(@dateSent.getMinutes()) |
aa33d796 |
|
b227af8d |
return @_padDate(@dateSent.getHours()) + ':' + @_padDate(@dateSent.getMinutes())
_padDate: (number) ->
if number < 10
'0' + number
else
number |