2014-05-05 06:04:50 +00:00
|
|
|
# pass the layout=false for not rendering the layouts and also can specify the methods to in the backend controller.
|
|
|
|
# data-layout-content="arrayname" in layouts can be used to render data in the array
|
2014-07-09 02:05:02 +00:00
|
|
|
require 'zhconv'
|
2014-07-16 10:48:23 +00:00
|
|
|
require "uri"
|
2014-04-01 07:10:21 +00:00
|
|
|
class PagesController < ApplicationController
|
2014-05-20 02:31:44 +00:00
|
|
|
before_action :get_key
|
2014-04-01 07:10:21 +00:00
|
|
|
layout :get_layout
|
|
|
|
include PagesHelper
|
2014-05-20 02:31:44 +00:00
|
|
|
before_filter :check_frontend_open, :only => [:home,:show]
|
2014-05-29 04:08:56 +00:00
|
|
|
before_filter :check_authorization, :except => [:home,:show]
|
2014-07-24 06:00:43 +00:00
|
|
|
before_filter :set_edit_mode
|
2014-04-01 07:10:21 +00:00
|
|
|
|
|
|
|
def index
|
2014-12-26 02:26:40 +00:00
|
|
|
@pages = Page.all
|
2014-04-01 07:10:21 +00:00
|
|
|
# render json: @pages
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_view
|
|
|
|
@manifest = @key
|
|
|
|
@dataApi = "edit"
|
2014-05-22 11:19:25 +00:00
|
|
|
view = get_view
|
|
|
|
if File.exists?(view)
|
|
|
|
render view
|
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
|
2014-04-07 07:57:06 +00:00
|
|
|
def home
|
|
|
|
@manifest = @key
|
2014-04-14 03:27:09 +00:00
|
|
|
page = Page.first
|
2014-05-15 11:32:51 +00:00
|
|
|
impressionist(page)
|
2014-08-05 06:45:52 +00:00
|
|
|
OrbitHelper.set_params params,current_user
|
2014-04-07 07:57:06 +00:00
|
|
|
OrbitHelper.set_site_locale locale
|
2014-07-11 13:06:23 +00:00
|
|
|
render :html => render_final_page("home",page,true).html_safe
|
2014-04-07 07:57:06 +00:00
|
|
|
end
|
|
|
|
|
2014-04-01 07:10:21 +00:00
|
|
|
def show
|
2014-06-06 08:30:56 +00:00
|
|
|
display_type = ""
|
2014-05-28 12:05:39 +00:00
|
|
|
path = request.path.split('/')
|
2014-05-29 03:44:35 +00:00
|
|
|
if path.size <= 2
|
2014-04-01 15:38:17 +00:00
|
|
|
redirect_to root_path
|
2014-04-01 12:40:03 +00:00
|
|
|
else
|
|
|
|
if path.last.include? '-'
|
|
|
|
params[:page_id] = path[-2]
|
2014-06-30 10:08:48 +00:00
|
|
|
s = CGI.unescape(path[-1])
|
|
|
|
s.encode!('UTF-8')
|
|
|
|
params[:slug] = s
|
2014-05-05 06:04:50 +00:00
|
|
|
uid = path[-1].split("-").last
|
|
|
|
uid = uid.split("?").first
|
|
|
|
params[:uid] = uid
|
|
|
|
params[:target_action] = params[:method] || "show"
|
2014-06-06 08:30:56 +00:00
|
|
|
display_type = "show"
|
2014-04-01 12:40:03 +00:00
|
|
|
else
|
|
|
|
params[:page_id] = path[-1]
|
|
|
|
params[:slug] = nil
|
|
|
|
params[:uid] = nil
|
2014-05-05 06:04:50 +00:00
|
|
|
params[:target_action] = params[:method] || "index"
|
2014-06-06 08:30:56 +00:00
|
|
|
display_type = "index"
|
2014-06-04 12:36:12 +00:00
|
|
|
OrbitHelper.set_page_number params[:page_no].to_i || 1
|
2014-04-01 12:40:03 +00:00
|
|
|
end
|
|
|
|
page = Page.find_by_param(params[:page_id])
|
2014-04-21 07:19:29 +00:00
|
|
|
if !page.nil?
|
2014-07-11 13:06:23 +00:00
|
|
|
if !page.enabled_for_mobile && !$mobile.blank?
|
|
|
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
|
|
|
|
return
|
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
if page.enabled_for.include? I18n.locale.to_s
|
2014-07-25 04:24:58 +00:00
|
|
|
if page.page_type == "link"
|
|
|
|
redirect_to page.external_url
|
|
|
|
return
|
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
module_app = page.module.downcase.pluralize
|
|
|
|
params[:target_controller] = "#{module_app}"
|
2014-06-06 08:30:56 +00:00
|
|
|
if display_type == "index"
|
|
|
|
params[:layout_type] = params[:method] || page.layout || "index"
|
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
params[:url] = page.url
|
2014-12-09 14:00:40 +00:00
|
|
|
categories = []
|
2014-12-26 02:26:40 +00:00
|
|
|
page.categories.each do |c|
|
|
|
|
category = Category.find(c) rescue nil
|
|
|
|
if !category.nil? && !category.disable
|
|
|
|
categories << c
|
2014-12-09 13:25:51 +00:00
|
|
|
end
|
|
|
|
end
|
2014-12-26 02:26:40 +00:00
|
|
|
categories = ["all"] if categories.blank?
|
2014-04-21 07:19:29 +00:00
|
|
|
@manifest = @key
|
2014-08-05 06:45:52 +00:00
|
|
|
OrbitHelper.set_params params,current_user
|
2014-04-21 07:19:29 +00:00
|
|
|
OrbitHelper.set_site_locale locale
|
2014-05-14 11:47:25 +00:00
|
|
|
OrbitHelper.set_this_module_app module_app.singularize
|
2014-12-09 13:25:51 +00:00
|
|
|
OrbitHelper.set_page_categories categories || ["all"]
|
2014-07-11 13:12:08 +00:00
|
|
|
OrbitHelper.set_page_tags page.tags || []
|
2014-07-23 16:04:10 +00:00
|
|
|
OrbitHelper.set_page_role_status page.role_status || []
|
2014-07-31 07:41:28 +00:00
|
|
|
OrbitHelper.set_member_sort_position page.member_sort_position
|
2014-04-21 07:19:29 +00:00
|
|
|
OrbitHelper.set_page_data_count page.data_count
|
2014-05-05 06:04:50 +00:00
|
|
|
if params[:layout].kind_of?(String)
|
|
|
|
layout = to_bool(params[:layout])
|
|
|
|
else
|
|
|
|
layout = true
|
|
|
|
end
|
|
|
|
|
2014-05-15 11:32:51 +00:00
|
|
|
impressionist(page)
|
2014-07-10 07:49:29 +00:00
|
|
|
render :html => render_final_page("#{module_app}/#{params[:target_action]}",page,layout).html_safe
|
2014-04-21 07:19:29 +00:00
|
|
|
else
|
2014-05-20 02:31:44 +00:00
|
|
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
|
2014-04-21 07:19:29 +00:00
|
|
|
end
|
|
|
|
else
|
2014-05-20 02:31:44 +00:00
|
|
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
|
2014-04-21 07:19:29 +00:00
|
|
|
end
|
2014-04-01 12:40:03 +00:00
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
|
2014-04-21 07:19:29 +00:00
|
|
|
def update_item_position
|
|
|
|
@page = Page.find(params[:id])
|
|
|
|
new_parent_page = Page.find(params[:parent_id])
|
|
|
|
old_parent_page_id = @page.parent_page_id
|
|
|
|
@page.parent_page_id = new_parent_page.id
|
|
|
|
if new_parent_page.id != old_parent_page_id
|
|
|
|
url = (new_parent_page.url == "/" ? "" : new_parent_page.url)
|
|
|
|
@page.url = url + "/#{@page.page_id}"
|
|
|
|
end
|
|
|
|
@page.save
|
|
|
|
params["children_ids"].each_with_index do |child,i|
|
|
|
|
page = Page.find(child)
|
|
|
|
page.number = i
|
|
|
|
page.save
|
|
|
|
end
|
|
|
|
|
|
|
|
if new_parent_page.id != old_parent_page_id
|
|
|
|
old_parent_page = Page.find(old_parent_page_id)
|
|
|
|
|
2014-09-26 09:10:17 +00:00
|
|
|
# old_parent_page.child_page.each_with_index do |page,i|
|
|
|
|
# page.number = i
|
|
|
|
# page.save
|
|
|
|
# end
|
|
|
|
params["parent_children_ids"] = params["parent_children_ids"] || []
|
|
|
|
params["parent_children_ids"].each_with_index do |child, i|
|
|
|
|
page = Page.find(child)
|
2014-04-21 07:19:29 +00:00
|
|
|
page.number = i
|
|
|
|
page.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render :json => {"success"=>true}.to_json
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:10:21 +00:00
|
|
|
def preview
|
|
|
|
render render_final_page
|
|
|
|
end
|
|
|
|
|
2014-04-11 11:38:56 +00:00
|
|
|
def destroy
|
|
|
|
page = Page.find(params[:id])
|
2014-07-21 14:20:36 +00:00
|
|
|
@parent_pages = page.parent_pages_without_root
|
2014-04-11 11:38:56 +00:00
|
|
|
page.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-21 07:19:29 +00:00
|
|
|
def get_categories
|
|
|
|
module_app = ModuleApp.find_by_key(params[:module]);
|
2014-06-27 03:38:06 +00:00
|
|
|
if module_app.key.eql?("member")
|
2014-07-29 03:18:15 +00:00
|
|
|
roles = Role.order_by(:_id=>'ASC').all.collect do |role|
|
2014-06-27 03:38:06 +00:00
|
|
|
{
|
2014-07-23 16:04:10 +00:00
|
|
|
"title" => role.title,
|
|
|
|
"id" => role.id.to_s,
|
|
|
|
"status" => RoleStatus.where(:role=>role).collect do |status|
|
|
|
|
{
|
|
|
|
"title" => status.title,
|
|
|
|
"id" => status.id.to_s
|
|
|
|
}
|
|
|
|
end
|
2014-06-27 03:38:06 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
2014-12-01 11:11:40 +00:00
|
|
|
if !module_app.key.eql?("page_content")
|
2014-12-09 13:25:51 +00:00
|
|
|
categories = module_app.categories.enabled.collect do |cat|
|
2014-12-01 11:11:40 +00:00
|
|
|
{
|
|
|
|
"title" => cat.title,
|
|
|
|
"id" => cat.id.to_s
|
|
|
|
}
|
|
|
|
end
|
2014-12-26 02:26:40 +00:00
|
|
|
tags = module_app.tags.collect do |t|
|
|
|
|
{
|
|
|
|
"name" => t.name,
|
|
|
|
"id" => t.id.to_s
|
|
|
|
}
|
|
|
|
end
|
2014-12-01 11:11:40 +00:00
|
|
|
else
|
|
|
|
categories = []
|
2014-12-26 02:26:40 +00:00
|
|
|
tags = []
|
2014-12-01 11:11:40 +00:00
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
end
|
2014-07-17 07:16:02 +00:00
|
|
|
|
2014-07-29 03:18:15 +00:00
|
|
|
roles = roles.nil? ? [] : roles
|
2014-07-17 07:16:02 +00:00
|
|
|
categories = categories.nil? ? [] : categories
|
2014-12-26 02:26:40 +00:00
|
|
|
tags = tags.nil? ? [] : tags
|
2014-06-27 03:38:06 +00:00
|
|
|
|
2014-06-18 11:38:35 +00:00
|
|
|
if module_app.data_count.nil?
|
2014-12-26 02:26:40 +00:00
|
|
|
render :json => {"categories" => categories, "tags" => tags,"roles" => roles,"layouts" => (get_layouts module_app.key),"data_count" => {"present"=>false}, "locale" => I18n.locale.to_s}.to_json
|
2014-06-18 11:38:35 +00:00
|
|
|
else
|
2014-12-26 02:26:40 +00:00
|
|
|
render :json => {"categories" => categories, "tags" => tags,"roles" => roles,"layouts" => (get_layouts module_app.key),"data_count" => {"present"=>true,"start"=>module_app.data_count.begin, "end" => module_app.data_count.end}, "locale" => I18n.locale.to_s}.to_json
|
2014-06-18 11:38:35 +00:00
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
|
|
|
|
def new
|
2014-12-26 02:26:40 +00:00
|
|
|
@page = Page.new(
|
2014-07-18 08:32:17 +00:00
|
|
|
:enabled_for_mobile=>true,
|
|
|
|
:menu_enabled_for=>["en", "zh_tw"],
|
|
|
|
:enabled_for=>["en", "zh_tw"],
|
|
|
|
:enabled_for_sitemap=>["en", "zh_tw"]
|
|
|
|
)
|
2014-12-26 02:26:40 +00:00
|
|
|
@pages = Page.where(:page_id.ne => "" , :page_id.exists => true)
|
|
|
|
@modules = ModuleApp.all.frontend_enabled.order_by(:key=>'asc')
|
2014-04-01 07:10:21 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-04-21 07:19:29 +00:00
|
|
|
def edit
|
|
|
|
@page = Page.find(params[:id])
|
2014-06-09 10:58:44 +00:00
|
|
|
if params[:type] == "page"
|
|
|
|
@pages = Page.where(:page_id.ne => "" , :page_id.exists => true)
|
|
|
|
@modules = ModuleApp.all.frontend_enabled
|
2014-06-18 11:38:35 +00:00
|
|
|
@module_app = ModuleApp.find_by_key(@page.module) rescue nil
|
2014-12-09 13:25:51 +00:00
|
|
|
@categories = @module_app.categories.enabled rescue []
|
2014-12-01 11:11:40 +00:00
|
|
|
if @module_app.key.eql?("page_content")
|
|
|
|
@categories = []
|
|
|
|
end
|
2014-07-11 13:12:08 +00:00
|
|
|
@tags = @module_app.tags rescue []
|
2014-06-27 03:38:06 +00:00
|
|
|
if @module_app.key.eql?("member")
|
2014-07-29 03:18:15 +00:00
|
|
|
@roles = Role.order_by(:_id=>'ASC').all.collect do |role|
|
2014-07-22 08:48:46 +00:00
|
|
|
{
|
2014-07-23 16:04:10 +00:00
|
|
|
"title" => role.title,
|
|
|
|
"id" => role.id.to_s,
|
|
|
|
"status" => RoleStatus.where(:role=>role)
|
2014-07-22 08:48:46 +00:00
|
|
|
}
|
|
|
|
end
|
2014-06-27 03:38:06 +00:00
|
|
|
else
|
2014-07-23 16:04:10 +00:00
|
|
|
@roles = []
|
2014-06-27 03:38:06 +00:00
|
|
|
end
|
2014-06-18 11:38:35 +00:00
|
|
|
@layout_types = get_layouts @module_app.key
|
2014-06-09 10:58:44 +00:00
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@page = Page.find(params[:id])
|
|
|
|
@page.update_attributes(page_update_params)
|
|
|
|
@page.save
|
2014-07-21 14:20:36 +00:00
|
|
|
@parent_pages = @page.parent_pages_without_root
|
2014-04-21 07:19:29 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:10:21 +00:00
|
|
|
def create
|
2014-05-22 09:57:58 +00:00
|
|
|
params['page']['page_id'] = params['page']['page_id'].gsub('-','_')
|
|
|
|
@page = Page.new(page_params)
|
2014-04-01 07:10:21 +00:00
|
|
|
@page.save!
|
2014-07-21 14:20:36 +00:00
|
|
|
@parent_pages = @page.parent_pages_without_root
|
2014-04-11 11:38:56 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
|
2014-12-26 02:26:40 +00:00
|
|
|
private
|
2014-04-01 07:10:21 +00:00
|
|
|
|
2014-06-06 08:30:56 +00:00
|
|
|
def get_layouts(module_app)
|
|
|
|
layout_types = []
|
2014-07-25 12:05:06 +00:00
|
|
|
f = File.join("#{Rails.root}/app/templates/#{@key}/modules/#{module_app}/info.json")
|
|
|
|
if File.exists?f
|
|
|
|
info = File.read(f)
|
|
|
|
hash = JSON.parse(info) rescue {}
|
|
|
|
frontends = hash["frontend"] || []
|
|
|
|
frontends.each do |frontend|
|
|
|
|
frontend["thumbnail"] = "/assets/#{module_app}/thumbs/#{frontend["thumbnail"]}"
|
|
|
|
layout_types << frontend
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if layout_types.empty?
|
|
|
|
Dir.glob("#{Rails.root}/app/templates/#{@key}/modules/#{module_app}/*").each do |w|
|
|
|
|
next if File.ftype(w).eql?("directory")
|
|
|
|
w = File.basename(w, ".*")
|
|
|
|
w = File.basename(w, ".*")
|
|
|
|
if w[0,1] != "_" && w[0,1] != "s" && w != "info"
|
|
|
|
layout_types << w
|
|
|
|
end
|
2014-06-06 08:30:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
layout_types
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:04:50 +00:00
|
|
|
def render_final_page(original_view=get_view,page,layout)
|
2014-07-10 07:49:29 +00:00
|
|
|
final_html_for_render = ""
|
2014-05-22 11:19:25 +00:00
|
|
|
if layout
|
2014-05-29 10:32:27 +00:00
|
|
|
parts = $mobile.blank? ? (page.page_parts rescue []) : (page.mobile_page_parts rescue [])
|
|
|
|
|
2014-05-22 11:19:25 +00:00
|
|
|
@part_partials = {}
|
|
|
|
|
2014-05-29 10:32:27 +00:00
|
|
|
parts.each do |part|
|
2014-06-04 08:22:48 +00:00
|
|
|
subparts = part.sub_parts.asc(:created_at)
|
2014-05-29 10:32:27 +00:00
|
|
|
partials = []
|
|
|
|
subparts.each do |subpart|
|
|
|
|
if subpart.kind == "module_widget"
|
2014-12-10 10:09:50 +00:00
|
|
|
|
2014-10-31 05:41:16 +00:00
|
|
|
OrbitHelper.set_current_widget subpart
|
2014-05-29 10:32:27 +00:00
|
|
|
OrbitHelper.set_widget_data_count subpart.data_count
|
|
|
|
OrbitHelper.set_widget_module_app subpart.module
|
|
|
|
OrbitHelper.set_widget_item_url subpart
|
2014-07-01 06:36:15 +00:00
|
|
|
OrbitHelper.set_widget_title subpart.title
|
2014-12-10 10:09:50 +00:00
|
|
|
OrbitHelper.set_widget_categories subpart.categories || ["all"]
|
2014-07-11 13:12:08 +00:00
|
|
|
OrbitHelper.set_widget_tags subpart.tags || []
|
2014-05-29 10:32:27 +00:00
|
|
|
custom_value = subpart.custom_string_field || subpart.custom_array_field rescue nil
|
|
|
|
if !custom_value.nil?
|
|
|
|
OrbitHelper.set_widget_custom_value custom_value
|
2014-07-24 06:00:43 +00:00
|
|
|
end
|
|
|
|
if @editmode
|
2014-11-03 12:00:59 +00:00
|
|
|
partials << "<div class='editmode-ps' title='#{subpart.module}'> " + render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type,subpart.id.to_s) + "<a href='/page_parts/edit_sub_part?page_id=#{page.id.to_s}&part_id=#{part.id.to_s}&sub_part_id=#{subpart.id.to_s}#{(!$mobile.blank? ? '&mobile_view=1' : '')}'> </a></div>"
|
2014-07-24 06:00:43 +00:00
|
|
|
else
|
2014-11-03 12:00:59 +00:00
|
|
|
partials << render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type,subpart.id.to_s)
|
2014-07-24 06:00:43 +00:00
|
|
|
end
|
2014-05-29 10:32:27 +00:00
|
|
|
elsif subpart.kind == "text"
|
2014-07-24 06:00:43 +00:00
|
|
|
if @editmode
|
2014-07-24 06:08:20 +00:00
|
|
|
partials << "<div class='editmode-ps' title='text'> " + subpart.content + "<a href='/page_parts/edit_sub_part?page_id=#{part.page_id.to_s}&part_id=#{part.id.to_s}&sub_part_id=#{subpart.id.to_s}#{(!$mobile.blank? ? '&mobile_view=1' : '')}'> </a></div>"
|
2014-07-24 06:00:43 +00:00
|
|
|
else
|
|
|
|
partials << subpart.content
|
|
|
|
end
|
2014-05-22 11:19:25 +00:00
|
|
|
end
|
|
|
|
end
|
2014-05-29 10:32:27 +00:00
|
|
|
@part_partials["data-pp='#{part.part_id}'"] = partials
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
2014-05-28 12:05:39 +00:00
|
|
|
|
2014-05-22 11:19:25 +00:00
|
|
|
@file = nil
|
|
|
|
@layout_html = nil
|
2014-05-29 10:32:27 +00:00
|
|
|
if original_view == "home"
|
|
|
|
@file = File.join('../templates', "#{@key}", "/home/index.html.erb")
|
2014-05-22 11:19:25 +00:00
|
|
|
else
|
2014-05-29 10:32:27 +00:00
|
|
|
@file = File.join('../templates', "#{@key}", "/home/page.html.erb")
|
2014-05-22 11:19:25 +00:00
|
|
|
end
|
|
|
|
@layout_html = render_to_string(@file)
|
|
|
|
doc = Nokogiri::HTML(@layout_html, nil, "UTF-8")
|
2014-04-01 07:10:21 +00:00
|
|
|
|
2014-05-22 11:19:25 +00:00
|
|
|
@part_partials.each do |key, partial|
|
|
|
|
html_string = ""
|
|
|
|
partial.each do |p|
|
2014-11-27 10:09:18 +00:00
|
|
|
if !p.nil?
|
|
|
|
html_string = html_string + p
|
|
|
|
end
|
2014-05-22 11:19:25 +00:00
|
|
|
end
|
|
|
|
pp = doc.css("*[#{key}]")
|
2014-06-04 12:36:12 +00:00
|
|
|
if !pp.blank?
|
|
|
|
pp = pp[0]
|
|
|
|
pp.inner_html = html_string
|
|
|
|
end
|
2014-05-22 11:19:25 +00:00
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
|
2014-07-24 06:00:43 +00:00
|
|
|
if @editmode
|
|
|
|
pps = doc.css("*[data-pp]")
|
|
|
|
pps.each do |pp|
|
|
|
|
number = pp.attributes["data-pp"].value
|
2014-10-01 11:37:18 +00:00
|
|
|
if pp.inner_html.strip == ""
|
2014-07-25 12:05:06 +00:00
|
|
|
pp.inner_html = "<a href='/page_parts/new?part=#{number}&page_id=#{page.id.to_s}#{(!$mobile.blank? ? '&mobile_view=1' : '')}'> </a>"
|
2014-07-24 06:00:43 +00:00
|
|
|
else
|
|
|
|
inner_html = pp.inner_html
|
2014-07-25 12:05:06 +00:00
|
|
|
pp.inner_html = inner_html + "<a href='/page_parts/#{number}/edit?page_id=#{page.id.to_s}#{(!$mobile.blank? ? '&mobile_view=1' : '')}'> </a>"
|
2014-07-24 06:00:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-29 10:32:27 +00:00
|
|
|
if original_view != "home"
|
2014-05-22 11:19:25 +00:00
|
|
|
viewarea = doc.css("*[data-content='true']")[0]
|
2014-07-18 06:43:02 +00:00
|
|
|
viewarea.inner_html = render_to_string(original_view) rescue "<div></div>"
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
2014-05-27 10:18:23 +00:00
|
|
|
link = doc.css("link")[0]
|
|
|
|
link.attributes["href"].value = current_site.favicon.url.nil? ? "/assets/favicon.ico" : current_site.favicon.url
|
2014-07-10 07:49:29 +00:00
|
|
|
final_html_for_render = doc.to_html
|
2014-04-01 07:10:21 +00:00
|
|
|
|
2014-05-22 11:19:25 +00:00
|
|
|
else
|
2014-07-18 06:43:02 +00:00
|
|
|
final_html_for_render = render_to_string(original_view) rescue "<div></div>"
|
2014-04-07 07:57:06 +00:00
|
|
|
end
|
2014-07-10 07:49:29 +00:00
|
|
|
final_html_for_render = change_to_language(final_html_for_render)
|
2014-07-25 12:05:06 +00:00
|
|
|
if @editmode
|
|
|
|
session[:mobile] = $temp_mobile
|
|
|
|
end
|
2014-11-05 09:25:28 +00:00
|
|
|
format_date(final_html_for_render,(original_view == "home" ? "home" : page.module)) rescue final_html_for_render
|
2014-10-01 08:12:38 +00:00
|
|
|
end
|
|
|
|
|
2014-11-05 09:25:28 +00:00
|
|
|
def format_date(html,module_key)
|
2014-10-01 08:12:38 +00:00
|
|
|
doc = Nokogiri::HTML(html, nil, "UTF-8")
|
2014-11-05 09:25:28 +00:00
|
|
|
doc.css("body").first.set_attribute("data-module",module_key) rescue nil
|
2014-10-01 08:12:38 +00:00
|
|
|
dates = doc.css("*[date-format]")
|
|
|
|
if dates.blank?
|
2014-11-05 09:25:28 +00:00
|
|
|
return doc.to_html
|
2014-10-01 08:12:38 +00:00
|
|
|
else
|
|
|
|
dates.each do |d|
|
|
|
|
format = d.attributes["date-format"].value
|
|
|
|
date = DateTime.parse(d.inner_text)
|
2014-10-01 11:37:18 +00:00
|
|
|
d.inner_html = d.inner_html.gsub(d.inner_text.strip, " " + date.strftime(format))
|
2014-10-01 08:12:38 +00:00
|
|
|
end
|
|
|
|
return doc.to_html
|
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_widget_path(widget)
|
|
|
|
file = File.join('../templates', "#{@key}", "modules/#{widget}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_view
|
2014-05-05 06:04:50 +00:00
|
|
|
page = Page.find(params[:id]) rescue Page.root
|
|
|
|
if page == Page.root
|
2014-05-29 10:32:27 +00:00
|
|
|
@view = File.join(Rails.root, 'app', 'templates', "#{@key}", "home/index.html.erb")
|
2014-04-01 07:10:21 +00:00
|
|
|
else
|
2014-04-15 04:49:38 +00:00
|
|
|
module_name = page.module.downcase.singularize
|
2014-05-29 10:32:27 +00:00
|
|
|
@view = File.join(Rails.root, 'app', 'templates', "#{@key}", "modules/#{module_name}/index.html.erb")
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_params
|
2014-05-02 10:19:57 +00:00
|
|
|
page = Page.find(params[:page][:parent_page])
|
|
|
|
page.url = page.url == "/" ? "" : page.url
|
|
|
|
@url = page.url + "/#{params[:page][:page_id]}"
|
2014-11-21 09:25:02 +00:00
|
|
|
valid_locales = current_site.valid_locales rescue []
|
|
|
|
p = params.require(:page).permit(:number, :page_type, :page_id, :module, :layout, :parent_page, :data_count, :enabled_for_mobile, :member_sort_position, enabled_for_sitemap: [], enabled_for: [], menu_enabled_for: [], categories: [], tags: [], role_status: [], name_translations: valid_locales ,external_url_translations: valid_locales)
|
2014-04-01 07:10:21 +00:00
|
|
|
p["url"] = @url
|
2014-07-16 10:48:23 +00:00
|
|
|
if p["external_url_translations"]
|
2014-11-20 09:06:15 +00:00
|
|
|
current_site.in_use_locales.each do |loc|
|
|
|
|
p["external_url_translations"][loc.to_s] = p["external_url_translations"][loc.to_s].sub("http://" + request.host_with_port,"") if p["external_url_translations"][loc.to_s].present?
|
|
|
|
end
|
2014-07-16 10:48:23 +00:00
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
p
|
|
|
|
end
|
|
|
|
|
2014-04-21 07:19:29 +00:00
|
|
|
def page_update_params
|
2014-11-21 09:25:02 +00:00
|
|
|
valid_locales = current_site.valid_locales rescue []
|
|
|
|
p = params.require(:page).permit(:number, :page_type, :page_id, :module, :layout, :parent_page, :data_count, :enabled_for_mobile, :member_sort_position, enabled_for_sitemap: [], enabled_for: [],menu_enabled_for: [], categories: [], tags: [], role_status: [], name_translations: valid_locales, external_url_translations: valid_locales)
|
2014-07-23 16:04:10 +00:00
|
|
|
p["role_status"] = p["role_status"] || []
|
|
|
|
p["categories"] = p["categories"] || []
|
2014-12-26 02:26:40 +00:00
|
|
|
p["tags"] = p["tags"] || []
|
2014-04-21 07:19:29 +00:00
|
|
|
p["enabled_for"] = p["enabled_for"] || []
|
|
|
|
p["menu_enabled_for"] = p["menu_enabled_for"] || []
|
2014-09-26 09:10:17 +00:00
|
|
|
p["enabled_for_sitemap"] = p["enabled_for_sitemap"] || []
|
2014-07-11 13:06:23 +00:00
|
|
|
p["enabled_for_mobile"] = p["enabled_for_mobile"] || 0
|
2014-07-16 10:48:23 +00:00
|
|
|
if p["external_url_translations"]
|
2014-11-20 09:06:15 +00:00
|
|
|
current_site.in_use_locales.each do |loc|
|
|
|
|
p["external_url_translations"][loc.to_s] = p["external_url_translations"][loc.to_s].sub("http://" + request.host_with_port,"") if p["external_url_translations"][loc.to_s].present?
|
|
|
|
end
|
2014-07-16 10:48:23 +00:00
|
|
|
end
|
2014-04-21 07:19:29 +00:00
|
|
|
p
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:10:21 +00:00
|
|
|
def get_layout
|
|
|
|
if request[:action] == "edit_view"
|
|
|
|
page = Page.find(params[:id])
|
2014-04-21 08:30:27 +00:00
|
|
|
if page.page_id == "" || page.page_id == nil
|
2014-04-01 07:10:21 +00:00
|
|
|
false
|
|
|
|
else
|
2014-05-29 10:32:27 +00:00
|
|
|
File.join("../../templates", "#{@key}", "/home/page.html.erb")
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
# elsif request[:action] == "show" || request[:action] == "moduleShow"
|
|
|
|
# File.join("../../templates", "themes", "#{@key}", '/home/page.html.erb')
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2014-05-05 06:04:50 +00:00
|
|
|
def to_bool(str)
|
|
|
|
return true if str == "true"
|
|
|
|
return false if str == "false"
|
|
|
|
end
|
2014-05-20 02:31:44 +00:00
|
|
|
|
|
|
|
def check_frontend_open
|
|
|
|
if !current_site.frontend_open && current_user.blank?
|
|
|
|
redirect_to '/admin/dashboards'
|
|
|
|
end
|
|
|
|
end
|
2014-05-28 12:05:39 +00:00
|
|
|
|
2014-05-29 04:08:56 +00:00
|
|
|
def check_authorization
|
|
|
|
if current_user.blank? or !current_user.is_admin?
|
|
|
|
redirect_to '/admin/dashboards'
|
|
|
|
end
|
|
|
|
end
|
2014-07-24 06:00:43 +00:00
|
|
|
|
|
|
|
def set_edit_mode
|
2014-11-13 08:29:38 +00:00
|
|
|
@dataApi = "frontend"
|
2014-07-25 12:05:06 +00:00
|
|
|
@editmode = false
|
2014-07-24 06:00:43 +00:00
|
|
|
if !current_user.nil? and current_user.is_admin?
|
|
|
|
if params[:editmode] == "on"
|
|
|
|
@editmode = true
|
|
|
|
@dataApi = "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-11 13:06:23 +00:00
|
|
|
|
2014-07-10 07:49:29 +00:00
|
|
|
def change_to_language(final_html)
|
|
|
|
if session[:zh_cn]
|
|
|
|
final_html = ZhConv.convert("zh-cn", final_html)
|
|
|
|
final_html.gsub!('/zh_tw/','/zh_cn/')
|
2014-07-19 19:05:30 +00:00
|
|
|
final_html.sub!('<a href="'+request.path+'">繁体中文</a>','<a href="'+(request.path.sub('/zh_cn/','/zh_tw/'))+'">繁体中文</a>')
|
2014-07-10 07:49:29 +00:00
|
|
|
end
|
|
|
|
final_html
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|