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