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-10-24 21:03:34 +00:00
|
|
|
|
2014-10-25 01:44:30 +00:00
|
|
|
this.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
|
|
|
|
|
2014-09-04 07:16:06 +00:00
|
|
|
this.model.messages().fetch({reset: true});
|
2014-08-25 02:28:15 +00:00
|
|
|
this.$el.find('.discussion-container').append(this.view.el);
|
2014-10-10 03:08:21 +00:00
|
|
|
window.addEventListener('storage', (function(){
|
2014-10-24 21:03:34 +00:00
|
|
|
this.model.messages().fetch();
|
2014-10-10 03:08:21 +00:00
|
|
|
}).bind(this));
|
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-10-25 01:44:30 +00:00
|
|
|
var message = input.val();
|
|
|
|
var thread = this.model;
|
|
|
|
|
|
|
|
if (message.length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.fileInput.getFiles().then(function(attachments) {
|
|
|
|
thread.sendMessage(message, attachments);
|
|
|
|
});
|
2014-07-23 21:16:05 +00:00
|
|
|
input.val("");
|
|
|
|
}
|
2014-07-23 07:24:17 +00:00
|
|
|
},
|
2014-07-23 20:06:37 +00:00
|
|
|
|
|
|
|
render: function() {
|
2014-09-01 00:41:09 +00:00
|
|
|
Whisper.Layout.setContent(this.$el.show());
|
2014-11-11 07:16:46 +00:00
|
|
|
this.view.scrollToBottom();
|
2014-07-23 20:06:37 +00:00
|
|
|
return this;
|
|
|
|
}
|
2014-07-23 07:24:17 +00:00
|
|
|
});
|
|
|
|
})();
|