2014-07-23 09:24:17 +02:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Whisper.ConversationView = Backbone.View.extend({
|
|
|
|
initialize: function() {
|
2014-07-23 22:06:37 +02:00
|
|
|
this.listenTo(this.model, 'destroy', this.stopListening); // auto update
|
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-07-23 09:24:17 +02:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'submit #new-message': 'sendMessage',
|
2014-07-23 22:06:37 +02:00
|
|
|
'close': 'undelegateEvents'
|
2014-07-23 09:24:17 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
sendMessage: function(e) {
|
|
|
|
if (!this.$input.val().length) { return false; }
|
|
|
|
this.model.sendMessage(this.$input.val());
|
|
|
|
this.$input.val("");
|
|
|
|
e.preventDefault();
|
|
|
|
},
|
2014-07-23 22:06:37 +02:00
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.view.render();
|
|
|
|
return this;
|
|
|
|
}
|
2014-07-23 09:24:17 +02:00
|
|
|
});
|
|
|
|
})();
|