@ -25,7 +25,10 @@ module.exports = CoreView.extend({
} ,
render : function ( ) {
this . $el . html ( template ( this . options ) ) ;
this . $el . html ( template ( {
title : this . options . title ,
errorMessage : this . model . get ( 'errorMessage' )
} ) ) ;
this . _addSidebar ( ) ;
this . form = {
@ -37,6 +40,13 @@ module.exports = CoreView.extend({
password : this . $ ( '.js-password' )
} ;
if ( this . _model . connection ) {
this . form . server . val ( this . _model . connection . server ) ;
this . form . port . val ( this . _model . connection . port ) ;
this . form . database . val ( this . _model . connection . database ) ;
this . form . username . val ( this . _model . connection . username ) ;
this . form . password . val ( this . _model . connection . password ) ;
}
return this ;
} ,
@ -52,7 +62,7 @@ module.exports = CoreView.extend({
_checkVisibility : function ( ) {
const state = this . _model . get ( 'state' ) ;
if ( state === 'idle' || state === 'error' ) {
if ( state === 'idle' ) {
this . show ( ) ;
} else {
this . hide ( ) ;
@ -96,22 +106,24 @@ module.exports = CoreView.extend({
client . checkDBConnectorsConnection ( this . _service , params , ( errors , _response , data ) => {
if ( errors ) {
this . _checkConnectionError ( ) ;
this . _checkConnectionError ( data ) ;
} else if ( data && data . connected ) {
this . _checkConnectionSuccess ( ) ;
}
this . _checkConnectionSuccess ( data ) ;
} ) ;
} ,
_checkConnectionSuccess : function ( data ) {
if ( data && data . connected ) {
this . _model . set ( 'state' , 'connected' ) ;
this . _model . set ( 'service_name' , 'connector' ) ;
} else {
this . _model . set ( 'state' , 'error' ) ;
}
_checkConnectionSuccess : function ( ) {
this . _model . set ( 'state' , 'connected' ) ;
this . _model . set ( 'service_name' , 'connector' ) ;
} ,
_checkConnectionError : function ( ) {
this . _model . set ( 'state' , 'error' ) ;
_checkConnectionError : function ( data ) {
if ( data . responseJSON && data . responseJSON . connected === false ) {
this . _model . set ( 'errorMessage' , _t ( 'components.modals.add-layer.imports.database.connection-error' ) ) ;
} else {
this . _model . set ( 'errorMessage' , _t ( 'components.modals.add-layer.imports.database.general-error' ) ) ;
}
this . render ( ) ;
}
} ) ;