@@ -4,36 +4,24 @@ KT.hosts = {};
44$ ( document ) . on ( 'ContentLoad' , function ( ) {
55 KT . hosts . onKatelloHostEditLoad ( ) ;
66 window . tfm . hosts . registerPluginAttributes ( "os" ,
7- [ 'lifecycle_environment_id' , 'content_view_id' , 'environment_id' , 'content_source_id' , 'architecture_id' , 'parent_id' ] ) ;
8-
9- $ ( "#hostgroup_lifecycle_environment_id" ) . on ( "change" , KT . hosts . environmentChanged ) ;
10- $ ( "#host_lifecycle_environment_id" ) . on ( "change" , KT . hosts . environmentChanged ) ;
7+ [ 'content_view_environment_id' , 'content_source_id' , 'architecture_id' , 'parent_id' ] ) ;
118
129 KT . hosts . update_media_enablement ( ) ;
1310 KT . hosts . set_media_selection_bindings ( ) ;
1411} ) ;
1512
1613KT . hosts . contentSourceChanged = function ( ) {
17- $ ( "#hostgroup_lifecycle_environment_id" ) . val ( "" ) ;
18- $ ( "#host_lifecycle_environment_id" ) . val ( "" ) ;
1914 $ ( "#hostgroup_content_view_environment_id" ) . val ( "" ) ;
20- KT . hosts . fetchEnvironments ( ) ;
21- KT . hosts . environmentChanged ( ) ;
15+ $ ( "#host_content_view_environment_id" ) . val ( "" ) ;
2216 KT . hosts . refreshContentViewEnvironments ( ) ;
2317} ;
2418
25- KT . hosts . environmentChanged = function ( ) {
26- // if we don't save the currently selected view it's likely
27- // it will be undefined in toggle_installation_medium due to the CV dropdown reload
28- var previous_content_view = KT . hosts . getSelectedContentView ( ) ;
29-
30- KT . hosts . fetchContentViews ( ) ;
31- KT . hosts . toggle_installation_medium ( previous_content_view ) ;
32- } ;
33-
3419KT . hosts . refreshContentViewEnvironments = function ( ) {
3520 var select = $ ( "#hostgroup_content_view_environment_id" ) ;
36- if ( select . length === 0 ) return ; // Only for hostgroups
21+ if ( select . length === 0 ) {
22+ select = $ ( "#host_content_view_environment_id" ) ;
23+ }
24+ if ( select . length === 0 ) return ;
3725
3826 var content_source_id = $ ( '#content_source_id' ) . val ( ) ;
3927 var orgIdsElem = $ ( "#hostgroup_organization_ids" ) ;
@@ -43,7 +31,10 @@ KT.hosts.refreshContentViewEnvironments = function() {
4331 orgIds = orgIdsElem . data ( 'useds' ) ;
4432 }
4533 if ( orgIds === undefined || orgIds === null || orgIds . length === 0 ) {
46- return ; // Can't fetch without organization
34+ orgIds = [ $ ( "#host_organization_id" ) . val ( ) ] ;
35+ }
36+ if ( orgIds === undefined || orgIds === null || orgIds . length === 0 ) {
37+ return ;
4738 }
4839 var orgId = Array . isArray ( orgIds ) ? orgIds [ 0 ] : orgIds ;
4940
@@ -63,24 +54,22 @@ KT.hosts.refreshContentViewEnvironments = function() {
6354 $ . get ( url , params , function ( data ) {
6455 var foundPreviousValue = false ;
6556
66- // Add inherit option back if it was there
67- if ( previousInheritText && ( previousInheritText . includes ( 'Inherit' ) || previousInheritText === '' ) ) {
57+ if ( inheritOption . length && ( inheritOption . val ( ) === '' || previousInheritDataId ) ) {
6858 var inheritOpt = $ ( "<option />" ) . text ( previousInheritText ) . val ( '' ) ;
6959 if ( previousInheritDataId ) inheritOpt . attr ( 'data-id' , previousInheritDataId ) ;
7060 select . append ( inheritOpt ) ;
7161 }
7262
73- $ . each ( data . results , function ( index , cve ) {
74- var label = cve . lifecycle_environment . name + ' / ' + cve . content_view . name ;
75- var option = $ ( "<option />" ) . val ( cve . id ) . text ( label ) ;
76- if ( cve . id === parseInt ( previousValue ) ) {
63+ $ . each ( data . results , function ( index , cvEnv ) {
64+ var label = cvEnv . label ;
65+ var option = $ ( "<option />" ) . val ( cvEnv . id ) . text ( label ) ;
66+ if ( cvEnv . id === parseInt ( previousValue ) ) {
7767 option . prop ( 'selected' , true ) ;
7868 foundPreviousValue = true ;
7969 }
8070 select . append ( option ) ;
8171 } ) ;
8272
83- // If previous value not found in filtered list, select the blank/inherit option
8473 if ( ! foundPreviousValue ) {
8574 select . val ( '' ) ;
8675 }
@@ -89,126 +78,9 @@ KT.hosts.refreshContentViewEnvironments = function() {
8978 } ) ;
9079} ;
9180
92- KT . hosts . fetchEnvironments = function ( ) {
93- var select = KT . hosts . getEnvironmentSelect ( ) ;
94- var content_source_id = $ ( '#content_source_id' ) . val ( ) ;
95- var option ;
96- select . find ( 'option' ) . remove ( ) ;
97- if ( content_source_id ) {
98- var url = tfm . tools . foremanUrl ( '/katello/api/capsules/' + content_source_id ) ;
99- var orgIdsElem = $ ( "#hostgroup_organization_ids" ) ;
100- var orgIds = orgIdsElem . val ( ) ;
101- if ( orgIds === undefined || orgIds === null || orgIds . length === 0 ) {
102- orgIds = orgIdsElem . data ( 'useds' ) ;
103- }
104- if ( orgIds === undefined || orgIds === null || orgIds . length === 0 ) {
105- orgIds = [ $ ( "#host_organization_id" ) . val ( ) ] ;
106- } ;
107- orgIds = orgIds . map ( function ( id ) {
108- return Number ( id ) ;
109- } ) ;
110- $ . get ( url , function ( content_source ) {
111- $ . each ( content_source . lifecycle_environments , function ( index , env ) {
112- // Don't show environments that aren't in the selected org. See jQuery.each() docs
113- if ( ! orgIds . includes ( env . organization_id ) ) return true ;
114- option = $ ( "<option />" ) . val ( env . id ) . text ( env . name ) ;
115- select . append ( option ) ;
116- } ) ;
117- select . trigger ( 'change' ) ;
118- } ) ;
119- }
120- } ;
121-
122- KT . hosts . fetchContentViews = function ( ) {
123- var select = KT . hosts . getContentViewSelect ( ) ;
124- var envId = KT . hosts . getSelectedEnvironment ( ) ;
125- var option ;
126- var previous_view = KT . hosts . getSelectedContentView ( ) ;
127- var previousInheritViewText = select . find ( 'option:first-child' ) . text ( ) ;
128- select . find ( 'option' ) . remove ( ) ;
129- if ( envId ) {
130- KT . hosts . signalContentViewFetch ( true ) ;
131- var url = tfm . tools . foremanUrl ( '/katello/api/v2/content_views' ) ;
132- $ . get ( url , { environment_id : envId , full_result : true } , function ( data ) {
133- if ( $ ( '#hostgroup_parent_id' ) . length > 0 ) {
134- select . append ( $ ( "<option />" ) . text ( previousInheritViewText ) . val ( '' ) ) ;
135- }
136- $ . each ( data . results , function ( index , view ) {
137- option = $ ( "<option />" ) . val ( view . id ) . text ( view . name ) ;
138- if ( view . id === parseInt ( previous_view ) ) {
139- option . prop ( 'selected' , true ) ;
140- }
141- select . append ( option ) ;
142- } ) ;
143- select . trigger ( 'change' ) ;
144- KT . hosts . signalContentViewFetch ( false ) ;
145- } ) ;
146- }
147- } ;
148-
149- KT . hosts . signalContentViewFetch = function ( fetching ) {
150- var select = KT . hosts . getContentViewSelect ( ) ;
151- var select2 = KT . hosts . getContentViewSelect2 ( ) ;
152- spinner = $ ( '<img>' ) . attr ( 'src' , select . data ( "spinner-path" ) ) ,
153- spinner_id = "content_view_spinner" ;
154-
155- if ( fetching ) {
156- select . hide ( ) ;
157- select2 . hide ( ) ;
158- $ ( spinner ) . attr ( 'id' , spinner_id ) . insertAfter ( select ) ;
159- } else {
160- select2 . show ( ) ;
161- $ ( '#' + spinner_id ) . remove ( ) ;
162- }
163- } ;
164-
165- KT . hosts . getContentViewSelect2 = function ( ) {
166- var select = $ ( "#s2id_host_content_view_id" ) . first ( ) ;
167- if ( select . length === 0 ) {
168- select = $ ( "#s2id_hostgroup_content_view_id" ) . first ( ) ;
169- }
170- return select ;
171- } ;
172-
173- KT . hosts . getContentViewSelect = function ( ) {
174- var select = $ ( "#host_content_view_id" ) . first ( ) ;
175- if ( select . length === 0 ) {
176- select = $ ( "#hostgroup_content_view_id" ) . first ( ) ;
177- }
178- return select ;
179- } ;
180-
181- KT . hosts . getSelectedContentView = function ( ) {
182- var select = KT . hosts . getContentViewSelect ( ) ;
183- return select . val ( ) || select . find ( "option:selected" ) . data ( "id" ) ;
184- } ;
185-
186- KT . hosts . getEnvironmentSelect = function ( ) {
187- var select = $ ( "#hostgroup_lifecycle_environment_id" ) . first ( ) ;
188- if ( select . length === 0 ) {
189- select = $ ( "#host_lifecycle_environment_id" ) . first ( ) ;
190- }
191- return select ;
192- } ;
193-
194- KT . hosts . getSelectedEnvironment = function ( ) {
195- var envId = $ ( "#hostgroup_lifecycle_environment_id" ) . val ( ) ;
196- if ( envId === undefined || envId === null || envId . length === 0 ) {
197- envId = $ ( "#host_lifecycle_environment_id" ) . val ( )
198- }
199- if ( envId === undefined || envId === null || envId . length === 0 ) {
200- envId = $ ( "#hostgroup_lifecycle_environment_id > option:selected" ) . data ( "id" ) ;
201- }
202-
203- if ( envId && envId . length === 0 ) {
204- envId = undefined ;
205- }
206- return envId ;
207- } ;
208-
20981KT . hosts . onKatelloHostEditLoad = function ( ) {
21082 var prefixes = [ 'host' , 'hostgroup' ] ,
211- attributes = [ 'content_view_id' , 'environment_id ', 'architecture_id' ] ;
83+ attributes = [ 'content_view_environment_id ' , 'architecture_id' ] ;
21284
21385 $ ( 'body' ) . off ( '.hostsContentSourceNS' ) ;
21486
@@ -226,26 +98,38 @@ KT.hosts.onKatelloHostEditLoad = function(){
22698 } ) ;
22799} ;
228100
229- KT . hosts . toggle_installation_medium = function ( content_view_id ) {
230- var lifecycle_environment_id , content_source_id , architecture_id , operatingsystem_id ;
231-
232- if ( content_view_id === undefined ) {
233- content_view_id = KT . hosts . getSelectedContentView ( ) ;
101+ KT . hosts . getSelectedContentViewEnvironment = function ( ) {
102+ var cvEnvId = $ ( "#hostgroup_content_view_environment_id" ) . val ( ) ;
103+ if ( ! cvEnvId ) {
104+ cvEnvId = $ ( "#host_content_view_environment_id" ) . val ( ) ;
105+ }
106+ if ( ! cvEnvId ) {
107+ cvEnvId = $ ( "#hostgroup_content_view_environment_id > option:selected" ) . data ( "id" ) ;
108+ }
109+ if ( ! cvEnvId ) {
110+ var hiddenInput = $ ( "input[name='host[content_facet_attributes][content_view_environment_ids][]']" ) . first ( ) ;
111+ if ( hiddenInput . length ) {
112+ cvEnvId = hiddenInput . val ( ) ;
113+ }
234114 }
115+ return cvEnvId ;
116+ } ;
117+
118+ KT . hosts . toggle_installation_medium = function ( ) {
119+ var content_view_environment_id , content_source_id , architecture_id , operatingsystem_id ;
120+
121+ content_view_environment_id = KT . hosts . getSelectedContentViewEnvironment ( ) ;
122+ content_source_id = $ ( '#content_source_id' ) . val ( ) ;
235123
236124 if ( $ ( '#hostgroup_operatingsystem_id' ) . data ( 'type' ) == 'hostgroup' ) {
237- lifecycle_environment_id = KT . hosts . getSelectedEnvironment ( ) ;
238- content_source_id = $ ( '#content_source_id' ) . val ( ) ;
239125 architecture_id = $ ( '#hostgroup_architecture_id' ) . val ( ) ;
240126 operatingsystem_id = $ ( '#hostgroup_operatingsystem_id' ) . val ( ) ;
241127 } else {
242- lifecycle_environment_id = KT . hosts . getSelectedEnvironment ( ) ;
243- content_source_id = $ ( '#content_source_id' ) . val ( ) ;
244128 architecture_id = $ ( '#host_architecture_id' ) . val ( ) ;
245129 operatingsystem_id = $ ( '#host_operatingsystem_id' ) . val ( ) ;
246130 }
247131
248- if ( content_view_id && lifecycle_environment_id && content_source_id && architecture_id && operatingsystem_id ) {
132+ if ( content_view_environment_id && content_source_id && architecture_id && operatingsystem_id ) {
249133 os_selected ( KT . hosts . get_os_element ( ) ) ;
250134 }
251135} ;
@@ -318,13 +202,11 @@ KT.hosts.get_synced_content_dropdown = function() {
318202} ;
319203
320204KT . hosts . on_install_media_dropdown_change = function ( ) {
321- // reset the kickstart-repository-id .. They are either or.
322205 KT . hosts . get_synced_content_dropdown ( ) . val ( "" ) ;
323206 activate_select2 ( "#media_select" ) ;
324207} ;
325208
326209KT . hosts . on_synced_content_dropdown_change = function ( ) {
327- // reset the kickstart-repository-id .. They are either or.
328210 $ ( "#host_medium_id" ) . val ( "" ) ;
329211 $ ( "#s2id_host_medium_id" ) . val ( "" ) ;
330212 $ ( "#hostgroup_medium_id" ) . val ( "" ) ;
@@ -333,7 +215,6 @@ KT.hosts.on_synced_content_dropdown_change = function() {
333215} ;
334216
335217KT . hosts . set_install_media_bindings = function ( ) {
336- // reset the host medium id
337218 $ ( "#host_medium_id" ) . on ( "select2:select" , KT . hosts . on_install_media_dropdown_change ) ;
338219 $ ( "#s2id_host_medium_id" ) . on ( "select2:select" , KT . hosts . on_install_media_dropdown_change ) ;
339220 $ ( "#hostgroup_medium_id" ) . on ( "select2:select" , KT . hosts . on_install_media_dropdown_change ) ;
0 commit comments