@@ -78,6 +78,35 @@ export default Ember.ObjectController.extend(NewOrEditContainer, {
7878 removeDevice : function ( obj ) {
7979 this . get ( 'devicesArray' ) . removeObject ( obj ) ;
8080 } ,
81+
82+ chooseRegistry : function ( registry ) {
83+ var found = false ;
84+ this . get ( 'registryChoices' ) . forEach ( ( choice ) => {
85+ var prefix = choice . get ( 'serverAddress' ) + ':' ;
86+
87+ if ( registry && choice . get ( 'id' ) === registry . get ( 'id' ) )
88+ {
89+ found = true ;
90+ choice . set ( 'active' , true ) ;
91+ this . set ( 'displayPrefix' , prefix ) ;
92+ this . set ( 'selectedRegistry' , choice ) ;
93+ this . set ( 'credentialChoices' , choice . get ( 'credentials' ) ) ;
94+ }
95+ else
96+ {
97+ choice . set ( 'active' , false ) ;
98+ }
99+ } ) ;
100+
101+ if ( ! found )
102+ {
103+ this . set ( 'displayPrefix' , 'docker:' ) ;
104+ this . set ( 'selectedRegistry' , null ) ;
105+ this . set ( 'credentialChoices' , null ) ;
106+ }
107+
108+ this . set ( 'registryCredentialId' , this . get ( 'credentialChoices.firstObject.id' ) ) ;
109+ } ,
81110 } ,
82111
83112 validate : function ( ) {
@@ -213,21 +242,70 @@ export default Ember.ObjectController.extend(NewOrEditContainer, {
213242 } . observes ( 'linksArray.@each.{linkName,targetInstanceId}' ) ,
214243
215244 // Image
245+ registryChoices : null ,
246+ displayPrefix : 'docker:' ,
216247 userImageUuid : 'ubuntu:14.04.1' ,
248+ credentialChoices : null ,
249+ showCredentials : Ember . computed . gt ( 'credentialChoices.length' , 1 ) ,
217250 userImageUuidDidChange : function ( ) {
218- var image = this . get ( 'userImageUuid' ) ;
219- if ( image . indexOf ( 'docker:' ) === 0 )
251+ var input = this . get ( 'userImageUuid' ) ;
252+ var choices = this . get ( 'registryChoices' ) || [ ] ;
253+
254+ // Look for a private registry with the matching prefix
255+ var prefix , choice , found = false ;
256+ for ( var i = 0 ; i < choices . get ( 'length' ) ; i ++ )
220257 {
221- this . set ( 'userImageUuid' , image . replace ( / ^ d o c k e r : / , '' ) ) ;
258+ choice = choices . objectAt ( i ) ;
259+ prefix = choice . get ( 'serverAddress' ) + ':' ;
260+ choice . set ( 'selected' , false ) ;
261+ if ( input . indexOf ( prefix ) === 0 )
262+ {
263+ this . set ( 'userImageUuid' , input . substr ( prefix . length ) ) ;
264+ this . send ( 'chooseRegistry' , choice ) ;
265+ }
222266 }
223- else
267+
268+ if ( found )
224269 {
225- image = 'docker:' + image ;
270+ return ;
226271 }
227272
228- this . set ( 'imageUuid' , image ) ;
273+ prefix = 'docker:' ;
274+ if ( input . indexOf ( prefix ) === 0 )
275+ {
276+ this . set ( 'userImageUuid' , input . substr ( prefix . length ) ) ;
277+ this . send ( 'chooseRegistry' , null ) ;
278+ }
229279 } . observes ( 'userImageUuid' ) ,
230280
281+ updateImageUuid : function ( ) {
282+ var uuid = 'docker:' ;
283+ var registry = this . get ( 'selectedRegistry.serverAddress' ) ;
284+ if ( registry )
285+ {
286+ uuid += registry + '/' ;
287+ }
288+ uuid += this . get ( 'userImageUuid' ) ;
289+
290+ this . set ( 'imageUuid' , uuid ) ;
291+ } . observes ( 'selectedRegistry.serverAddress' , 'userImageUuid' ) ,
292+
293+ credentialChoicesChanged : function ( ) {
294+ var found = false ;
295+ var id = this . get ( 'registryCredentialId' ) ;
296+ ( this . get ( 'credentialChoices' ) || [ ] ) . forEach ( ( choice ) => {
297+ if ( choice . get ( 'id' ) === id )
298+ {
299+ found = true ;
300+ }
301+ } ) ;
302+
303+ if ( ! found )
304+ {
305+ this . set ( 'registryCredentialId' , null ) ;
306+ }
307+ } . observes ( 'credentialChoices.@each.id' , 'registryCredentialId' ) ,
308+
231309 // Volumes
232310 volumesArray : null ,
233311 initVolumes : function ( ) {
0 commit comments