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]
|
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
|
2012-08-04 07:42:53 +00:00
|
|
|
impressionist(@item)
|
2012-08-07 11:21:54 +00:00
|
|
|
render_page
|
2009-06-01 06:20:15 +00:00
|
|
|
else
|
|
|
|
render :text => 'You need a home page'
|
|
|
|
end
|
|
|
|
end
|
2009-05-07 18:13:27 +00:00
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
def show
|
2012-05-15 13:26:09 +00:00
|
|
|
#begin
|
|
|
|
@item = Item.first(:conditions => {:path => params[:page_name]})
|
2012-08-07 11:21:54 +00:00
|
|
|
if @item && @item.is_published #&& (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
|
2012-08-04 07:42:53 +00:00
|
|
|
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'
|
|
|
|
render_page unless save_from_no_lang_for_page
|
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-01-24 03:38:53 +00:00
|
|
|
#rescue
|
|
|
|
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
|
|
|
#end
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|
2012-01-24 10:16:58 +00:00
|
|
|
|
|
|
|
def index_from_link
|
2012-05-13 11:32:05 +00:00
|
|
|
url = "/#{@item.path}"
|
|
|
|
options = ''
|
2012-05-13 14:35:00 +00:00
|
|
|
options << "?page_main=#{params[:page_main]}" unless params[:page_main].blank?
|
2012-05-13 11:32:05 +00:00
|
|
|
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?
|
2012-06-20 06:50:51 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
|
2012-08-07 11:21:54 +00:00
|
|
|
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
|
2012-06-20 06:50:51 +00:00
|
|
|
uri = URI::escape(url + options)
|
2012-08-07 11:21:54 +00:00
|
|
|
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
|
|
|
redirect_to(uri)unless save_from_no_lang_for_page
|
2012-01-24 10:16:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_from_link
|
2012-05-13 11:32:05 +00:00
|
|
|
url = "/#{@item.path}?id=#{params[:id]}"
|
|
|
|
options = ''
|
2012-08-13 03:34:14 +00:00
|
|
|
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?
|
2012-05-13 11:32:05 +00:00
|
|
|
options << "&preview=#{params[:preview]}" unless params[:preview].blank?
|
2012-08-07 11:21:54 +00:00
|
|
|
redirect_to(url + options) unless save_from_no_lang_for_page
|
2012-01-24 10:16:58 +00:00
|
|
|
end
|
|
|
|
|
2012-02-13 05:02:52 +00:00
|
|
|
def load_orbit_bar
|
2012-02-28 20:21:56 +00:00
|
|
|
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
|
2012-02-13 05:02:52 +00:00
|
|
|
end
|
|
|
|
|
2012-01-24 10:16:58 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def get_item
|
2012-02-06 14:09:33 +00:00
|
|
|
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
2012-08-01 08:33:46 +00:00
|
|
|
if !params[:category_id].blank? && !params[:tag_id].blank?
|
|
|
|
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
|
2012-08-03 09:12:54 +00:00
|
|
|
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
|
2012-08-01 08:33:46 +00:00
|
|
|
elsif !params[:category_id].blank?
|
2012-08-07 11:21:54 +00:00
|
|
|
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
|
2012-08-01 08:33:46 +00:00
|
|
|
elsif !params[:tag_id].blank?
|
2012-08-07 11:21:54 +00:00
|
|
|
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
|
2012-08-01 08:33:46 +00:00
|
|
|
end
|
2012-08-07 11:21:54 +00:00
|
|
|
@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
|
2012-07-09 08:48:23 +00:00
|
|
|
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
|
2012-01-24 10:16:58 +00:00
|
|
|
end
|
2011-12-23 10:34:21 +00:00
|
|
|
|
2012-08-07 11:21:54 +00:00
|
|
|
protected
|
|
|
|
def save_from_no_lang_for_page
|
|
|
|
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
|
|
|
|
flash[:notice] = t('sys.module_page_lang_not_support')
|
|
|
|
redirect_to '/'
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|