2012-11-15 07:51:44 +00:00
|
|
|
class Admin::PagesController < Admin::ItemsController
|
2009-05-07 17:18:16 +00:00
|
|
|
|
2013-10-28 03:37:56 +00:00
|
|
|
def show
|
|
|
|
@item = Page.find(params[:id])
|
|
|
|
@no_orbit_bar = true
|
|
|
|
@edit = true
|
|
|
|
render :text => parse_page_content(@item), :layout => 'page_layout'
|
|
|
|
end
|
|
|
|
|
2009-05-07 17:18:16 +00:00
|
|
|
def create
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Page.new(params[:page])
|
2013-07-02 08:46:44 +00:00
|
|
|
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
|
2011-05-25 06:50:56 +00:00
|
|
|
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'
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-11-08 08:34:26 +00:00
|
|
|
if params[:page][:category]
|
|
|
|
if params[:page][:category][0] == ""
|
|
|
|
params[:page][:category] = []
|
|
|
|
end
|
2013-11-07 11:14:53 +00:00
|
|
|
end
|
2013-11-08 08:34:26 +00:00
|
|
|
if params[:page][:tag]
|
|
|
|
if params[:page][:tag][0] == ""
|
|
|
|
params[:page][:tag] = []
|
|
|
|
end
|
2013-11-07 11:14:53 +00:00
|
|
|
end
|
2011-08-23 18:34:24 +00:00
|
|
|
@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])
|
2014-02-07 06:59:39 +00:00
|
|
|
unless params[:page]['frontend_field'].nil?
|
|
|
|
frontend_class = []
|
|
|
|
frontend_field_name = []
|
|
|
|
frontend_sat_to_link = []
|
|
|
|
|
|
|
|
params[:page]['frontend_field'].each do |field|
|
|
|
|
frontend_class << field['class']
|
|
|
|
frontend_field_name << field['field_name']
|
|
|
|
frontend_sat_to_link << field['sat_to_link']
|
|
|
|
end
|
|
|
|
|
|
|
|
@item['frontend_class'] = frontend_class
|
|
|
|
@item['frontend_field_name'] = frontend_field_name
|
|
|
|
@item['frontend_sat_to_link'] = frontend_sat_to_link
|
|
|
|
end
|
|
|
|
|
|
|
|
@item['tag'] = params[:page]['tag'] == nil ? [] : params[:page]['tag']
|
|
|
|
|
|
|
|
@item.save
|
|
|
|
|
2013-10-27 16:59:38 +00:00
|
|
|
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
|
2013-11-06 14:30:41 +00:00
|
|
|
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
|
2013-11-27 09:50:33 +00:00
|
|
|
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]
|
2011-08-23 18:34:24 +00:00
|
|
|
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
|
2011-08-23 18:34:24 +00:00
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|