From a85cfb1a9536cb04ed3f89df171862f3e393941a Mon Sep 17 00:00:00 2001 From: Robin Knaur Date: Wed, 3 Aug 2016 15:24:32 +0200 Subject: [PATCH] Generic toolbar button for skip, disable and error message (transferred from ManageIQ/manageiq@5e9ecb1de6cf92beeefce1f87bc7f078b03678cf) --- .../generic_feature_button_with_disable.rb | 24 +++++++++++++++++++ .../application_helper/toolbar/x_vm_center.rb | 5 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/helpers/application_helper/button/generic_feature_button_with_disable.rb diff --git a/app/helpers/application_helper/button/generic_feature_button_with_disable.rb b/app/helpers/application_helper/button/generic_feature_button_with_disable.rb new file mode 100644 index 00000000000..5494272a7a0 --- /dev/null +++ b/app/helpers/application_helper/button/generic_feature_button_with_disable.rb @@ -0,0 +1,24 @@ +class ApplicationHelper::Button::GenericFeatureButtonWithDisable < ApplicationHelper::Button::GenericFeatureButton + needs_record + + def calculate_properties + self[:enabled] = !(self[:title] = @error_message if disabled?) + end + + def disabled? +<<<<<<< HEAD + !!(@error_message = @record.is_available_now_error_message(@feature)) +======= + begin + begin + @error_message = @record.try(:unsupported_reason, @feature) + rescue NoMethodError + @error_message = @record.try(:is_available_now_error_message, @feature) if @error_message.nil? + end + rescue + @error_message = 'Feature is not supported.' + true + end +>>>>>>> 407f786... fixup + end +end diff --git a/app/helpers/application_helper/toolbar/x_vm_center.rb b/app/helpers/application_helper/toolbar/x_vm_center.rb index 6a42ae2b0dc..fedd1fd05db 100644 --- a/app/helpers/application_helper/toolbar/x_vm_center.rb +++ b/app/helpers/application_helper/toolbar/x_vm_center.rb @@ -106,7 +106,7 @@ class ApplicationHelper::Toolbar::XVmCenter < ApplicationHelper::Toolbar::Basic 'product product-clone fa-lg', t = N_('Clone this VM'), t, - :klass => ApplicationHelper::Button::GenericFeatureButton, + :klass => ApplicationHelper::Button::GenericFeatureButton, :options => {:feature => :clone}), button( :vm_publish, @@ -187,7 +187,8 @@ class ApplicationHelper::Toolbar::XVmCenter < ApplicationHelper::Toolbar::Basic N_('Power On'), :image => "power_on", :confirm => N_("Power On this VM?"), - :klass => ApplicationHelper::Button::VmStart), + :klass => ApplicationHelper::Button::GenericFeatureButtonWithDisable, + :options => {:feature => :start}), button( :vm_stop, nil,