diff --git a/app/helpers/application_helper/button/basic.rb b/app/helpers/application_helper/button/basic.rb index ee3976a8892f..4b0d49302443 100644 --- a/app/helpers/application_helper/button/basic.rb +++ b/app/helpers/application_helper/button/basic.rb @@ -14,6 +14,10 @@ def initialize(view_context, view_binding, instance_data, props) end end + def data + nil + end + def role_allows_feature? # for select buttons RBAC is checked only for nested buttons return true if self[:type] == :buttonSelect diff --git a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb index e7b3286c637b..135b764e5e3a 100644 --- a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb +++ b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb @@ -1,5 +1,22 @@ class ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete < ApplicationHelper::Button::Basic + needs :@record + def disabled? - !@record.custom_buttons.count.zero? + @record.kind_of?(CustomButtonSet) && !@record.custom_buttons.count.zero? + end + + def data + {'function' => 'sendDataWithRx', + 'function-data' => { + :type => 'delete', + :controller => 'toolbarActions', + :url => "show_list", + :payload => { + :entity => @record.class.model_name.plural, + :back_url => "/generic_object_definition/", + :name => @record.name, + :labels => { :single => @record.class.name } + } + }.to_json} end end diff --git a/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb b/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb index fc31d40e0a35..a76050677355 100644 --- a/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb +++ b/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb @@ -12,12 +12,11 @@ class ApplicationHelper::Toolbar::GenericObjectDefinitionButtonCenter < Applicat :url => 'custom_button_edit', ), button( - :ab_button_delete, + :custom_button_delete, 'pficon pficon-delete fa-lg', - N_('Remove this Button from Inventory'), - :data => {'function' => 'sendDataWithRx', - 'function-data' => '{"type": "delete_custom_button", "controller": "genericObjectDefinitionToolbarController", "entity": "Button"}'}, + N_('Remove this Custom Button from Inventory'), :confirm => N_("Warning: This Button will be permanently removed!"), + :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete ) ] ) diff --git a/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb b/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb index f346911c9fc8..4776b7642944 100644 --- a/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb +++ b/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb @@ -18,13 +18,11 @@ class ApplicationHelper::Toolbar::GenericObjectDefinitionButtonGroupCenter < App :url => 'custom_button_new', ), button( - :ab_button_delete, + :custom_button_set_delete, 'pficon pficon-delete fa-lg', - N_('Remove this Button Group from Inventory'), - :data => {'function' => 'sendDataWithRx', - 'function-data' => '{"type": "delete_custom_button_set", "controller": "genericObjectDefinitionToolbarController", "entity": "Button Group"}'}, + N_('Remove this Custom Button Group from Inventory'), + :confirm => N_("Warning: This Custom Button Group will be permanently removed!"), :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete, - :confirm => N_("Warning: This Button Group will be permanently removed!"), ), ] ) diff --git a/app/helpers/application_helper/toolbar_builder.rb b/app/helpers/application_helper/toolbar_builder.rb index e222e4477e9b..f02e3ff885b3 100644 --- a/app/helpers/application_helper/toolbar_builder.rb +++ b/app/helpers/application_helper/toolbar_builder.rb @@ -116,7 +116,7 @@ def build_select_button(bgi, index) def apply_common_props(button, input) button.update( :color => input[:color], - :data => input[:data], + :data => input[:data] || button.data, :hidden => button[:hidden] || !!input[:hidden], :icon => input[:icon], :name => button[:id], diff --git a/app/javascript/toolbar-actions/delete.js b/app/javascript/toolbar-actions/delete.js index 530301cde559..f5fc300c9ee0 100644 --- a/app/javascript/toolbar-actions/delete.js +++ b/app/javascript/toolbar-actions/delete.js @@ -23,12 +23,18 @@ export function generateMessages(results) { }, { false: 0, true: 0 }); } -export function APIDelete(entity, resources, labels) { +export function APIDelete(entity, resources, labels = { single: '', multiple: '' }, backUrl, name) { + debugger; API.post(`/api/${entity}`, { action: 'delete', resources, }).then((data) => { - showMessage(generateMessages(data.results), labels); + if (backUrl) { + miqFlashLater({ message: sprintf(__('%s: "%s" was successfully deleted'), labels.single, name) }); + window.location.href = backUrl; + } else { + showMessage(generateMessages(data.results), labels); + }; return data; }); } @@ -41,6 +47,6 @@ export function onDelete(data, resources) { if (data.customAction) { customActionDelete(data, resources); } else { - APIDelete(data.entity, resources, data.labels); + APIDelete(data.entity, resources, data.labels, data.back_url, data.name); } }