2013-02-06 03:16:51 +08:00
|
|
|
class Admin::SiteCustomizationsController < Admin::AdminController
|
2013-02-07 23:45:24 +08:00
|
|
|
|
2013-11-13 01:13:17 +08:00
|
|
|
before_filter :enable_customization
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def index
|
2014-12-22 13:20:06 +08:00
|
|
|
@site_customizations = SiteCustomization.order(:name)
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: @site_customizations }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-06-06 15:14:32 +08:00
|
|
|
@site_customization = SiteCustomization.new(site_customization_params)
|
2013-02-06 03:16:51 +08:00
|
|
|
@site_customization.user_id = current_user.id
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @site_customization.save
|
2013-08-21 22:49:35 +08:00
|
|
|
log_site_customization_change(nil, site_customization_params)
|
2013-02-06 03:16:51 +08:00
|
|
|
format.json { render json: @site_customization, status: :created}
|
|
|
|
else
|
|
|
|
format.json { render json: @site_customization.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@site_customization = SiteCustomization.find(params[:id])
|
2013-08-21 22:49:35 +08:00
|
|
|
log_record = log_site_customization_change(@site_customization, site_customization_params)
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
2013-06-06 15:14:32 +08:00
|
|
|
if @site_customization.update_attributes(site_customization_params)
|
2013-02-06 03:16:51 +08:00
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
2013-08-21 22:49:35 +08:00
|
|
|
log_record.destroy if log_record
|
2013-02-06 03:16:51 +08:00
|
|
|
format.json { render json: @site_customization.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@site_customization = SiteCustomization.find(params[:id])
|
2013-08-22 00:03:21 +08:00
|
|
|
StaffActionLogger.new(current_user).log_site_customization_destroy(@site_customization)
|
2013-02-06 03:16:51 +08:00
|
|
|
@site_customization.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-06 15:14:32 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def site_customization_params
|
2014-11-11 04:51:55 +08:00
|
|
|
params.require(:site_customization)
|
2015-01-14 18:52:42 +08:00
|
|
|
.permit(:name, :stylesheet, :header, :top, :footer,
|
|
|
|
:mobile_stylesheet, :mobile_header, :mobile_top, :mobile_footer,
|
|
|
|
:head_tag, :body_tag,
|
2014-12-22 13:18:32 +08:00
|
|
|
:position, :enabled, :key,
|
2014-11-11 04:51:55 +08:00
|
|
|
:stylesheet_baked)
|
2013-06-06 15:14:32 +08:00
|
|
|
end
|
|
|
|
|
2013-08-21 22:49:35 +08:00
|
|
|
def log_site_customization_change(old_record, new_params)
|
|
|
|
StaffActionLogger.new(current_user).log_site_customization_change(old_record, new_params)
|
|
|
|
end
|
|
|
|
|
2013-11-13 01:13:17 +08:00
|
|
|
def enable_customization
|
|
|
|
session[:disable_customization] = false
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|