Skip to content

Commit

Permalink
Merge pull request #5873 from ZitaNemeckova/fix_cb_tabs
Browse files Browse the repository at this point in the history
Switch to Advanced tab when only error is "Request is required"
  • Loading branch information
h-kataria authored Aug 7, 2019
2 parents 4cee794 + 47b25af commit 88b4b54
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
34 changes: 28 additions & 6 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,15 @@ def ab_button_add
drop_breadcrumb(:name => _("Edit of Button"), :url => "/miq_ae_customization/button_edit")
@lastaction = "automate_button"
@layout = "miq_ae_automate_button"
javascript_flash
if @switch_tab
render :update do |page|
page << javascript_prologue
page.replace("flash_msg_div", :partial => "layouts/flash_msg")
page << "document.querySelector(\"#ab_advanced_tab_tab > a\").click();"
end
else
javascript_flash
end
return
end

Expand Down Expand Up @@ -586,7 +594,15 @@ def ab_button_save
drop_breadcrumb(:name => _("Edit of Button"), :url => "/miq_ae_customization/button_edit")
@lastaction = "automate_button"
@layout = "miq_ae_automate_button"
javascript_flash
if @switch_tab
render :update do |page|
page << javascript_prologue
page.replace("flash_msg_div", :partial => "layouts/flash_msg")
page << "document.querySelector(\"#ab_advanced_tab_tab > a\").click();"
end
else
javascript_flash
end
return
end

Expand Down Expand Up @@ -820,10 +836,6 @@ def button_valid?(button_hash = @edit[:new])

add_flash(_("Button Hover Text is required"), :error) if button_hash[:description].blank?

add_flash(_("Starting Process is required"), :error) if ab_button_name(button_hash).blank?

add_flash(_("Request is required"), :error) if button_hash[:object_request].blank?

if button_hash[:visibility_typ] == "role" && button_hash[:roles].blank?
add_flash(_("At least one Role must be selected"), :error)
end
Expand All @@ -838,6 +850,16 @@ def button_valid?(button_hash = @edit[:new])

validate_playbook_button(button_hash) if button_hash[:button_type] == "ansible_playbook"

if ab_button_name(button_hash).blank?
add_flash(_("Starting Process is required"), :error)
@switch_tab = true if @flash_array.length == 1
end

if button_hash[:object_request].blank?
add_flash(_("Request is required"), :error)
@switch_tab = true if @flash_array.length == 1
end

!flash_errors?
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/buttons/_ab_advanced_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- url = url_for_only_path(:action => 'automate_button_field_changed')
#ab_form
#ab_advanced_form
%h3
= _('Advanced Options')
- if @edit[:new][:display_for] == "single"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/application_controller/buttons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@
:open_url => true,
:display_for => :list}
}
flash_errors = [{:message => "Starting Process is required", :level => :error},
{:message => 'URL can be opened only by buttons for a single entity', :level => :error}]
flash_errors = [{:message => 'URL can be opened only by buttons for a single entity', :level => :error},
{:message => "Starting Process is required", :level => :error},]

controller.send(:button_valid?, edit[:new])
expect(assigns(:flash_array)).to match(flash_errors)
Expand Down

0 comments on commit 88b4b54

Please sign in to comment.