From 65564e61f65b1196ec767db18aa5263eb6828a67 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Wed, 23 Oct 2019 12:19:55 +0200 Subject: [PATCH] Use instance methods instead of class ones. Each button has its own class. --- .../application_helper/button/basic.rb | 4 ++-- ..._object_definition_button_button_delete.rb | 19 +++++++++++++++++++ ...t_definition_button_button_group_delete.rb | 12 ++++++------ ...generic_object_definition_button_center.rb | 2 +- .../application_helper/toolbar_builder.rb | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb diff --git a/app/helpers/application_helper/button/basic.rb b/app/helpers/application_helper/button/basic.rb index c5c6da8cdd5b..a26799288bad 100644 --- a/app/helpers/application_helper/button/basic.rb +++ b/app/helpers/application_helper/button/basic.rb @@ -14,8 +14,8 @@ def initialize(view_context, view_binding, instance_data, props) end end - def self.data(_record) - nil + def data(data) + data end def role_allows_feature? diff --git a/app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb b/app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb new file mode 100644 index 000000000000..6d8f23d7586a --- /dev/null +++ b/app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb @@ -0,0 +1,19 @@ +class ApplicationHelper::Button::GenericObjectDefinitionButtonButtonDelete < ApplicationHelper::Button::Basic + needs :@record + + def data(data) + { + 'function' => 'sendDataWithRx', + 'function-data' => { + :type => 'delete', + :controller => 'toolbarActions', + :payload => { + :entity => "custom_buttons", + :redirect_url => "/generic_object_definition/", + :name => @record.name, + :labels => { :single => _("Button") } + } + } + } + end +end 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 5c768fb9b87d..f38c24e41145 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 @@ -5,17 +5,17 @@ def disabled? @record.kind_of?(CustomButtonSet) && !@record.custom_buttons.count.zero? end - def self.data(record) + def data(data) { - 'function' => 'sendDataWithRx', - 'function-data' => { + 'function' => 'sendDataWithRx', + 'function-data' => { :type => 'delete', :controller => 'toolbarActions', :payload => { - :entity => record.class.model_name.plural, + :entity => "custom_button_sets", :redirect_url => "/generic_object_definition/", - :name => record.name, - :labels => { :single => record.class.name } + :name => @record.name, + :labels => { :single => _("Button Group") } } } } 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 88dfc5cf4985..9942aeb8d701 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 @@ -16,7 +16,7 @@ class ApplicationHelper::Toolbar::GenericObjectDefinitionButtonCenter < Applicat 'pficon pficon-delete fa-lg', N_('Remove this Custom Button from Inventory'), :confirm => N_("Warning: This Button will be permanently removed!"), - :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete + :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonDelete ) ] ) diff --git a/app/helpers/application_helper/toolbar_builder.rb b/app/helpers/application_helper/toolbar_builder.rb index dbfde62518c9..92f729eb2398 100644 --- a/app/helpers/application_helper/toolbar_builder.rb +++ b/app/helpers/application_helper/toolbar_builder.rb @@ -112,7 +112,7 @@ def build_select_button(bgi, index) def apply_common_props(button, input) button.update( :color => input[:color], - :data => input[:data] || (input[:klass].present? ? input[:klass].data(@record) : nil), + :data => button.data(input[:data]), :hidden => button[:hidden] || !!input[:hidden], :icon => input[:icon], :name => button[:id],