@@ -19,7 +19,7 @@ var ConnectionView = View.extend({
1919 }
2020 } ,
2121 events : {
22- click : 'onClick' ,
22+ ' click a' : 'onClick' ,
2323 dblclick : 'onDoubleClick' ,
2424 mouseover : 'onMouseOver' ,
2525 mouseout : 'onMouseOut' ,
@@ -119,37 +119,47 @@ var ConnectView = View.extend({
119119 ]
120120 } ,
121121 events : {
122- 'click .btn-info' : 'onInfoClicked' ,
123122 'input [data-hook=name]' : 'onNameChanged' ,
124123 'input [data-hook=port]' : 'onPortChanged' ,
125124 'input [data-hook=hostname]' : 'onHostNameChanged' ,
126125 'submit form' : 'onSubmit'
127126 } ,
128- onInfoClicked : function ( evt ) {
129- evt . stopPropagation ( ) ;
130- // debug('info clicked');
131- } ,
132127 onNameChanged : function ( evt ) {
133128 this . displayedConnection . name = evt . target . value ;
134129 } ,
135130 onPortChanged : function ( evt ) {
136- this . displayedConnection . port = parseInt ( evt . target . value , 10 ) ;
131+ this . displayedConnection . portString = evt . target . value ;
137132 } ,
138133 onHostNameChanged : function ( evt ) {
139134 this . displayedConnection . hostname = evt . target . value ;
140135 } ,
141136 initialize : function ( ) {
142137 document . title = 'Connect to MongoDB' ;
138+ this . displayedConnection . set ( {
139+ name : '' ,
140+ portString : '' ,
141+ hostname : ''
142+ } ) ;
143143 this . connections . fetch ( ) ;
144144 } ,
145145 onSubmit : function ( event ) {
146146 event . stopPropagation ( ) ;
147147 event . preventDefault ( ) ;
148148
149+ // choose default connection values if unset
150+ if ( ! this . displayedConnection . hostname ) {
151+ this . displayedConnection . unset ( 'hostname' ) ;
152+ }
153+ if ( ! this . displayedConnection . portString ) {
154+ this . displayedConnection . unset ( 'portString' ) ;
155+ }
156+
149157 this . has_error = false ;
150158
151159 var existingConnection = this . connections . get ( this . displayedConnection . uri ) ;
152- if ( existingConnection && existingConnection . name !== this . displayedConnection . name ) {
160+ if ( this . displayedConnection . name !== ''
161+ && existingConnection
162+ && existingConnection . name !== this . displayedConnection . name ) {
153163 // the connection uri (`host:port`) exists already, but under a different name
154164 app . statusbar . hide ( ) ;
155165 this . has_error = true ;
@@ -162,19 +172,20 @@ var ConnectView = View.extend({
162172
163173 // now test if the connection name already exists with another uri
164174 existingConnection = this . connections . get ( this . displayedConnection . name , 'name' ) ;
165- if ( existingConnection && existingConnection . uri !== this . displayedConnection . uri ) {
175+ if ( this . displayedConnection . name !== ''
176+ && existingConnection
177+ && existingConnection . uri !== this . displayedConnection . uri ) {
166178 // the connection name exists already, but with a different uri
167179 app . statusbar . hide ( ) ;
168180 this . has_error = true ;
169- this . message = format ( 'A different connection with the name "%s" already exists. Please '
181+ this . message = format ( 'Another connection with the name "%s" already exists. Please '
170182 + 'choose a different name.' ,
171183 existingConnection . name ) ;
172184 return ;
173185 }
174186
175187 // now test if the server is reachable
176188 app . statusbar . show ( ) ;
177- this . message = format ( 'Testing connection...' ) ;
178189 this . displayedConnection . test ( this . onConnectionTested . bind ( this ) ) ;
179190 } ,
180191 onConnectionTested : function ( err , model ) {
@@ -184,15 +195,17 @@ var ConnectView = View.extend({
184195 this . message = format ( 'Could not connect to %s, please check that a MongoDB instance '
185196 + 'is running there.' , model . uri ) ;
186197 } else {
187- model . save ( ) ;
188- this . connections . add ( model ) ;
189- this . message = 'Connected!' ;
198+ if ( model . name !== '' ) {
199+ // only store if the user chose a name to save the connection
200+ model . save ( ) ;
201+ this . connections . add ( model ) ;
202+ }
190203 window . open ( format ( '%s?uri=%s#schema' , window . location . origin , model . uri ) ) ;
191204
192205 setTimeout ( this . set . bind ( this , {
193206 message : ''
194207 } ) , 500 ) ;
195- // setTimeout(window.close, 1000);
208+ setTimeout ( window . close , 1000 ) ;
196209 }
197210 } ,
198211 render : function ( ) {
0 commit comments