signal-desktop/js/views/conversation_view.js
lilia 9af18ce6ae Encapsulate page layout js
The layout class is the only class that should have knowledge of
page-level constant markup, such as #gutter and #contacts, and
should be pretty much the only place we find elements by id (with
the exception of template elements).

This change removes references to #gutter from views. Rather than
hardcoding assumptions about page layout, view elements should
ask the layout to insert themselves into the main content area by
calling Whisper.Layout.setContent.
2014-08-31 17:46:01 -07:00

36 lines
971 B
JavaScript

var Whisper = Whisper || {};
(function () {
'use strict';
Whisper.ConversationView = Backbone.View.extend({
className: 'conversation',
initialize: function() {
this.listenTo(this.model, 'destroy', this.stopListening); // auto update
this.template = $('#conversation').html();
Mustache.parse(this.template);
this.$el.html(Mustache.render(this.template));
this.view = new Whisper.MessageListView({collection: this.model.messages()});
this.$el.find('.discussion-container').append(this.view.el);
},
events: {
'submit .send': 'sendMessage',
'close': 'remove'
},
sendMessage: function(e) {
e.preventDefault();
var input = this.$el.find('.send input');
if (input.val().length > 0) {
this.model.sendMessage(input.val());
input.val("");
}
},
render: function() {
Whisper.Layout.setContent(this.$el.show());
return this;
}
});
})();