From ae52c047bfbc9d24f91441581b22d83c3473709d Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 1 Dec 2015 16:13:58 -0800 Subject: [PATCH] Clean up open-event logic with new convos and search results Search view triggers an open event when a valid phone number is entered and the 'Create new contact' card is clicked. Inbox view should listen and respond to this event. It should also disregard select events on the new contact element since those are fired before phone number validation. Finally, the search view can stop listening to select events because the inbox view is already doing so. // FREEBIE --- js/views/conversation_search_view.js | 7 +------ js/views/inbox_view.js | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/js/views/conversation_search_view.js b/js/views/conversation_search_view.js index 3db9e809..7a04f5f1 100644 --- a/js/views/conversation_search_view.js +++ b/js/views/conversation_search_view.js @@ -26,7 +26,6 @@ events: { 'select .new-contact': 'createConversation', - 'select .contacts': 'open' }, filterContacts: function(e) { @@ -72,17 +71,13 @@ ConversationController.findOrCreatePrivateById( this.new_contact_view.model.id ).then(function(conversation) { - this.$el.trigger('open', conversation); + this.trigger('open', conversation); this.initNewContact(); this.resetTypeahead(); }.bind(this)); } }, - open: function(e, conversation) { - this.$el.trigger('open', conversation); - }, - reset: function() { this.delegateEvents(); this.typeahead_view.delegateEvents(); diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index a9a58dc7..97bf2428 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -98,6 +98,8 @@ this.searchView.$el.show(); this.inboxListView.$el.hide(); }); + this.listenTo(this.searchView, 'open', + this.openConversation.bind(this, null)); if (inboxCollection.length === 0) { this.searchView.showAllContacts = true; @@ -120,7 +122,7 @@ 'click .hamburger': 'toggleMenu', 'click .show-debug-log': 'showDebugLog', 'click .show-new-conversation': 'showCompose', - 'select .gutter .contact': 'openConversation', + 'select .gutter .conversation-list-item': 'openConversation', 'input input.search': 'filterContacts' }, filterContacts: function(e) {