Orbit/app/controllers/pages_controller.rb

67 lines
2.1 KiB
Ruby
Raw Normal View History

class PagesController < ApplicationController
2012-03-21 17:51:16 +00:00
include ApplicationHelper
before_filter :get_item, :only => [:index_from_link, :show_from_link]
def index
@item = Page.find_by_name('home')
if @item
2012-05-15 13:26:09 +00:00
impressionist(@item)
2011-02-22 08:00:13 +00:00
render_page
else
render :text => 'You need a home page'
end
end
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]})
if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
impressionist(@item)
case @item._type
when 'Page'
render_page
when 'Link'
redirect_to @item[:url]
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
def index_from_link
2012-05-13 11:32:05 +00:00
url = "/#{@item.path}"
options = ''
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?
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
uri = URI::escape(url + options)
redirect_to uri
end
def show_from_link
2012-05-13 11:32:05 +00:00
url = "/#{@item.path}?id=#{params[:id]}"
options = ''
options << "&preview=#{params[:preview]}" unless params[:preview].blank?
redirect_to url + options
end
def load_orbit_bar
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
end
protected
def get_item
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
2012-05-15 13:26:09 +00:00
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action]})
2012-07-09 08:48:23 +00:00
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
end
2011-12-23 10:34:21 +00:00
end