@ -5,6 +5,31 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    'use strict' ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    window . Whisper  =  window . Whisper  ||  { } ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    Whisper . NewContactView  =  Whisper . View . extend ( { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        templateName :  'new-contact' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        className :  'conversation-list-item contact' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        events :  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            'click' :  'validate' 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        initialize :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . listenTo ( this . model ,  'change' ,  this . render ) ;  // auto update
 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        render _attributes :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            return  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    number :  'Click to create new contact' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    title :  this . model . getNumber ( ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    avatar :  this . model . getAvatar ( ) , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        validate :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( this . model . isValid ( ) )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . $el . addClass ( 'valid' ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            }  else  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . $el . removeClass ( 'valid' ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    } ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				    Whisper . ConversationSearchView  =  Whisper . View . extend ( { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        className :  'conversation-search' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        initialize :  function ( options )  { 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -25,7 +50,7 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        events :  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            ' select  .new-contact':  'createConversation' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            ' click  .new-contact':  'createConversation' , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        filterContacts :  function ( e )  { 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -34,7 +59,9 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                if  ( this . maybeNumber ( query ) )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . new _contact _view . model . set ( 'id' ,  query ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . new _contact _view . render ( ) . $el . show ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . new _contact _view . validate ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . hideHints ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                }  else  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . new _contact _view . $el . hide ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                } 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -55,7 +82,7 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . new _contact _view . $el . hide ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            // Creates a view to display a new contact
 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . new _contact _view  =  new  Whisper . ConversationListItem View( { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            this . new _contact _view  =  new  Whisper . NewContact View( { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                el :  this . $new _contact , 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                model :  ConversationController . create ( { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    type :  'private' , 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -66,8 +93,7 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        createConversation :  function ( )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  conversation  =  this . new _contact _view . model ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            var  error  =  conversation . validate ( conversation . attributes ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( ! error )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            if  ( this . new _contact _view . model . isValid ( ) )  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                ConversationController . findOrCreatePrivateById ( 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . new _contact _view . model . id 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                ) . then ( function ( conversation )  { 
 
			
		 
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
			
			 
			 
			
				@ -75,6 +101,9 @@
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . initNewContact ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                    this . resetTypeahead ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                } . bind ( this ) ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            }  else  { 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . new _contact _view . $ ( '.number' ) . text ( "Invalid number" ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				                this . $input . focus ( ) ; 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				            } 
 
			
		 
		
	
		
			
				 
				 
			
			 
			 
			
				        } ,