diff --git a/app/assets/javascripts/host_edit.js b/app/assets/javascripts/host_edit.js index 742a5ea7ad8e..477e7441f937 100644 --- a/app/assets/javascripts/host_edit.js +++ b/app/assets/javascripts/host_edit.js @@ -165,6 +165,16 @@ function update_capabilities(capabilities) { var stop_pooling; +if (window.location.href.contains('hostgroup')) { + document.addEventListener('DOMContentLoaded', function() { + const form = document.querySelector('form'); + form.addEventListener('submit', function() { + // // making sure inherited compute resource is included in the form + const hostgroup_compute_resource_id = $('#hostgroup_compute_resource_id'); + hostgroup_compute_resource_id.prop('disabled', false); + }); + }); +} function submit_with_all_params() { $('form.hostresource-form input[type="submit"]').attr('disabled', true); stop_pooling = false; diff --git a/app/controllers/hostgroups_controller.rb b/app/controllers/hostgroups_controller.rb index 1bbc7dd24974..ca27a0e46b5e 100644 --- a/app/controllers/hostgroups_controller.rb +++ b/app/controllers/hostgroups_controller.rb @@ -30,6 +30,7 @@ def nest @hostgroup = Hostgroup.new(:parent_id => @parent.id) load_vars_for_ajax + @hostgroup.compute_resource_id = @parent.compute_resource_id @hostgroup.locations = @parent.locations @hostgroup.organizations = @parent.organizations # Clone any parameters as well @@ -101,11 +102,12 @@ def csv_columns def load_vars_for_ajax return unless @hostgroup.present? - @architecture = @hostgroup.architecture - @operatingsystem = @hostgroup.operatingsystem - @domain = @hostgroup.domain - @subnet = @hostgroup.subnet - @realm = @hostgroup.realm + @compute_resource_id = @hostgroup.compute_resource_id + @architecture = @hostgroup.architecture + @operatingsystem = @hostgroup.operatingsystem + @domain = @hostgroup.domain + @subnet = @hostgroup.subnet + @realm = @hostgroup.realm end def users_in_ancestors @@ -144,11 +146,12 @@ def refresh_hostgroup def inherit_parent_attributes return unless @parent.present? - @hostgroup.architecture ||= @parent.architecture - @hostgroup.operatingsystem ||= @parent.operatingsystem - @hostgroup.domain ||= @parent.domain - @hostgroup.subnet ||= @parent.subnet - @hostgroup.realm ||= @parent.realm + @hostgroup.compute_resource_id ||= @parent.compute_resource_id + @hostgroup.architecture ||= @parent.architecture + @hostgroup.operatingsystem ||= @parent.operatingsystem + @hostgroup.domain ||= @parent.domain + @hostgroup.subnet ||= @parent.subnet + @hostgroup.realm ||= @parent.realm end def reset_explicit_attributes diff --git a/app/helpers/hostgroups_helper.rb b/app/helpers/hostgroups_helper.rb index 9fdddc637bae..a6c0592ee0f2 100644 --- a/app/helpers/hostgroups_helper.rb +++ b/app/helpers/hostgroups_helper.rb @@ -37,4 +37,19 @@ def prioritized_members(list, value_key) sort_by { |member| member[:priority] }. map { |member_hash| member_hash[value_key] } end + + def hostgroup_inherited_by_default?(field, hostgroup) + return false if hostgroup.ancestry.nil? + return false if params[:action] == 'clone' + return true unless params[:hostgroup] + !params[:hostgroup][field] + end + + def blank_or_inherit_hostgroup_f(f, attr, blank_value: _("no value")) + return true unless f.object.respond_to?(:parent_id) && f.object.parent_id + inherited_value = f.object.send(attr) + inherited_value = inherited_value.name_method if inherited_value.present? && inherited_value.respond_to?(:name_method) + inherited_value ||= blank_value + _("Inherit parent (%s)") % inherited_value + end end diff --git a/app/views/hostgroups/_form.html.erb b/app/views/hostgroups/_form.html.erb index 83b83a069f0c..f21ef6724e74 100644 --- a/app/views/hostgroups/_form.html.erb +++ b/app/views/hostgroups/_form.html.erb @@ -1,5 +1,5 @@ <%= javascript 'host_edit', 'host_edit_interfaces' %> -<%= form_for @hostgroup, :html => {:class => 'hostresource-form hostgroup-form form-horizontal well', :data => {:id => @hostgroup.try(:id)}} do |f| %> +<%= form_for @hostgroup, :html => {:class => 'hostresource-form hostgroup-form form-horizontal well', :data => {:id => @hostgroup.try(:id), :submit => 'progress_bar'}} do |f| %> <%= base_errors_for @hostgroup %>