2014-05-17 04:48:46 +00:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Whisper.ConversationView = Backbone.View.extend({
|
|
|
|
tagName: 'li',
|
|
|
|
className: 'conversation',
|
|
|
|
|
2014-06-08 03:32:17 +00:00
|
|
|
events: {
|
2014-07-22 18:55:26 +00:00
|
|
|
'click': 'open',
|
2014-06-08 03:32:17 +00:00
|
|
|
'submit form': 'sendMessage'
|
|
|
|
},
|
2014-05-17 04:48:46 +00:00
|
|
|
initialize: function() {
|
2014-07-22 18:55:26 +00:00
|
|
|
this.template = $('#contact').html();
|
|
|
|
Mustache.parse(this.template);
|
|
|
|
|
2014-05-17 04:48:46 +00:00
|
|
|
this.listenTo(this.model, 'change', this.render); // auto update
|
|
|
|
this.listenTo(this.model, 'destroy', this.remove); // auto update
|
|
|
|
|
|
|
|
this.$el.addClass('closed');
|
2014-06-08 03:32:17 +00:00
|
|
|
},
|
2014-05-17 04:48:46 +00:00
|
|
|
|
2014-06-08 03:32:17 +00:00
|
|
|
sendMessage: function(e) {
|
|
|
|
if (!this.$input.val().length) { return false; }
|
|
|
|
this.model.sendMessage(this.$input.val());
|
|
|
|
this.$input.val("");
|
|
|
|
e.preventDefault();
|
2014-05-17 04:48:46 +00:00
|
|
|
},
|
|
|
|
|
2014-06-08 03:32:17 +00:00
|
|
|
remove: function() {
|
|
|
|
this.$el.remove();
|
|
|
|
},
|
|
|
|
|
2014-05-17 04:48:46 +00:00
|
|
|
open: function(e) {
|
2014-07-22 18:55:26 +00:00
|
|
|
var v = new Whisper.MessageListView({collection: this.model.messages()});
|
|
|
|
v.render();
|
2014-05-17 04:48:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2014-07-22 18:55:26 +00:00
|
|
|
this.$el.html(
|
|
|
|
Mustache.render(this.template, {
|
|
|
|
name: this.model.get('name')
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2014-05-17 04:48:46 +00:00
|
|
|
return this;
|
2014-07-22 18:55:26 +00:00
|
|
|
},
|
|
|
|
|
2014-05-17 04:48:46 +00:00
|
|
|
});
|
|
|
|
})();
|