@@ -16,16 +16,17 @@ define(function (require) {
1616 GitFtp = require ( "./GitFtp" ) ;
1717
1818 // Module variables
19- var ftpRemotesTemplate = require ( "text!src/Ftp/templates/remotes-picker.html" ) ,
19+ var ftpScopesTemplate = require ( "text!src/Ftp/templates/remotes-picker.html" ) ,
2020 $gitPanel = null ,
2121 $remotesDropdown = null ;
2222
2323 // Implementation
2424
2525 var attachEvents = _ . once ( function ( ) {
2626 $gitPanel
27- . on ( "click" , ".gitftp-remote-new" , handleGitFtpRemoteCreation )
28- . on ( "click" , ".gitftp-remove-remote" , function ( ) { handleGitFtpRemoteRemove ( $ ( this ) ) ; } )
27+ . on ( "click" , ".gitftp-remote-new" , handleGitFtpScopeCreation )
28+ . on ( "click" , ".gitftp-remove-remote" , function ( ) { handleGitFtpScopeRemove ( $ ( this ) ) ; } )
29+ . on ( "click" , ".gitftp-init-remote" , function ( ) { handleGitFtpInitScope ( $ ( this ) ) ; } )
2930 . on ( "click" , ".gitftp-push" , handleGitFtpPush ) ;
3031 } ) ;
3132
@@ -38,10 +39,10 @@ define(function (require) {
3839 }
3940
4041 function handleGitFtpPush ( ) {
41- var gitFtpRemote = $gitPanel . find ( ".git-remote-selected" ) . text ( ) . trim ( ) ;
42+ var gitFtpScope = $gitPanel . find ( ".git-remote-selected" ) . text ( ) . trim ( ) ;
4243 $gitPanel . find ( ".gitftp-push" ) . prop ( "disabled" , true ) . addClass ( "btn-loading" ) ;
4344
44- GitFtp . push ( gitFtpRemote ) . done ( function ( result ) {
45+ GitFtp . push ( gitFtpScope ) . done ( function ( result ) {
4546 Dialogs . showModalDialog (
4647 DefaultDialogs . DIALOG_ID_INFO ,
4748 Strings . GITFTP_PUSH_RESPONSE , // title
@@ -56,42 +57,42 @@ define(function (require) {
5657 } ) ;
5758 }
5859
59- function handleGitFtpRemoteCreation ( ) {
60+ function handleGitFtpScopeCreation ( ) {
6061 $gitPanel . find ( ".git-remotes" )
6162 . addClass ( "btn-loading" )
6263 . prop ( "disabled" , true ) ;
6364
64- return Utils . askQuestion ( Strings . CREATE_GITFTP_NEW_REMOTE , Strings . ENTER_GITFTP_REMOTE_NAME )
65+ return Utils . askQuestion ( Strings . CREATE_GITFTP_NEW_SCOPE , Strings . ENTER_GITFTP_SCOPE_NAME )
6566 . then ( function ( name ) {
6667 return Utils . askQuestion (
67- Strings . CREATE_GITFTP_NEW_REMOTE ,
68- Strings . ENTER_GITFTP_REMOTE_URL ,
68+ Strings . CREATE_GITFTP_NEW_SCOPE ,
69+ Strings . ENTER_GITFTP_SCOPE_URL ,
6970 { defaultValue : "ftp://user:passwd@example.org/folder" }
7071 )
7172 . then ( function ( url ) {
7273 return GitFtp . addScope ( name , url ) . then ( function ( ) {
7374
7475 // Render the list element of the new remote
7576 // TODO: replace this part with a way to call `Remotes.refreshRemotesPicker()`
76- var $newRemote = $ ( "<li/>" )
77- . addClass ( "gitftp-remote" )
78- . append ( "<a/>" )
79- . find ( "a" )
80- . attr ( { href : "#" , "data-remote-name" : name , "data-type" : "ftp" } )
81- . addClass ( "remote-name" )
82- . append ( "<span/>" )
83- . find ( "span" )
84- . addClass ( "trash-icon gitftp-remove-remote" )
85- . html ( "×" )
86- . end ( )
87- . append ( "<span/>" )
88- . find ( "span:nth-child(2)" )
89- . addClass ( "change-remote" )
90- . text ( name )
91- . end ( )
92- . end ( ) ;
93-
94- $gitPanel . find ( ".git-remotes-dropdown .ftp-remotes-header" ) . after ( $newRemote ) ;
77+ var $newScope = $ ( "<li/>" )
78+ . addClass ( "gitftp-remote" )
79+ . append ( "<a/>" )
80+ . find ( "a" )
81+ . attr ( { href : "#" , "data-remote-name" : name , "data-type" : "ftp" } )
82+ . addClass ( "remote-name" )
83+ . append ( "<span/>" )
84+ . find ( "span" )
85+ . addClass ( "trash-icon gitftp-remove-remote" )
86+ . html ( "×" )
87+ . end ( )
88+ . append ( "<span/>" )
89+ . find ( "span:nth-child(2)" )
90+ . addClass ( "change-remote" )
91+ . text ( name )
92+ . end ( )
93+ . end ( ) ;
94+
95+ $gitPanel . find ( ".git-remotes-dropdown .ftp-remotes-header" ) . after ( $newScope ) ;
9596
9697 } ) . catch ( function ( err ) {
9798 ErrorHandler . showError ( err , "Git-FTP remote creation failed" ) ;
@@ -105,25 +106,25 @@ define(function (require) {
105106 } ) ;
106107 }
107108
108- function handleGitFtpRemoteRemove ( $this ) {
109+ function handleGitFtpScopeRemove ( $this ) {
109110 $gitPanel . find ( ".git-remotes" )
110111 . addClass ( "btn-loading" )
111112 . prop ( "disabled" , true ) ;
112113
113114 var $selectedElement = $this . closest ( ".remote-name" ) ,
114- $currentRemote = $gitPanel . find ( ".git-remote-selected" ) ,
115- remoteName = $selectedElement . data ( "remote-name" ) ;
115+ $currentScope = $gitPanel . find ( ".git-remote-selected" ) ,
116+ scopeName = $selectedElement . data ( "remote-name" ) ;
116117
117118 return Utils . askQuestion (
118- Strings . DELETE_REMOTE ,
119- StringUtils . format ( Strings . DELETE_REMOTE_NAME , remoteName ) ,
119+ Strings . DELETE_SCOPE ,
120+ StringUtils . format ( Strings . DELETE_SCOPE_NAME , scopeName ) ,
120121 { booleanResponse : true }
121122 ) . then ( function ( response ) {
122123 if ( response ) {
123- return GitFtp . removeScope ( remoteName ) . then ( function ( ) {
124+ return GitFtp . removeScope ( scopeName ) . then ( function ( ) {
124125 $selectedElement . parent ( ) . remove ( ) ;
125- var newRemote = $gitPanel . find ( ".git-remotes-dropdown .remote" ) . first ( ) . find ( "a" ) . data ( "remote-name" ) ;
126- $currentRemote . data ( "remote-name" , newRemote ) . html ( newRemote ) ;
126+ var newScope = $gitPanel . find ( ".git-remotes-dropdown .remote" ) . first ( ) . find ( "a" ) . data ( "remote-name" ) ;
127+ $currentScope . data ( "remote-name" , newScope ) . html ( newScope ) ;
127128 } ) . catch ( function ( err ) {
128129 ErrorHandler . showError ( err , "Remove scope failed" ) ;
129130 } ) ;
@@ -135,16 +136,41 @@ define(function (require) {
135136 } ) ;
136137 }
137138
138- function addFtpRemotesToPicker ( ) {
139- GitFtp . getRemotes ( ) . then ( function ( ftpRemotes ) {
139+ function handleGitFtpInitScope ( $this ) {
140+ $gitPanel . find ( ".git-remotes" )
141+ . addClass ( "btn-loading" )
142+ . prop ( "disabled" , true ) ;
143+
144+ var $selectedElement = $this . closest ( ".remote-name" ) ,
145+ scopeName = $selectedElement . data ( "remote-name" ) ;
146+
147+ return Utils . askQuestion (
148+ Strings . INIT_GITFTP_SCOPE ,
149+ StringUtils . format ( Strings . INIT_GITFTP_SCOPE_NAME , scopeName ) ,
150+ { booleanResponse : true }
151+ ) . then ( function ( response ) {
152+ if ( response ) {
153+ return GitFtp . init ( scopeName ) . then ( function ( ) {
154+ } ) . catch ( function ( err ) {
155+ ErrorHandler . showError ( err , "Init scope failed" ) ;
156+ } ) ;
157+ }
158+ } ) . finally ( function ( ) {
159+ $gitPanel . find ( ".git-remotes" )
160+ . removeClass ( "btn-loading" )
161+ . prop ( "disabled" , false ) ;
162+ } ) ;
163+ }
164+
165+ function addFtpScopesToPicker ( ) {
166+ GitFtp . getScopes ( ) . then ( function ( ftpScopes ) {
140167
141168 // Pass to Mustache the needed data
142- var compiledTemplate = Mustache . render ( ftpRemotesTemplate , {
169+ var compiledTemplate = Mustache . render ( ftpScopesTemplate , {
143170 Strings : Strings ,
144- ftpRemotes : ftpRemotes ,
145- hasFtpRemotes : ftpRemotes . length > 0
171+ ftpScopes : ftpScopes ,
172+ hasFtpScopes : ftpScopes . length > 0
146173 } ) ;
147-
148174 $remotesDropdown . prepend ( compiledTemplate ) ;
149175
150176 } ) . catch ( function ( err ) {
@@ -158,7 +184,7 @@ define(function (require) {
158184 } ) ;
159185
160186 EventEmitter . on ( Events . REMOTES_REFRESH_PICKER , function ( ) {
161- addFtpRemotesToPicker ( ) ;
187+ addFtpScopesToPicker ( ) ;
162188 } ) ;
163189
164190} ) ;
0 commit comments