2014-07-23 09:24:17 +02:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Whisper.ConversationView = Backbone.View.extend({
|
2014-08-11 08:34:29 +02:00
|
|
|
className: 'conversation',
|
2014-07-23 09:24:17 +02:00
|
|
|
initialize: function() {
|
2014-07-23 22:06:37 +02:00
|
|
|
this.listenTo(this.model, 'destroy', this.stopListening); // auto update
|
2014-08-11 08:34:29 +02:00
|
|
|
this.template = $('#conversation').html();
|
|
|
|
Mustache.parse(this.template);
|
|
|
|
this.$el.html(Mustache.render(this.template));
|
2014-07-23 10:52:59 +02:00
|
|
|
|
2014-07-23 22:06:37 +02:00
|
|
|
this.view = new Whisper.MessageListView({collection: this.model.messages()});
|
2014-09-04 09:16:06 +02:00
|
|
|
this.model.messages().fetch({reset: true});
|
2014-08-25 04:28:15 +02:00
|
|
|
this.$el.find('.discussion-container').append(this.view.el);
|
2014-07-23 09:24:17 +02:00
|
|
|
},
|
|
|
|
events: {
|
2014-08-11 08:34:29 +02:00
|
|
|
'submit .send': 'sendMessage',
|
|
|
|
'close': 'remove'
|
2014-07-23 09:24:17 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
sendMessage: function(e) {
|
|
|
|
e.preventDefault();
|
2014-08-11 08:34:29 +02:00
|
|
|
var input = this.$el.find('.send input');
|
2014-07-23 23:16:05 +02:00
|
|
|
if (input.val().length > 0) {
|
|
|
|
this.model.sendMessage(input.val());
|
|
|
|
input.val("");
|
|
|
|
}
|
2014-07-23 09:24:17 +02:00
|
|
|
},
|
2014-07-23 22:06:37 +02:00
|
|
|
|
|
|
|
render: function() {
|
2014-09-01 02:41:09 +02:00
|
|
|
Whisper.Layout.setContent(this.$el.show());
|
2014-07-23 22:06:37 +02:00
|
|
|
return this;
|
|
|
|
}
|
2014-07-23 09:24:17 +02:00
|
|
|
});
|
|
|
|
})();
|