Skip to content

Commit

Permalink
Fixes #27478 - extract onchange event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ezr-ondrej authored and mmoll committed Sep 21, 2019
1 parent 0bf24b7 commit 6af08b0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
22 changes: 14 additions & 8 deletions app/assets/javascripts/host_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ $(document).on('ContentLoad', function() {
$(document).on('AddedClass', function(event, link) {
load_puppet_class_parameters(link);
});
$(document)
.on('change', '.hostgroup-select', function(evt) {
hostgroup_changed(evt.target);
}).on('change', '.host-form-compute-resource-handle', function(evt) {
computeResourceSelected(evt.target);
}).on('change', '.host-taxonomy-select', function(evt) {
update_form(evt.target);
}).on('change', '.host-architecture-select', function(evt) {
architecture_selected(evt.target);
}).on('change', '.host-architecture-os-select', function(evt) {
os_selected(evt.target);
}).on('change', '.host-os-media-select', function(evt) {
medium_selected(evt.target);
});

function update_nics(success_callback) {
var data = serializeForm().replace('method=patch', 'method=post');
Expand Down Expand Up @@ -323,14 +337,6 @@ function set_inherited_value(hostgroup_elem) {
});
}

function organization_changed(element) {
update_form(element);
}

function location_changed(element) {
update_form(element);
}

function update_form(element, options) {
options = options || {};
var url = $(element).data('url');
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hosts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def host_taxonomy_select(f, taxonomy)
select_opts = { :include_blank => !@host.managed? || @host.send(taxonomy_id).nil?,
:selected => selected_taxonomy }
html_opts = { :disabled => !@host.new_record?,
:onchange => "#{taxonomy.to_s.downcase}_changed(this);",
:class => 'host-taxonomy-select',
:label => label,
:'data-host-id' => @host.id,
:'data-url' => process_taxonomy_hosts_path,
Expand Down
3 changes: 2 additions & 1 deletion app/views/common/os_selection/_architecture.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{:selected => item.operatingsystem_id, :include_blank => blank_or_inherit_f(f, :operatingsystem) },
{ :label => _("Operating system"),
:help_inline => :indicator,
:onchange => 'os_selected(this);', :'data-url' => method_path('os_selected'), :'data-type' => controller_name.singularize,
:class => 'host-architecture-os-select',
:data => { :url => method_path('os_selected'), :type => controller_name.singularize },
:required => !item.is_a?(Hostgroup),
:placeholder => arch_oss.empty? ? _("No options available for selected Architecture") : nil }
%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/common/os_selection/_initial.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= fields_for item do |f| %>
<%= select_f f, :architecture_id, accessible_resource(f.object, :architecture), :id, :to_label, {:include_blank => blank_or_inherit_f(f, :architecture)},
{:label => _("Architecture"), :onchange => 'architecture_selected(this);', :'data-url' => method_path('architecture_selected'), :'data-type' => controller_name.singularize} %>
{:label => _("Architecture"), :class => 'host-architecture-select', :data => { :url => method_path('architecture_selected'), :type => controller_name.singularize }} %>

<span id="host_os">
<span id="os_select">
Expand Down
4 changes: 2 additions & 2 deletions app/views/common/os_selection/_operatingsystem.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<%= fields_for item do |f| %>
<%= select_f f, :medium_id, os_media, :id, :to_label,
{:include_blank => blank_or_inherit_f(f, :medium), :selected => item.medium_id},
{:label => _("Media"), :help_inline => :indicator, :onchange => 'medium_selected(this);',
:'data-url' => method_path('medium_selected'), :'data-type' => controller_name.singularize,
{:label => _("Media"), :help_inline => :indicator, :class => 'host-os-media-select',
:data => { :url => method_path('medium_selected'), :type => controller_name.singularize },
:required => !item.is_a?(Hostgroup), :placeholder => os_media.empty? ? _("No options available for selected Operating System") : nil }
%>
<%= select_f f, :ptable_id, os_ptable, :id, :to_label,
Expand Down
3 changes: 2 additions & 1 deletion app/views/hostgroups/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

<div class="tab-pane active" id="primary">
<%= select_f(f, :parent_id, parent_hostgroups, :id, :to_label, {:include_blank => true}, {:label => _('Parent'),
:onchange => 'hostgroup_changed(this);', :'data-url'=> process_hostgroup_hostgroups_path,
:class => 'hostgroup-select',
:data => { :url => process_hostgroup_hostgroups_path },
:help_inline => :indicator }) if show_parent?(@hostgroup) %>
<%= text_f f, :name %>
<%= textarea_f f, :description, :rows => :auto %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/hosts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<%= select_f f, :hostgroup_id, accessible_resource(@host, :hostgroup, :title), :id, :to_label,
{ :include_blank => true},
{ :onchange => 'hostgroup_changed(this);',
{ :class => 'hostgroup-select',
:data => {
:'host-id' => @host.id,
:'url' => (@host.new_record? || @host.type_changed?) ? process_hostgroup_hosts_path : hostgroup_or_environment_selected_hosts_path,
Expand All @@ -56,8 +56,8 @@
:disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT),
:disable_button_enabled => inherited_by_default?(:compute_resource_id, @host),
:user_set => user_set?(:compute_resource_id) },
{ :label => _('Deploy On'), :disabled => (!@host.new_record? || @host.uuid.present?), :'data-url' => compute_resource_selected_hosts_path,
:onchange => 'computeResourceSelected(this);',
{ :class => 'host-form-compute-resource-handle',
:label => _('Deploy On'), :disabled => (!@host.new_record? || @host.uuid.present?), :'data-url' => compute_resource_selected_hosts_path,
:help_inline => :indicator } if SETTINGS[:unattended] && @host.new_record? || @host.compute_resource_id %>

<% if @host.new_record? && visible_compute_profiles(@host).any? %>
Expand All @@ -70,8 +70,8 @@
:disable_button_enabled => inherited_by_default?(:compute_profile_id, @host),
:user_set => user_set?(:compute_profile_id)
},
{ :label => _("Compute profile"), :'data-url' => compute_resource_selected_hosts_path,
:onchange => 'computeResourceSelected(this);',
{ :class => 'host-form-compute-resource-handle',
:label => _("Compute profile"), :'data-url' => compute_resource_selected_hosts_path,
:help_inline => :indicator } if SETTINGS[:unattended] %>
</div>
<% end %>
Expand Down

0 comments on commit 6af08b0

Please sign in to comment.