diff --git a/js/views/conversations/show.js b/js/views/conversation_list_item_view.js similarity index 60% rename from js/views/conversations/show.js rename to js/views/conversation_list_item_view.js index 105f5c452d85..0aa3e5313e06 100644 --- a/js/views/conversations/show.js +++ b/js/views/conversation_list_item_view.js @@ -3,13 +3,12 @@ var Whisper = Whisper || {}; (function () { 'use strict'; - Whisper.ConversationView = Backbone.View.extend({ + Whisper.ConversationListItemView = Backbone.View.extend({ tagName: 'li', className: 'conversation', events: { 'click': 'open', - 'submit form': 'sendMessage' }, initialize: function() { this.template = $('#contact').html(); @@ -21,20 +20,8 @@ var Whisper = Whisper || {}; this.$el.addClass('closed'); }, - sendMessage: function(e) { - if (!this.$input.val().length) { return false; } - this.model.sendMessage(this.$input.val()); - this.$input.val(""); - e.preventDefault(); - }, - - remove: function() { - this.$el.remove(); - }, - open: function(e) { - var v = new Whisper.MessageListView({collection: this.model.messages()}); - v.render(); + var v = new Whisper.ConversationView({el: $('#main'), model: this.model}); }, render: function() { diff --git a/js/views/conversation_list_view.js b/js/views/conversation_list_view.js index 9484fa5f561c..5c529f077cd4 100644 --- a/js/views/conversation_list_view.js +++ b/js/views/conversation_list_view.js @@ -6,7 +6,7 @@ var Whisper = Whisper || {}; Whisper.ConversationListView = Whisper.ListView.extend({ tagName: 'ul', id: 'contacts', - itemView: Whisper.ConversationView, + itemView: Whisper.ConversationListItemView, collection: Whisper.Threads, events: { diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js new file mode 100644 index 000000000000..b6d2e20bd76e --- /dev/null +++ b/js/views/conversation_view.js @@ -0,0 +1,23 @@ +var Whisper = Whisper || {}; + +(function () { + 'use strict'; + + Whisper.ConversationView = Backbone.View.extend({ + initialize: function() { + this.listenTo(this.model, 'destroy', this.remove); // auto update + var v = new Whisper.MessageListView({collection: this.model.messages()}); + v.render(); + }, + events: { + 'submit #new-message': 'sendMessage', + }, + + sendMessage: function(e) { + if (!this.$input.val().length) { return false; } + this.model.sendMessage(this.$input.val()); + this.$input.val(""); + e.preventDefault(); + }, + }); +})(); diff --git a/popup.html b/popup.html index caca092c4541..18c954f6805a 100644 --- a/popup.html +++ b/popup.html @@ -94,11 +94,12 @@ - + - + +