var KT = KT ? KT : {}; KT.hosts = {}; $(document).on('ContentLoad', function(){ KT.hosts.onKatelloHostEditLoad(); window.tfm.hosts.registerPluginAttributes("os", ['lifecycle_environment_id', 'content_view_id', 'environment_id', 'content_source_id', 'architecture_id', 'parent_id']); $("#hostgroup_lifecycle_environment_id").change(KT.hosts.environmentChanged); $("#host_lifecycle_environment_id").change(KT.hosts.environmentChanged); KT.hosts.update_media_enablement(); KT.hosts.set_media_selection_bindings(); }); KT.hosts.contentSourceChanged = function() { $("#hostgroup_lifecycle_environment_id").val(""); $("#host_lifecycle_environment_id").val(""); KT.hosts.fetchEnvironments(); KT.hosts.environmentChanged(); }; KT.hosts.environmentChanged = function() { // if we don't save the currently selected view it's likely // it will be undefined in toggle_installation_medium due to the CV dropdown reload var previous_content_view = KT.hosts.getSelectedContentView(); KT.hosts.fetchContentViews(); KT.hosts.toggle_installation_medium(previous_content_view); }; KT.hosts.fetchEnvironments = function () { var select = KT.hosts.getEnvironmentSelect(); var content_source_id = $('#content_source_id').val(); var option; select.find('option').remove(); if (content_source_id) { var url = tfm.tools.foremanUrl('/katello/api/capsules/' + content_source_id); var orgId = $('#host_organization_id').val(); $.get(url, function (content_source) { $.each(content_source.lifecycle_environments, function(index, env) { // Don't show environments that aren't in the selected org. See jQuery.each() docs if (orgId && env.organization_id != orgId) return true; option = $("