@ -1,23 +1,34 @@
'use strict' ;
define (
[
'vent' ,
'marionette' ,
'Commands/CommandController' ,
'Mixins/AsModelBoundView' ,
'Mixins/AsValidatedView'
] , function ( Marionette , AsModelBoundView , AsValidatedView ) {
'Mixins/AsValidatedView' ,
'Mixins/CopyToClipboard'
] , function ( vent , Marionette , CommandController , AsModelBoundView , AsValidatedView ) {
var view = Marionette . ItemView . extend ( {
template : 'Settings/General/GeneralViewTemplate' ,
events : {
'change .x-auth' : '_setAuthOptionsVisibility' ,
'change .x-ssl' : '_setSslOptionsVisibility'
'change .x-auth' : '_setAuthOptionsVisibility' ,
'change .x-ssl' : '_setSslOptionsVisibility' ,
'click .x-reset-api-key' : '_resetApiKey'
} ,
ui : {
authToggle : '.x-auth' ,
authOptions : '.x-auth-options' ,
sslToggle : '.x-ssl' ,
sslOptions : '.x-ssl-options'
authToggle : '.x-auth' ,
authOptions : '.x-auth-options' ,
sslToggle : '.x-ssl' ,
sslOptions : '.x-ssl-options' ,
resetApiKey : '.x-reset-api-key' ,
copyApiKey : '.x-copy-api-key' ,
apiKeyInput : '.x-api-key'
} ,
initialize : function ( ) {
vent . on ( vent . Events . CommandComplete , this . _commandComplete , this ) ;
} ,
onRender : function ( ) {
@ -28,6 +39,17 @@ define(
if ( ! this . ui . sslToggle . prop ( 'checked' ) ) {
this . ui . sslOptions . hide ( ) ;
}
CommandController . bindToCommand ( {
element : this . ui . resetApiKey ,
command : {
name : 'resetApiKey'
}
} ) ;
} ,
onShow : function ( ) {
this . ui . copyApiKey . copyToClipboard ( this . ui . apiKeyInput ) ;
} ,
_setAuthOptionsVisibility : function ( ) {
@ -54,6 +76,20 @@ define(
else {
this . ui . sslOptions . slideUp ( ) ;
}
} ,
_resetApiKey : function ( ) {
if ( window . confirm ( "Reset API Key?" ) ) {
CommandController . Execute ( 'resetApiKey' , {
name : 'resetApiKey'
} ) ;
}
} ,
_commandComplete : function ( options ) {
if ( options . command . get ( 'name' ) === 'resetapikey' ) {
this . model . fetch ( ) ;
}
}
} ) ;