This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/pages_controller.rb

87 lines
3.1 KiB
Ruby
Raw Permalink Normal View History

class Admin::PagesController < Admin::ItemsController
def show
@item = Page.find(params[:id])
@no_orbit_bar = true
@edit = true
render :text => parse_page_content(@item), :layout => 'page_layout'
end
def create
@item = Page.new(params[:page])
if @item.module_app && @item.module_app.key == 'page_content'
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end
if @item.save
2013-10-27 16:59:38 +00:00
render 'admin/items/reload_items'
2010-01-04 09:49:55 +00:00
else
2013-10-27 16:59:38 +00:00
@error = error_messages_for(@item)
render 'admin/items/form_error'
end
end
def update
if params[:page][:category]
if params[:page][:category][0] == ""
params[:page][:category] = []
end
2013-11-07 11:14:53 +00:00
end
if params[:page][:tag]
if params[:page][:tag][0] == ""
params[:page][:tag] = []
end
2013-11-07 11:14:53 +00:00
end
@item = Page.find(params[:id])
2013-01-21 08:56:37 +00:00
if @item.module_app && @item.module_app.key == 'page_content' && @item.page_contexts.blank?
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end
2013-10-27 16:59:38 +00:00
if @item.update_attributes(params[:page])
render 'admin/items/reload_items'
else
2013-10-23 07:51:49 +00:00
@error = error_messages_for(@item)
2013-10-27 16:59:38 +00:00
render 'admin/items/form_error'
2013-10-23 07:51:49 +00:00
end
end
def get_display_style
2013-10-27 16:59:38 +00:00
@item = Page.find(params[:id]) rescue nil
@module_app = ModuleApp.find(params[:module_id]) rescue nil
if @module_app
if params[:val].eql?("default_widget")
@checked_style = @item.frontend_style.present? ? @item.frontend_style : nil if @item && @item.app_frontend_url.eql?("default_widget")
@enabled_styles = @module_app.get_default_widget["enabled_styles"]
@widget_fields = @module_app.widget_fields.collect do |widget_field|
label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}")
[label, widget_field[0], class: widget_field[2]]
end
@class_options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
@partial = 'default_front'
else
@frontend_styles = @module_app.app_pages[params[:val]]["style"] rescue nil
@partial = 'custom_front' if @frontend_styles.present?
end
end
2013-10-23 07:51:49 +00:00
end
def get_page_setting_json
begin
page = Page.find(params[:id])
design = {main: page.design_id.to_s, sub: page.theme_id.to_s}
m = {}
m["main"] = page.module_app_id.to_s
m["sub"] = page.app_frontend_url
m["category"] = page.category.present? ? page.category.map{|c| c.to_s} : []
m["tags"] = page.tag.present? ? page.tag.map{|c| c.to_s} : []
2013-10-23 07:51:49 +00:00
m["public"] = page.is_published ? 1 : 0
m["link"] = @site_in_use_locales.inject([]) do |link, locale|
2013-10-29 06:39:23 +00:00
link << [locale, (page.enabled_for && page.enabled_for.include?(locale)) ? 1 : 0, (page.menu_enabled_for && page.menu_enabled_for[locale].eql?('true')) ? 1 :0]
end
2013-10-23 07:51:49 +00:00
m["count"] = page.frontend_data_count
render json: JSON.pretty_generate({design: design, module: m})
rescue
2013-10-23 10:28:09 +00:00
render :json => {error: ''}, status: 422
end
end
end