mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
#11068: update confirm_modal_component to accept controller values
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ConfirmModalComponent < ModalComponent
|
||||
# @param controller_data_values [Array(Hash)] format: {<value-name-1>: value1, <value-name-2>: value2}
|
||||
def initialize(
|
||||
id:,
|
||||
reflex: nil,
|
||||
@@ -10,7 +11,8 @@ class ConfirmModalComponent < ModalComponent
|
||||
confirm_reflexes: nil,
|
||||
confirm_button_color: :primary,
|
||||
confirm_button_text: I18n.t('js.admin.modals.confirm'),
|
||||
cancel_button_text: I18n.t('js.admin.modals.cancel')
|
||||
cancel_button_text: I18n.t('js.admin.modals.cancel'),
|
||||
controller_data_values: {}
|
||||
)
|
||||
super(id:, close_button: true)
|
||||
@confirm_actions = confirm_actions
|
||||
@@ -21,6 +23,7 @@ class ConfirmModalComponent < ModalComponent
|
||||
@confirm_button_color = confirm_button_color
|
||||
@confirm_button_text = confirm_button_text
|
||||
@cancel_button_text = cancel_button_text
|
||||
@controller_data_values = transform_values_for_controller(controller_data_values)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -28,4 +31,17 @@ class ConfirmModalComponent < ModalComponent
|
||||
def close_button_class
|
||||
"secondary"
|
||||
end
|
||||
|
||||
def modal_attrs
|
||||
@modal_attrs ||= {
|
||||
id: @id,
|
||||
"data-controller": "modal #{@controller}",
|
||||
"data-action": "keyup@document->modal#closeIfEscapeKey",
|
||||
"data-#{@controller}-reflex-value": @reflex
|
||||
}.merge(@controller_data_values)
|
||||
end
|
||||
|
||||
def transform_values_for_controller(values)
|
||||
values.transform_keys { |value_name| "data-#{@controller}-#{value_name}-value" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
%div{ id: @id, "data-controller": "modal #{@controller}", "data-action": "keyup@document->modal#closeIfEscapeKey", "data-#{@controller}-reflex-value": @reflex }
|
||||
%div{ **modal_attrs }
|
||||
.reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" }
|
||||
.reveal-modal.fade.tiny.help-modal{ "data-modal-target": "modal" }
|
||||
= content
|
||||
|
||||
Reference in New Issue
Block a user