Files
grecia/app/controllers/concerns/admin/widget/cards_actions.rb
taitus 6059aab674 Allow saving a position when create a widget card
We are ensuring that only position field is rendered only on
non-header cards.

Note that we have 3 sections that use widget cards:
- Homepage (cards and header cards)
- Custompages (only have cards)
- Sdg Homepage (cards and header cards)
2024-03-21 18:15:50 +01:00

72 lines
1.3 KiB
Ruby

module Admin::Widget::CardsActions
extend ActiveSupport::Concern
include Translatable
include ImageAttributes
included do
helper_method :form_path
end
def new
@card.header = header_card?
render template: "#{cards_view_path}/new"
end
def create
if @card.save
redirect_to_index
else
render template: "#{cards_view_path}/new"
end
end
def edit
render template: "#{cards_view_path}/edit"
end
def update
if @card.update(card_params)
redirect_to_index
else
render template: "#{cards_view_path}/edit"
end
end
def destroy
@card.destroy!
redirect_to_index
end
private
def card_params
params.require(:widget_card).permit(allowed_params)
end
def allowed_params
[
:link_url, :button_text, :button_url, :alignment, :header, :columns, :order,
translation_params(Widget::Card),
image_attributes: image_attributes
]
end
def header_card?
params[:header_card].present?
end
def redirect_to_index
notice = t("admin.site_customization.pages.cards.#{params[:action]}.notice")
redirect_to index_path, notice: notice
end
def cards_view_path
"admin/widget/cards"
end
def form_path
nil
end
end