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