2012-11-15 07:51:44 +00:00
|
|
|
class Admin::PagesController < Admin::ItemsController
|
2013-04-11 19:13:03 +00:00
|
|
|
helper Admin::PagePartsHelper
|
|
|
|
include Admin::FrontendWidgetInterface
|
|
|
|
|
2009-05-07 17:18:16 +00:00
|
|
|
def show
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Page.find(params[:id])
|
2013-04-11 19:13:03 +00:00
|
|
|
@no_orbit_bar = true
|
|
|
|
render layout: 'page_layout'
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2013-04-11 19:13:03 +00:00
|
|
|
@item = Page.new(params[:page])
|
2012-02-17 06:54:11 +00:00
|
|
|
@item.parent = Item.find(params[:parent_id]) rescue nil
|
2013-04-11 19:13:03 +00:00
|
|
|
get_variables_for_new
|
|
|
|
render layout: false
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-03-11 10:21:17 +00:00
|
|
|
@item = Page.find(params[:id])
|
2013-04-11 19:13:03 +00:00
|
|
|
get_variables_for_edit
|
|
|
|
render layout: false
|
2013-04-01 09:06:10 +00:00
|
|
|
end
|
2013-01-21 08:56:37 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
def reload_themes
|
|
|
|
design = Design.find(params[:design_id])
|
|
|
|
@themes = design.themes
|
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
|
|
|
end
|
|
|
|
end
|
2013-03-11 10:21:17 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
def reload_frontend_pages
|
|
|
|
@item = Page.find(params[:id]) rescue Page.new
|
|
|
|
@selected={
|
|
|
|
:design => nil,
|
|
|
|
:theme=> nil,
|
|
|
|
:module_app=>(ModuleApp.find(params[:module_app_id]) rescue nil),
|
|
|
|
:app_frontend_url=> @item.app_frontend_url || 'default_widget', #@module_apps.first
|
|
|
|
:category=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:tag=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:page_frontend_data_count=>nil,
|
|
|
|
:frontend_style => nil
|
|
|
|
}
|
|
|
|
@app_frontend_urls = @selected[:module_app] ? select_array_for_app_frontend_urls(@selected[:module_app].app_pages) : nil
|
2013-03-11 10:21:17 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
get_categories_and_tags
|
|
|
|
get_frontend_data_count
|
|
|
|
get_frontend_styles
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
2012-04-29 22:27:38 +00:00
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
2013-04-01 09:06:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def reload_front_end_setting
|
|
|
|
@item = Page.find(params[:id]) rescue Page.new
|
|
|
|
|
|
|
|
@categories = nil
|
|
|
|
@tags = nil
|
|
|
|
@page_frontend_data_counts = nil
|
|
|
|
|
|
|
|
@selected={
|
|
|
|
# :design => @item.design || @designs.first,
|
|
|
|
# :theme=> @item.theme,
|
|
|
|
:module_app=>ModuleApp.find(params[:module_app_id]),
|
|
|
|
:app_frontend_url=> params[:frontend] ,
|
|
|
|
:category=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:tag=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:page_frontend_data_count=>nil,
|
|
|
|
:frontend_style => nil
|
|
|
|
}
|
|
|
|
@app_frontend_urls = @selected[:module_app].nil? ? nil : @selected[:module_app].app_pages.each{|name,data| [I18n.t(data["i18n"]),name]}
|
|
|
|
@frontend_styles = @selected[:module_app].app_pages[params["frontend"]]["style"] rescue nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def reload_widget_field
|
|
|
|
@index = params[:field_seri].to_i
|
|
|
|
@item = Page.find(params[:id]) rescue Page.new
|
|
|
|
@selected = {
|
2013-04-02 10:39:46 +00:00
|
|
|
:module_app=> (ModuleApp.find(params[:module_app_id]) || @item.module_app ),
|
2013-04-01 09:06:10 +00:00
|
|
|
:default_widget_field=>params[:widget_field_value]
|
|
|
|
}
|
|
|
|
# @choosen_field = params[:widget_field_value]
|
|
|
|
# @module_app = @item.module_app
|
|
|
|
# @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil?
|
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
|
|
|
|
def create
|
2013-04-01 09:06:10 +00:00
|
|
|
clean_tags_and_category_params
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Page.new(params[:page])
|
2012-02-21 11:22:42 +00:00
|
|
|
|
2013-04-11 19:13:03 +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
|
2012-02-21 11:22:42 +00:00
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
if @item.save
|
2012-09-12 11:12:50 +00:00
|
|
|
flash.now[:notice] = t('create.success.page')
|
2011-06-01 02:24:14 +00:00
|
|
|
respond_to do |format|
|
2013-04-11 19:13:03 +00:00
|
|
|
format.js { render 'admin/items/reload_items' }
|
2011-06-01 02:24:14 +00:00
|
|
|
end
|
2010-01-04 09:49:55 +00:00
|
|
|
else
|
2013-04-11 19:13:03 +00:00
|
|
|
get_variables_for_new
|
2011-06-01 02:24:14 +00:00
|
|
|
render :action => "new"
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-04-01 09:06:10 +00:00
|
|
|
clean_tags_and_category_params
|
2011-08-23 18:34:24 +00:00
|
|
|
@item = Page.find(params[:id])
|
2012-02-24 11:11:51 +00:00
|
|
|
|
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
|
2011-08-25 00:13:38 +00:00
|
|
|
if @item.update_attributes(params[:page])
|
2012-09-12 11:12:50 +00:00
|
|
|
flash[:notice] = t('update.success.page')
|
2011-08-23 18:34:24 +00:00
|
|
|
respond_to do |format|
|
2013-04-11 19:13:03 +00:00
|
|
|
format.js { render 'admin/items/reload_items' }
|
2011-08-23 18:34:24 +00:00
|
|
|
end
|
|
|
|
else
|
2013-04-11 19:13:03 +00:00
|
|
|
get_variables_for_edit
|
2011-08-23 18:34:24 +00:00
|
|
|
render :action => "edit"
|
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
protected
|
2013-03-11 10:21:17 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
def get_frontend_styles
|
|
|
|
has_old_value = @selected[:module_app].app_pages[@selected[:app_frontend_url]]
|
|
|
|
@frontend_styles = has_old_value ? has_old_value["style"] : (@selected[:module_app].app_pages.first[1]["style"] rescue nil)
|
2013-01-21 08:56:37 +00:00
|
|
|
end
|
2013-04-11 19:13:03 +00:00
|
|
|
|
|
|
|
def get_variables_for_new
|
|
|
|
@designs = Design.all.entries
|
|
|
|
@themes = Design.first.themes
|
|
|
|
@module_apps = ModuleApp.for_frontend_select
|
|
|
|
@app_frontend_urls = nil
|
|
|
|
@categories = nil
|
|
|
|
@tags = nil
|
|
|
|
@page_frontend_data_counts = nil
|
|
|
|
@frontend_styles = nil
|
|
|
|
@selected={
|
|
|
|
:design => @designs.first,
|
|
|
|
:theme=> @themes.first,
|
|
|
|
:module_app=>nil,#@module_apps.first
|
|
|
|
:app_frontend_url=> nil, #@module_apps.first
|
|
|
|
:category=>nil,
|
|
|
|
:tag=>nil,
|
|
|
|
:page_frontend_data_count=>nil,
|
|
|
|
:frontend_style => nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_variables_for_edit
|
|
|
|
@designs = Design.all.entries
|
|
|
|
@themes = @item.design ? @item.design.themes : @designs.first.themes
|
|
|
|
@module_apps = ModuleApp.for_frontend_select
|
|
|
|
@categories = nil
|
|
|
|
@tags = nil
|
|
|
|
@page_frontend_data_counts = nil
|
|
|
|
@frontend_styles = nil
|
|
|
|
|
|
|
|
@selected={
|
|
|
|
:design => @item.design || @designs.first,
|
|
|
|
:theme=> @item.theme,
|
|
|
|
:module_app=>@item.module_app,#@module_apps.first
|
|
|
|
:app_frontend_url=> @item.app_frontend_url, #@module_apps.first
|
|
|
|
:category=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:tag=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:page_frontend_data_count=>nil,
|
|
|
|
:frontend_style => nil
|
|
|
|
}
|
|
|
|
@app_frontend_urls = @item.module_app ? select_array_for_app_frontend_urls(@item.module_app.app_pages) : nil
|
|
|
|
get_categories_and_tags
|
|
|
|
get_frontend_data_count
|
|
|
|
end
|
|
|
|
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|