Merge branch 'master' into feature/3153
This commit is contained in:
@@ -3,14 +3,17 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
include ImageAttributes
|
||||
|
||||
def new
|
||||
@card = ::Widget::Card.new(header: header_card?)
|
||||
if header_card?
|
||||
@card = ::Widget::Card.new(header: header_card?)
|
||||
else
|
||||
@card = ::Widget::Card.new(site_customization_page_id: params[:page_id])
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@card = ::Widget::Card.new(card_params)
|
||||
if @card.save
|
||||
notice = "Success"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
redirect_to_customization_page_cards_or_homepage
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -23,8 +26,7 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
def update
|
||||
@card = ::Widget::Card.find(params[:id])
|
||||
if @card.update(card_params)
|
||||
notice = "Updated"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
redirect_to_customization_page_cards_or_homepage
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -34,25 +36,39 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
@card = ::Widget::Card.find(params[:id])
|
||||
@card.destroy
|
||||
|
||||
notice = "Removed"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
redirect_to_customization_page_cards_or_homepage
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def card_params
|
||||
params.require(:widget_card).permit(
|
||||
:link_url, :button_text, :button_url, :alignment, :header,
|
||||
translation_params(Widget::Card),
|
||||
image_attributes: image_attributes
|
||||
)
|
||||
end
|
||||
def card_params
|
||||
params.require(:widget_card).permit(
|
||||
:link_url, :button_text, :button_url, :alignment, :header, :site_customization_page_id,
|
||||
:columns,
|
||||
translation_params(Widget::Card),
|
||||
image_attributes: image_attributes
|
||||
)
|
||||
end
|
||||
|
||||
def header_card?
|
||||
params[:header_card].present?
|
||||
end
|
||||
def header_card?
|
||||
params[:header_card].present?
|
||||
end
|
||||
|
||||
def resource
|
||||
Widget::Card.find(params[:id])
|
||||
end
|
||||
def redirect_to_customization_page_cards_or_homepage
|
||||
notice = t("admin.site_customization.pages.cards.#{params[:action]}.notice")
|
||||
|
||||
if @card.site_customization_page_id
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
end
|
||||
|
||||
def page
|
||||
::SiteCustomization::Page.find(@card.site_customization_page_id)
|
||||
end
|
||||
|
||||
def resource
|
||||
Widget::Card.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user