@@ -19,7 +19,7 @@ var ConnectionView = View.extend({
19
19
}
20
20
} ,
21
21
events : {
22
- click : 'onClick' ,
22
+ ' click a' : 'onClick' ,
23
23
dblclick : 'onDoubleClick' ,
24
24
mouseover : 'onMouseOver' ,
25
25
mouseout : 'onMouseOut' ,
@@ -119,37 +119,47 @@ var ConnectView = View.extend({
119
119
]
120
120
} ,
121
121
events : {
122
- 'click .btn-info' : 'onInfoClicked' ,
123
122
'input [data-hook=name]' : 'onNameChanged' ,
124
123
'input [data-hook=port]' : 'onPortChanged' ,
125
124
'input [data-hook=hostname]' : 'onHostNameChanged' ,
126
125
'submit form' : 'onSubmit'
127
126
} ,
128
- onInfoClicked : function ( evt ) {
129
- evt . stopPropagation ( ) ;
130
- // debug('info clicked');
131
- } ,
132
127
onNameChanged : function ( evt ) {
133
128
this . displayedConnection . name = evt . target . value ;
134
129
} ,
135
130
onPortChanged : function ( evt ) {
136
- this . displayedConnection . port = parseInt ( evt . target . value , 10 ) ;
131
+ this . displayedConnection . portString = evt . target . value ;
137
132
} ,
138
133
onHostNameChanged : function ( evt ) {
139
134
this . displayedConnection . hostname = evt . target . value ;
140
135
} ,
141
136
initialize : function ( ) {
142
137
document . title = 'Connect to MongoDB' ;
138
+ this . displayedConnection . set ( {
139
+ name : '' ,
140
+ portString : '' ,
141
+ hostname : ''
142
+ } ) ;
143
143
this . connections . fetch ( ) ;
144
144
} ,
145
145
onSubmit : function ( event ) {
146
146
event . stopPropagation ( ) ;
147
147
event . preventDefault ( ) ;
148
148
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
+
149
157
this . has_error = false ;
150
158
151
159
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 ) {
153
163
// the connection uri (`host:port`) exists already, but under a different name
154
164
app . statusbar . hide ( ) ;
155
165
this . has_error = true ;
@@ -162,19 +172,20 @@ var ConnectView = View.extend({
162
172
163
173
// now test if the connection name already exists with another uri
164
174
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 ) {
166
178
// the connection name exists already, but with a different uri
167
179
app . statusbar . hide ( ) ;
168
180
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 '
170
182
+ 'choose a different name.' ,
171
183
existingConnection . name ) ;
172
184
return ;
173
185
}
174
186
175
187
// now test if the server is reachable
176
188
app . statusbar . show ( ) ;
177
- this . message = format ( 'Testing connection...' ) ;
178
189
this . displayedConnection . test ( this . onConnectionTested . bind ( this ) ) ;
179
190
} ,
180
191
onConnectionTested : function ( err , model ) {
@@ -184,15 +195,17 @@ var ConnectView = View.extend({
184
195
this . message = format ( 'Could not connect to %s, please check that a MongoDB instance '
185
196
+ 'is running there.' , model . uri ) ;
186
197
} 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
+ }
190
203
window . open ( format ( '%s?uri=%s#schema' , window . location . origin , model . uri ) ) ;
191
204
192
205
setTimeout ( this . set . bind ( this , {
193
206
message : ''
194
207
} ) , 500 ) ;
195
- // setTimeout(window.close, 1000);
208
+ setTimeout ( window . close , 1000 ) ;
196
209
}
197
210
} ,
198
211
render : function ( ) {
0 commit comments