2014-05-16 21:48:46 -07:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Whisper.MessageView = Backbone.View.extend({
|
|
|
|
tagName: "li",
|
2014-07-27 12:12:59 -10:00
|
|
|
className: "entry",
|
2014-05-16 21:48:46 -07:00
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.$el.addClass(this.model.get('type'));
|
2014-07-22 21:06:55 -10:00
|
|
|
|
2014-07-20 10:39:17 -10:00
|
|
|
this.template = $('#message').html();
|
|
|
|
Mustache.parse(this.template);
|
2014-07-22 21:06:55 -10:00
|
|
|
|
|
|
|
this.listenTo(this.model, 'change', this.render); // auto update
|
|
|
|
this.listenTo(this.model, 'destroy', this.remove); // auto update
|
|
|
|
|
2014-05-16 21:48:46 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2014-07-20 10:39:17 -10:00
|
|
|
this.$el.html(
|
|
|
|
Mustache.render(this.template, {
|
2014-07-27 12:12:59 -10:00
|
|
|
message: this.model.get('body'),
|
2014-11-11 00:35:18 -08:00
|
|
|
timestamp: moment(this.model.get('timestamp')).fromNow(),
|
2014-07-27 12:12:59 -10:00
|
|
|
attachments: this.model.get('attachments'),
|
2014-10-22 16:14:18 -07:00
|
|
|
bubble_class: this.model.get('type') === 'outgoing' ? 'sent' : 'incoming',
|
2014-11-13 14:35:37 -08:00
|
|
|
sender: this.model.get('conversationType') === 'group' ? this.model.get('sender') : ''
|
2014-07-20 10:39:17 -10:00
|
|
|
})
|
|
|
|
);
|
2014-05-16 21:48:46 -07:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
2014-11-11 00:35:18 -08:00
|
|
|
|
2014-05-16 21:48:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
})();
|