signal-desktop/js/views/conversation_view.js
lilia 0741c74618 Don't recreate views unnecessarily
Let ConversationListItemView save a reference to its corresponding
ConversationView. This lets it render or delegate/undelegate events
when opening and closing a conversation.

Similarly for ConversationView itself, which contains a MessageListView.
2014-07-27 11:35:49 -10:00

29 lines
698 B
JavaScript

var Whisper = Whisper || {};
(function () {
'use strict';
Whisper.ConversationView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.model, 'destroy', this.stopListening); // auto update
this.view = new Whisper.MessageListView({collection: this.model.messages()});
},
events: {
'submit #new-message': 'sendMessage',
'close': 'undelegateEvents'
},
sendMessage: function(e) {
if (!this.$input.val().length) { return false; }
this.model.sendMessage(this.$input.val());
this.$input.val("");
e.preventDefault();
},
render: function() {
this.view.render();
return this;
}
});
})();