Skip to content

Commit

Permalink
Toolbar delete button for Button/Button Group goes via generic API de…
Browse files Browse the repository at this point in the history
…lete code not via genericObjectDefinitionToolbarController

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1753388
  • Loading branch information
ZitaNemeckova committed Oct 7, 2019
1 parent 5b4a3bc commit 5b9802c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/helpers/application_helper/button/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!"),
),
]
)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
12 changes: 9 additions & 3 deletions app/javascript/toolbar-actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand All @@ -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);
}
}

0 comments on commit 5b9802c

Please sign in to comment.