Add cards to custom pages
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
class Admin::SiteCustomization::CardsController < Admin::SiteCustomization::BaseController
|
||||
skip_authorization_check
|
||||
|
||||
def index
|
||||
@cards = ::Widget::Card.page(params[:page_id])
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,14 +2,24 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
include Translatable
|
||||
|
||||
def new
|
||||
@card = ::Widget::Card.new(header: header_card?)
|
||||
if header_card?
|
||||
@card = ::Widget::Card.new(header: header_card?)
|
||||
elsif params[:page_id] != 0
|
||||
@card = ::Widget::Card.new(site_customization_page_id: params[:page_id])
|
||||
else
|
||||
@card = ::Widget::Card.new
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@card = ::Widget::Card.new(card_params)
|
||||
if @card.save
|
||||
notice = "Success"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
if params[:page_id] != 0
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -23,7 +33,11 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
@card = ::Widget::Card.find(params[:id])
|
||||
if @card.update(card_params)
|
||||
notice = "Updated"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
if params[:page_id] != 0
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -34,7 +48,11 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
@card.destroy
|
||||
|
||||
notice = "Removed"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
if params[:page_id] != 0
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
@@ -43,7 +61,7 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
|
||||
|
||||
params.require(:widget_card).permit(
|
||||
:link_url, :button_text, :button_url, :alignment, :header,
|
||||
:link_url, :button_text, :button_url, :alignment, :header, :site_customization_page_id,
|
||||
translation_params(Widget::Card),
|
||||
image_attributes: image_attributes
|
||||
)
|
||||
@@ -52,6 +70,9 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
def header_card?
|
||||
params[:header_card].present?
|
||||
end
|
||||
def page
|
||||
::SiteCustomization::Page.find(@card.site_customization_page_id)
|
||||
end
|
||||
|
||||
def resource
|
||||
Widget::Card.find(params[:id])
|
||||
|
||||
Reference in New Issue
Block a user