2009-05-07 17:18:16 +00:00
|
|
|
class PagesController < ApplicationController
|
2012-03-21 17:51:16 +00:00
|
|
|
include ApplicationHelper
|
2012-01-24 10:16:58 +00:00
|
|
|
before_filter :get_item, :only => [:index_from_link, :show_from_link]
|
2013-04-23 10:48:18 +00:00
|
|
|
before_filter :check_frontend_open, :only => [:index,:show]
|
2012-07-26 21:08:24 +00:00
|
|
|
# caches_page :index
|
2012-07-26 07:44:53 +00:00
|
|
|
|
2009-06-01 06:20:15 +00:00
|
|
|
def index
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Page.find_by_name('home')
|
2012-07-12 03:47:24 +00:00
|
|
|
|
2012-07-13 07:36:10 +00:00
|
|
|
if @item
|
2013-10-30 10:23:46 +00:00
|
|
|
# delayed_impressionist(@item)
|
|
|
|
impressionist(@item)
|
2013-10-21 03:13:15 +00:00
|
|
|
if params[:edit]
|
|
|
|
if request.referer && request.referer.ends_with?("admin/items")
|
|
|
|
redirect_to admin_page_url(@item)
|
|
|
|
else
|
|
|
|
render :file => "#{Rails.root}/public/403.html", :status => 403
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render_page
|
|
|
|
end
|
2009-06-01 06:20:15 +00:00
|
|
|
else
|
2013-05-14 03:26:35 +00:00
|
|
|
redirect_to '/admin/dashboards',:notice=>t(:need_home)
|
|
|
|
# render :text => t(:need_home)
|
2009-06-01 06:20:15 +00:00
|
|
|
end
|
|
|
|
end
|
2009-05-07 18:13:27 +00:00
|
|
|
|
2013-04-03 11:03:16 +00:00
|
|
|
def show
|
2012-05-15 13:26:09 +00:00
|
|
|
#begin
|
|
|
|
@item = Item.first(:conditions => {:path => params[:page_name]})
|
2013-10-11 13:08:22 +00:00
|
|
|
|
2012-09-11 02:52:27 +00:00
|
|
|
if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
|
2013-10-30 10:23:46 +00:00
|
|
|
# delayed_impressionist(@item)
|
|
|
|
impressionist(@item)
|
2012-07-30 10:34:54 +00:00
|
|
|
case @item.class.to_s
|
2012-08-07 11:21:54 +00:00
|
|
|
when 'Page'
|
2013-04-03 11:03:16 +00:00
|
|
|
if params[:clicked_field_name]
|
|
|
|
render_page({"clicked_field_name"=>params["clicked_field_name"]}) unless save_from_no_lang_for_page
|
2013-10-20 10:44:04 +00:00
|
|
|
elsif params[:edit]
|
|
|
|
if request.referer && request.referer.ends_with?("admin/items")
|
|
|
|
redirect_to admin_page_url(@item)
|
2013-04-03 11:03:16 +00:00
|
|
|
else
|
2013-10-20 10:44:04 +00:00
|
|
|
render :file => "#{Rails.root}/public/403.html", :status => 403
|
|
|
|
end
|
|
|
|
else
|
2013-10-08 06:52:24 +00:00
|
|
|
render_page(params.except(:controller, :action, :page_name)) unless save_from_no_lang_for_page
|
2013-04-03 11:03:16 +00:00
|
|
|
end
|
2012-05-15 13:26:09 +00:00
|
|
|
when 'Link'
|
2012-08-07 11:21:54 +00:00
|
|
|
redirect_to(@item[:url]) unless save_from_no_lang_for_page
|
2012-05-15 13:26:09 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
|
|
|
end
|
2012-12-19 09:15:31 +00:00
|
|
|
#rescue
|
|
|
|
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
|
|
|
#end
|
|
|
|
end
|
2012-01-24 10:16:58 +00:00
|
|
|
|
2013-05-31 03:30:01 +00:00
|
|
|
def convert_array_param(key,array)
|
|
|
|
array.collect{|t| "#{key}[]=#{t}"}.join("&")
|
|
|
|
end
|
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
def index_from_link
|
|
|
|
url = "/#{@item.path}"
|
|
|
|
options = ''
|
|
|
|
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
|
2013-11-15 14:29:57 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}click=#{params[:click]}" unless params[:click].blank?
|
2013-11-18 09:11:47 +00:00
|
|
|
# options << "#{options.blank? ? '?' : '&'}part_id=#{params[:page_part_id]}" unless params[:page_part_id].blank?
|
2013-05-31 03:30:01 +00:00
|
|
|
|
|
|
|
if params[:category_id].is_a? Array
|
2013-11-18 09:11:47 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('filter_category_id',params[:category_id])}" unless params[:category_id].blank?
|
2013-05-31 03:30:01 +00:00
|
|
|
elsif params[:category_id].is_a? String
|
2013-11-18 09:11:47 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}filter_category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
2013-05-31 03:30:01 +00:00
|
|
|
end
|
|
|
|
if params[:tag_id].is_a? Array
|
2013-11-18 09:11:47 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('filter_tag_id',params[:tag_id])}" unless params[:tag_id].blank?
|
2013-05-31 03:30:01 +00:00
|
|
|
elsif params[:category_id].is_a? String
|
2013-11-18 09:11:47 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}filter_tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
2013-05-31 03:30:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
|
|
|
|
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
|
2013-11-18 09:11:47 +00:00
|
|
|
# uri = URI::escape(url + options)
|
|
|
|
uri = url + options
|
2013-11-15 08:58:27 +00:00
|
|
|
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
2012-12-19 09:15:31 +00:00
|
|
|
redirect_to(uri)unless save_from_no_lang_for_page
|
|
|
|
end
|
2012-01-24 10:16:58 +00:00
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
def show_from_link
|
|
|
|
url = "/#{@item.path}"
|
|
|
|
options = ''
|
|
|
|
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank?
|
|
|
|
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
|
|
|
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
|
|
|
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
|
|
|
|
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank?
|
2013-04-03 11:03:16 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}clicked_field_name=#{params[:clicked_field_name]}" unless params[:clicked_field_name].blank?
|
2013-11-18 17:58:23 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}image_id=#{params[:image_id]}" unless params[:image_id].blank?
|
2012-12-19 09:15:31 +00:00
|
|
|
redirect_to(url + options) unless save_from_no_lang_for_page
|
|
|
|
end
|
2012-01-24 10:16:58 +00:00
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
def load_orbit_bar
|
2013-07-29 11:49:07 +00:00
|
|
|
@referer = request.referer
|
|
|
|
render partial: 'layouts/orbit_bar'
|
2012-12-19 09:15:31 +00:00
|
|
|
end
|
2012-02-13 05:02:52 +00:00
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
protected
|
2012-01-24 10:16:58 +00:00
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
def get_item
|
2013-11-15 14:29:57 +00:00
|
|
|
# if params[:page_id]
|
|
|
|
# @item = Item.find(params[:page_id])
|
|
|
|
# elsif params[:same_page_id]
|
|
|
|
# @item = Item.find(params[:same_page_id])
|
|
|
|
# else
|
|
|
|
# category_ids = Array(params[:category_id]) unless params[:category_id].nil?
|
|
|
|
# tag_ids = Array(params[:tag_id]) unless params[:tag_id].nil?
|
|
|
|
# module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
2013-11-15 09:32:00 +00:00
|
|
|
|
2013-11-15 14:29:57 +00:00
|
|
|
# default_query = { is_published: true, module_app_id: module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget'] }
|
|
|
|
# specific_categories = { :category => category_ids }
|
|
|
|
# in_categories = { :category.in => category_ids }
|
|
|
|
# nil_categories = { :category.in => [nil, []] }
|
|
|
|
# specific_tags = { :tag => tag_ids }
|
|
|
|
# in_tags = { :tag.in => tag_ids }
|
|
|
|
# nil_tags = { :tag.in => [nil, []] }
|
2013-11-15 09:32:00 +00:00
|
|
|
|
2013-11-15 14:29:57 +00:00
|
|
|
# if !category_ids.blank? && !tag_ids.blank?
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(specific_tags)).first
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(in_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(nil_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags).merge(in_categories)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags).merge(nil_categories)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_categories).merge(in_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_categories).merge(nil_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_tags).merge(nil_categories)).first unless @item
|
|
|
|
# elsif !category_ids.blank?
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(nil_tags)).first
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_categories).merge(nil_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_categories)).first unless @item
|
|
|
|
# elsif !tag_ids.blank?
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags).merge(nil_categories)).first
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_tags).merge(nil_categories)).first unless @item
|
|
|
|
# @item = Item.where(default_query.merge(in_tags)).first unless @item
|
|
|
|
# end
|
|
|
|
# @item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
|
|
|
|
# @item = Item.where(default_query.merge(nil_categories).merge(nil_tags)).first unless @item
|
|
|
|
# @item = Item.where(default_query).first unless @item
|
|
|
|
# end
|
|
|
|
# raise PageError, 'Missing Frontend Page' if @item.nil?
|
2013-11-15 09:32:00 +00:00
|
|
|
|
|
|
|
# if params[:page_id]
|
|
|
|
# @item = Item.find(params[:page_id])
|
|
|
|
# elsif params[:same_page_id]
|
|
|
|
# @item = Item.find(params[:same_page_id])
|
|
|
|
# else
|
|
|
|
# category_ids = params[:category_id].is_a?(Array) ? params[:category_id] : [params[:category_id]]
|
|
|
|
# tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]]
|
|
|
|
# module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
|
|
|
# if !category_ids.blank? && !tag_ids.blank?
|
|
|
|
# @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => category_ids, :tag.in => tag_ids})
|
|
|
|
# @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => category_ids, :tag.in => [nil, []]}) unless @item
|
|
|
|
# elsif !category_ids.blank?
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :category.in => category_ids).any_in(tag: [nil, []]).first
|
|
|
|
# elsif !tag_ids.blank?
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :tag.in => tag_ids).any_in(category: [nil, []]).first
|
|
|
|
# end
|
|
|
|
# @item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).all_of("tag" => {"$in" => [nil, []]},"category" => { "$in" => [nil, []]}).first unless @item
|
2013-11-18 09:11:47 +00:00
|
|
|
# # @item = Item.root.children.where(:module_app_id => module_app.id).first
|
2013-11-15 09:32:00 +00:00
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
|
|
|
|
# end
|
|
|
|
# raise PageError,'Missing Frontend Page' if @item.nil?
|
2013-11-18 09:11:47 +00:00
|
|
|
|
2013-11-15 14:29:57 +00:00
|
|
|
if params[:page_id]
|
|
|
|
@item = Item.find(params[:page_id])
|
|
|
|
elsif params[:same_page_id]
|
|
|
|
@item = Item.find(params[:same_page_id])
|
|
|
|
else
|
|
|
|
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
2013-11-18 09:11:47 +00:00
|
|
|
category_ids = params[:category_id] ? (params[:category_id].is_a?(Array) ? params[:category_id] : [params[:category_id]]) : []
|
|
|
|
tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]]
|
|
|
|
|
|
|
|
if !category_ids.blank?
|
|
|
|
@item = Item.where(:category => category_ids).first
|
|
|
|
else
|
|
|
|
if params[:action] && params[:action] == "show_from_link"
|
2013-11-19 09:13:27 +00:00
|
|
|
model = params[:app_action].classify.constantize rescue nil
|
|
|
|
if !model.nil?
|
|
|
|
item = model.find(params[:id])
|
|
|
|
@item = Item.where(:category => [item.category_id.to_s]).first
|
|
|
|
end
|
2013-11-18 09:11:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@item = Item.root.children.where(:module_app_id => module_app.id).first unless @item
|
2013-11-15 14:29:57 +00:00
|
|
|
end
|
|
|
|
raise PageError,'Missing Frontend Page' if @item.nil?
|
2012-12-19 09:15:31 +00:00
|
|
|
end
|
2013-09-06 08:41:02 +00:00
|
|
|
|
|
|
|
def check_frontend_open
|
2013-11-04 07:41:23 +00:00
|
|
|
if !Site.first.frontend_open && current_user.nil? #Need to be change
|
2013-09-06 08:41:02 +00:00
|
|
|
redirect_to '/admin/dashboards'
|
|
|
|
end
|
|
|
|
end
|
2011-12-23 10:34:21 +00:00
|
|
|
|
2012-08-07 11:21:54 +00:00
|
|
|
def save_from_no_lang_for_page
|
2012-12-19 09:15:31 +00:00
|
|
|
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
|
|
|
|
flash[:error] = t('sys.module_page_lang_not_support')
|
|
|
|
redirect_to '/'
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2012-08-07 11:21:54 +00:00
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|