c034ac8267
Each conversation views now manages its own separate elements rather than all binding to a shared #conversation element, and similarly for message composition ui. Also includes the beginnings of group creation UI (not working yet), featuring bootstrap-tagsinput field for entering group recipients
36 lines
960 B
JavaScript
36 lines
960 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').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() {
|
|
this.$el.show().insertAfter($('#gutter'));
|
|
return this;
|
|
}
|
|
});
|
|
})();
|