2020-02-03 13:14:03 +00:00
|
|
|
class OlympiamanagementsController < ApplicationController
|
2020-02-01 16:37:59 +00:00
|
|
|
include ActionView::Context #vary important (only add this can access @@session from view)
|
|
|
|
before_action :set_sign_up_setting
|
2020-02-03 13:14:03 +00:00
|
|
|
prepend_view_path "app/templates" #for_render_pages
|
|
|
|
layout :get_layout #for_render_pages
|
|
|
|
before_action :check_login, except: :login
|
2020-02-01 16:37:59 +00:00
|
|
|
#include "#{Rails.root}/app/helpers/application_helper.rb"
|
2020-02-03 13:14:03 +00:00
|
|
|
def check_login
|
|
|
|
begin
|
|
|
|
@@error
|
|
|
|
rescue
|
|
|
|
@@error = nil
|
|
|
|
end
|
|
|
|
if request.session[:olympia_login_id].to_s.blank?
|
|
|
|
render_contents_in_index_page(render_to_string(:formats=> [:html] ,:partial=>'login',:locals=>{:@error=>@@error})) and return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def login
|
|
|
|
@@error = nil
|
|
|
|
if !params[:login_id].to_s.blank?
|
|
|
|
if OlympiaSchoolDataFields.where(:account_number=>params[:login_id]).length == 0
|
|
|
|
@@error = "no_account"
|
|
|
|
else
|
|
|
|
if OlympiaSchoolDataFields.where(:account_number=>params[:login_id]).first.password != params[:login_pw]
|
|
|
|
@@error = "password_error"
|
|
|
|
else
|
|
|
|
session[:olympia_login_id] = params[:login_id]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if params[:PreviousPage].to_s.blank?
|
|
|
|
redirect_to :back
|
|
|
|
else
|
|
|
|
redirect_to params[:PreviousPage].to_s
|
|
|
|
end
|
|
|
|
end
|
2020-01-31 13:46:35 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "olympiamanagement"
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
def set_sign_up_setting
|
2020-02-03 13:14:03 +00:00
|
|
|
@key = Site.first.template rescue "" #for_render_pages
|
2020-02-01 16:37:59 +00:00
|
|
|
@sign_up_setting = SignUpSetting.last
|
|
|
|
data_arr = [{:url=>'/olympiamanagements/school_connection_data',:name=>t('olympiamanagement.school_connection_data')},
|
|
|
|
{:url=>'/olympiamanagements/add_sign_up_student_data',:name=>t('olympiamanagement.add_sign_up_student_data')},
|
|
|
|
{:url=>'/olympiamanagements/sign_up_student_data_list',:name=>t('olympiamanagement.sign_up_student_data_list')},
|
|
|
|
{:url=>'/olympiamanagements/edit_password',:name=>t('olympiamanagement.edit_password')},
|
|
|
|
{:url=>'/olympiamanagements/print_registration_form',:name=>t('olympiamanagement.print_registration_form')},
|
|
|
|
{:url=>'/olympiamanagements/logout',:name=>t('olympiamanagement.logout')}]
|
|
|
|
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
|
|
|
|
end
|
2020-01-22 14:03:38 +00:00
|
|
|
def index
|
2020-01-31 13:46:35 +00:00
|
|
|
uid = OrbitHelper.params[:uid] rescue ""
|
|
|
|
tags = OrbitHelper.widget_tags
|
|
|
|
categories = OrbitHelper.widget_categories || []
|
2020-02-02 11:25:42 +00:00
|
|
|
set_sign_up_setting
|
|
|
|
@time_arr = ["year","month","day","o_clock","minute"]
|
|
|
|
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
|
|
|
|
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
|
|
|
|
time_now_str = Time.now.strftime("%Y %m %d %H %M")
|
|
|
|
@instructions_name = {}
|
|
|
|
Site.first.in_use_locales.each do |locale|
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
@instructions_name[locale.to_s] = I18n.t('olympiamanagement.registration_instructions')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
|
|
|
|
@instructions_pages = Page.where(:parent_page_id=>@page.id).select{|page| page.name_translations==@instructions_name}
|
2020-01-31 14:56:46 +00:00
|
|
|
case OrbitHelper.params[:layout_type]
|
|
|
|
when "olympia_managements_instructions_index"
|
2020-02-02 11:25:42 +00:00
|
|
|
if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
|
|
|
|
@olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s
|
|
|
|
@sign_up_setting.attributes.to_h.each do |key,value|
|
|
|
|
@olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s)
|
|
|
|
end
|
|
|
|
if !OrbitHelper.current_user.nil?
|
|
|
|
@edit_link = '/admin/olympiamanagements/sign_up_setting#registration_instructions'
|
|
|
|
@edit_text = (I18n.locale.to_s == "zh_tw") ? "編輯" : "Edit"
|
|
|
|
if !OrbitHelper.current_user.nil?
|
|
|
|
@olympiamanagement_instruction += '<p class="admin-edit text-right"><a class="btn btn-primary" href="'+@edit_link+'" title="'+@edit_text+'"><i class="icon-edit"></i> '+@edit_text+'</a></p>'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}}
|
|
|
|
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
|
|
|
|
@olympiamanagement_instruction = @breadcumb + @olympiamanagement_instruction.html_safe
|
|
|
|
else
|
|
|
|
if !@instructions_pages.empty?
|
|
|
|
@instructions_pages.each{|page| page.destroy}
|
|
|
|
end
|
|
|
|
@olympiamanagement_instruction = '<h3 style="margin: 20px 0px 10px; padding: 0px; color: rgb(0, 153, 153); font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; font-size: 0.9375em; line-height: 20px; font-family: 微軟正黑體, sans-serif;">'+t('olympiamanagement.sign_up_hint')+'</h3>'
|
2020-01-31 14:56:46 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"olympiamanagement" => [],
|
|
|
|
"extras"=>{"instructions"=> @olympiamanagement_instruction}
|
|
|
|
}
|
|
|
|
when "olympia_managements_index"
|
2020-02-02 11:25:42 +00:00
|
|
|
if Page.where(:parent_page_id=>@page.id,:name=>@page.name).length == 0
|
|
|
|
@newpage = Page.create(:layout=> @page.layout,:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>@page.url,
|
|
|
|
:menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>@page.page_id)
|
|
|
|
@newpage.name_translations = @page.name_translations
|
|
|
|
@newpage.save
|
|
|
|
@newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions",
|
|
|
|
:menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions')
|
|
|
|
@newpage.name_translations = @instructions_name
|
|
|
|
@newpage.save
|
|
|
|
end
|
2020-02-03 13:14:03 +00:00
|
|
|
@error = @@error rescue nil
|
2020-02-02 11:25:42 +00:00
|
|
|
@page_content
|
|
|
|
if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
|
|
|
|
if @instructions_pages.empty?
|
|
|
|
@newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions",
|
|
|
|
:menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions')
|
|
|
|
@newpage.name_translations = @instructions_name
|
|
|
|
@newpage.save
|
|
|
|
elsif @instructions_pages.length != 1
|
|
|
|
@instructions_pages.slice(1,@instructions_pages.length).each{|page| page.destroy}
|
|
|
|
end
|
2020-02-03 13:14:03 +00:00
|
|
|
if !(OrbitHelper.params || params)[:login_id].to_s.blank? && @@session[:olympia_login_id].to_s.blank?
|
|
|
|
if OlympiaSchoolDataFields.where(:account_number=>(OrbitHelper.params || params)[:login_id]).length == 0
|
2020-02-01 16:37:59 +00:00
|
|
|
@error = "no_account"
|
|
|
|
else
|
2020-02-03 13:14:03 +00:00
|
|
|
if OlympiaSchoolDataFields.where(:account_number=>(OrbitHelper.params || params)[:login_id]).first.password != (OrbitHelper.params || params)[:login_pw]
|
2020-02-01 16:37:59 +00:00
|
|
|
@error = "password_error"
|
|
|
|
else
|
2020-02-03 13:14:03 +00:00
|
|
|
@@session[:olympia_login_id] = (OrbitHelper.params || params)[:login_id]
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if @@session[:olympia_login_id].to_s.blank?
|
2020-02-03 13:14:03 +00:00
|
|
|
@page_content = render_to_string(:formats=> [:html] ,:partial=>'login',:locals=>{:@error=>@error})
|
2020-02-01 16:37:59 +00:00
|
|
|
else
|
2020-02-03 13:14:03 +00:00
|
|
|
@@error = nil
|
2020-02-01 16:37:59 +00:00
|
|
|
@page_content = @breadcumb
|
|
|
|
end
|
|
|
|
else
|
2020-02-02 11:25:42 +00:00
|
|
|
if !@instructions_pages.empty?
|
|
|
|
@instructions_pages.each{|page| page.destroy}
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}}
|
|
|
|
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
|
|
|
|
@page_content = @breadcumb+'<h3 style="margin: 20px 0px 10px; padding: 0px; color: rgb(0, 153, 153); font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; font-size: 0.9375em; line-height: 20px; font-family: 微軟正黑體, sans-serif;">'+t('olympiamanagement.sign_up_hint')+'</h3>'
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
{
|
|
|
|
"olympiamanagement" => [],
|
|
|
|
"extras"=>{"page_content"=> @page_content}
|
|
|
|
}
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def school_connection_data
|
|
|
|
@time_arr = ["year","month","day","o_clock","minute"]
|
|
|
|
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
|
|
|
|
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
|
|
|
|
time_now_str = Time.now.strftime("%Y %m %d %H %M")
|
|
|
|
if !(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?
|
2020-02-02 11:25:42 +00:00
|
|
|
@school_data_fields = [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_code'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_address'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'class_number'=>{'type'=>'String','size'=>'5','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'enrollment_limited'=>{'type'=>'Fixnum','size'=>'5','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
|
|
|
|
{'school_contact_person_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'department_job_title'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'office_tel_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'fax'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'mobile_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
|
|
|
|
{'email'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}]
|
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
|
|
|
|
@page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_school_data.html',:locals=>{:@school_data_fields=>@school_data_fields,:@olympia_school_data_field=>@olympia_school_data_field})
|
|
|
|
render_contents_in_index_page(@breadcumb+@page_content)#redirect_to :back
|
2020-02-01 16:37:59 +00:00
|
|
|
else
|
2020-02-02 11:25:42 +00:00
|
|
|
redirect_to :back
|
2020-01-31 13:46:35 +00:00
|
|
|
end
|
2020-01-22 14:03:38 +00:00
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
def add_sign_up_student_data
|
|
|
|
@time_arr = ["year","month","day","o_clock","minute"]
|
|
|
|
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
|
|
|
|
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
|
|
|
|
time_now_str = Time.now.strftime("%Y %m %d %H %M")
|
2020-02-03 13:14:03 +00:00
|
|
|
#@request = Rack::Request.new((OrbitHelper.request.env rescue nil) || (request.env rescue env))
|
|
|
|
#@session = @request.session
|
|
|
|
#render :html => session.to_hash and return
|
2020-02-02 11:25:42 +00:00
|
|
|
if !(!(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?)
|
2020-02-01 16:37:59 +00:00
|
|
|
redirect_to :back
|
|
|
|
else
|
2020-02-02 11:25:42 +00:00
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
|
2020-02-01 16:37:59 +00:00
|
|
|
redirect_to :back if @olympia_school_data_field.nil?
|
|
|
|
@required_fields = [:school_contact_person_name,:department_job_title,:office_tel_number,:fax,:mobile_number,:email]
|
|
|
|
@flag = true
|
|
|
|
@required_fields.each do |field|
|
|
|
|
if @olympia_school_data_field[field].to_s.blank?
|
|
|
|
@flag = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2020-02-02 11:25:42 +00:00
|
|
|
if !@flag
|
|
|
|
I18n.t('olympiamanagement.please_set_school_connect_data')
|
|
|
|
render_contents_in_index_page(@breadcumb+"<p><a href=#{school_connection_data_olympiamanagements_path}>#{I18n.t('olympiamanagement.please_set_school_connect_data')}</a></p>".html_safe)
|
|
|
|
else
|
|
|
|
render_contents_in_index_page(@breadcumb)
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
#if @flag = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def sign_up_student_data_list
|
|
|
|
end
|
|
|
|
def edit_password
|
2020-02-02 11:25:42 +00:00
|
|
|
if !session[:olympia_login_id].to_s.blank?
|
|
|
|
if params[:confirm_password].nil? && params[:new_password].nil?
|
|
|
|
@page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_password.html',:locals=>{:@error=>(@@error rescue nil)})
|
|
|
|
render_contents_in_index_page(@breadcumb+@page_content)
|
|
|
|
else
|
|
|
|
@@error = nil
|
|
|
|
if params[:confirm_password].to_s != params[:new_password].to_s
|
|
|
|
@@error = "confirm_password_error"
|
|
|
|
elsif params[:confirm_password].to_s.blank? && params[:new_password].to_s.blank?
|
|
|
|
@@error = "password_all_empty"
|
|
|
|
elsif params[:confirm_password].to_s.blank?
|
|
|
|
@@error = "confirm_password_empty"
|
|
|
|
elsif params[:new_password].to_s.blank?
|
|
|
|
@@error = "new_password_empty"
|
|
|
|
else
|
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
|
|
|
|
@olympia_school_data_field.password = params[:new_password]
|
|
|
|
@olympia_school_data_field.save
|
|
|
|
end
|
|
|
|
redirect_to edit_password_olympiamanagements_path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
|
|
|
|
redirect_to "/#{I18n.locale}#{@page.url}"
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
|
|
|
def print_registration_form
|
|
|
|
end
|
|
|
|
def logout
|
|
|
|
session[:olympia_login_id] = ""
|
2020-02-02 11:25:42 +00:00
|
|
|
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
|
|
|
|
redirect_to "/#{I18n.locale}#{@page.url}"#render :html => session.to_hash
|
2020-02-01 16:37:59 +00:00
|
|
|
end
|
2020-01-22 14:03:38 +00:00
|
|
|
def widget
|
2020-01-31 13:46:35 +00:00
|
|
|
uid = OrbitHelper.params[:uid] rescue ""
|
|
|
|
tags = OrbitHelper.widget_tags
|
|
|
|
categories = OrbitHelper.widget_categories || []
|
|
|
|
@sign_up_setting = SignUpSetting.last
|
|
|
|
@olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s
|
|
|
|
@sign_up_setting.attributes.to_h.each do |key,value|
|
|
|
|
@olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s)
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"olympiamanagement" => [],
|
|
|
|
"extras"=>{"instructions"=> @olympiamanagement_instruction}
|
|
|
|
}
|
|
|
|
end
|
2020-01-31 14:56:46 +00:00
|
|
|
def download_school_code
|
2020-02-02 11:25:42 +00:00
|
|
|
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
|
2020-01-31 14:56:46 +00:00
|
|
|
dir_path = 'tmp/olypiamanagement/'
|
|
|
|
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
|
|
|
|
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
|
|
|
|
@filename = 'download_school_code.xlsx'
|
|
|
|
Dir.chdir(dir_path) do
|
|
|
|
File.open(@filename, 'w') do |f|
|
|
|
|
f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'school_code.xlsx',:locals=> {:@OlympiaSchoolDataFields=>@OlympiaSchoolDataFields} )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tmp_filename_data = File.read(dir_path +@filename)
|
|
|
|
send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: "#{Time.now.year}#{Time.now.month}#{Time.now.day}_download_school_code.xlsx")
|
|
|
|
end
|
2020-02-01 16:37:59 +00:00
|
|
|
def render_contents_in_index_page(contents=@breadcumb)
|
|
|
|
doc = Nokogiri::HTML(render_final_page("page",Page.where(:layout=>"olympia_managements_index").first,true), nil, "UTF-8")
|
|
|
|
viewarea = doc.css("*[data-content='true']")[0]
|
2020-02-02 11:25:42 +00:00
|
|
|
viewarea.inner_html = contents
|
2020-02-01 16:37:59 +00:00
|
|
|
render :html => doc.to_html.html_safe
|
|
|
|
end
|
2020-02-03 13:14:03 +00:00
|
|
|
def change_to_language(final_html) #for_render_pages
|
|
|
|
if session[:zh_cn]
|
|
|
|
final_html = ZhConv.convert("zh-cn", final_html,false)
|
|
|
|
final_html.gsub!('/zh_tw/','/zh_cn/')
|
|
|
|
final_html.sub!('<a accesskey="t" href="'+request.path+'">繁体中文</a>','<a accesskey="t" href="'+(request.path.sub('/zh_cn/','/zh_tw/'))+'">繁体中文</a>')
|
|
|
|
end
|
|
|
|
final_html
|
|
|
|
end
|
|
|
|
def get_layout #for_render_pages
|
|
|
|
if request[:action] == "edit_view"
|
|
|
|
page = Page.find(params[:id])
|
|
|
|
if page.page_id == "" || page.page_id == nil
|
|
|
|
false
|
|
|
|
else
|
|
|
|
File.join("../../templates", "#{@key}", "/home/page.html.erb")
|
|
|
|
end
|
|
|
|
# elsif request[:action] == "show" || request[:action] == "moduleShow"
|
|
|
|
# File.join("../../templates", "themes", "#{@key}", '/home/page.html.erb')
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def render_final_page(original_view=get_view,page,layout) #for_render_pages
|
|
|
|
final_html_for_render = ""
|
|
|
|
OrbitHelper.set_css_to_render_to_empty
|
|
|
|
if layout
|
|
|
|
parts = $mobile.blank? ? (page.page_parts rescue []) : (page.mobile_page_parts rescue [])
|
|
|
|
@part_partials = {}
|
|
|
|
parts.each do |part|
|
|
|
|
subparts = part.sub_parts.asc(:created_at)
|
|
|
|
partials = []
|
|
|
|
subparts.each do |subpart|
|
|
|
|
if subpart.kind == "module_widget"
|
|
|
|
OrbitHelper.set_current_widget subpart
|
|
|
|
OrbitHelper.set_widget_data_count subpart.data_count
|
|
|
|
OrbitHelper.set_widget_module_app subpart.module
|
|
|
|
OrbitHelper.set_widget_item_url subpart
|
|
|
|
OrbitHelper.render_meta_tags []
|
|
|
|
OrbitHelper.set_widget_title subpart.title
|
|
|
|
OrbitHelper.set_widget_categories subpart.categories || ["all"]
|
|
|
|
OrbitHelper.set_widget_tags subpart.tags || ["all"]
|
|
|
|
custom_value = subpart.custom_string_field || subpart.custom_array_field rescue nil
|
|
|
|
if !custom_value.nil?
|
|
|
|
OrbitHelper.set_widget_custom_value custom_value
|
|
|
|
end
|
|
|
|
if @editmode
|
|
|
|
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>"
|
|
|
|
else
|
|
|
|
# widget_html = Rails.cache.fetch("subpart_#{subpart.module}_#{subpart.id.to_s}_"+I18n.locale.to_s,{ race_condition_ttl: 2, expires_in: 5.minutes}) do
|
|
|
|
# render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type,subpart.id.to_s)
|
|
|
|
# end
|
|
|
|
widget_html = render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type,subpart.id.to_s)
|
|
|
|
partials << widget_html
|
|
|
|
end
|
|
|
|
elsif subpart.kind == "text"
|
|
|
|
if @editmode
|
|
|
|
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>"
|
|
|
|
else
|
|
|
|
# change from px and pt and cm to em #start
|
|
|
|
have_change = false
|
|
|
|
if Site.all.first.page_sets.last.auto_convert_flag
|
|
|
|
if subpart.content.include? 'px'
|
|
|
|
have_change = true
|
|
|
|
inner_text = subpart.content
|
|
|
|
get_px = inner_text.enum_for(:scan,/:.*[+-]?(\d*[.])?\d+px[;\" ]/).map{Regexp.last_match.to_s}
|
|
|
|
get_px = get_px.uniq.sort_by(&:length).reverse!
|
|
|
|
get_px.each do |child_px|
|
|
|
|
convert_em = child_px.enum_for(:scan,/[+-]?(\d*[.])?\d+px/).map{Regexp.last_match.to_s}.sort_by(&:length).reverse!
|
|
|
|
calc_em = convert_em.collect{|v| "#{Float(v[0...v.length-2])/16}em"}
|
|
|
|
cp_child = child_px
|
|
|
|
(0...convert_em.length).each do |i|
|
|
|
|
cp_child = cp_child.gsub(convert_em[i],calc_em[i])
|
|
|
|
end
|
|
|
|
inner_text = inner_text.gsub(child_px,cp_child)
|
|
|
|
end
|
|
|
|
subpart.content = inner_text
|
|
|
|
end
|
|
|
|
if subpart.content.include? 'pt'
|
|
|
|
have_change = true
|
|
|
|
inner_text = subpart.content
|
|
|
|
get_pt = inner_text.enum_for(:scan,/:.*[+-]?(\d*[.])?\d+pt[;\" ]/).map{Regexp.last_match.to_s}
|
|
|
|
get_pt = get_pt.uniq.sort_by(&:length).reverse!
|
|
|
|
get_pt.each do |child_pt|
|
|
|
|
convert_em = child_pt.enum_for(:scan,/[+-]?(\d*[.])?\d+pt/).map{Regexp.last_match.to_s}.sort_by(&:length).reverse!
|
|
|
|
calc_em = convert_em.collect{|v| "#{Float(v[0...v.length-2])/12}em"}
|
|
|
|
cp_child = child_pt
|
|
|
|
(0...convert_em.length).each do |i|
|
|
|
|
cp_child = cp_child.gsub(convert_em[i],calc_em[i])
|
|
|
|
end
|
|
|
|
inner_text = inner_text.gsub(child_pt,cp_child)
|
|
|
|
end
|
|
|
|
subpart.content = inner_text
|
|
|
|
end
|
|
|
|
if subpart.content.include? 'cm'
|
|
|
|
have_change = true
|
|
|
|
inner_text = subpart.content
|
|
|
|
get_cm = inner_text.enum_for(:scan,/:.*[+-]?(\d*[.])?\d+cm[;\" ]/).map{Regexp.last_match.to_s}
|
|
|
|
get_cm = get_cm.uniq.sort_by(&:length).reverse!
|
|
|
|
get_cm.each do |child_cm|
|
|
|
|
convert_em = child_cm.enum_for(:scan,/[+-]?(\d*[.])?\d+cm/).map{Regexp.last_match.to_s}.sort_by(&:length).reverse!
|
|
|
|
calc_em = convert_em.collect{|v| "#{Float(v[0...v.length-2])*6/2.54}em"}
|
|
|
|
cp_child = child_cm
|
|
|
|
(0...convert_em.length).each do |i|
|
|
|
|
cp_child = cp_child.gsub(convert_em[i],calc_em[i])
|
|
|
|
end
|
|
|
|
inner_text = inner_text.gsub(child_cm,cp_child)
|
|
|
|
end
|
|
|
|
subpart.content = inner_text
|
|
|
|
end
|
|
|
|
# change from px and pt and cm to em #end
|
|
|
|
if have_change
|
|
|
|
subpart.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
partials << subpart.content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@part_partials["data-pp='#{part.part_id}'"] = partials
|
|
|
|
end
|
|
|
|
@file = nil
|
|
|
|
@layout_html = nil
|
|
|
|
if original_view == "home"
|
|
|
|
@file = File.join("#{@key}", "/home/index.html.erb")
|
|
|
|
else
|
|
|
|
@file = File.join("#{@key}", "/home/page.html.erb")
|
|
|
|
end
|
|
|
|
@layout_html = render_to_string(@file , :formats => :html)
|
|
|
|
doc = Nokogiri::HTML(@layout_html, nil, "UTF-8")
|
|
|
|
head = doc.css("head")
|
|
|
|
@part_partials.each do |key, partial|
|
|
|
|
html_string = ""
|
|
|
|
partial.each do |p|
|
|
|
|
if !p.nil?
|
|
|
|
html_string = html_string + p
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pp = doc.css("*[#{key}]")
|
|
|
|
if !pp.blank?
|
|
|
|
pp = pp[0]
|
|
|
|
pp.inner_html = html_string
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if @editmode
|
|
|
|
pps = doc.css("*[data-pp]")
|
|
|
|
pps.each do |pp|
|
|
|
|
number = pp.attributes["data-pp"].value
|
|
|
|
if pp.inner_html.strip == ""
|
|
|
|
pp.inner_html = "<a href='/page_parts/new?part=#{number}&page_id=#{page.id.to_s}#{(!$mobile.blank? ? '&mobile_view=1' : '')}'> </a>"
|
|
|
|
else
|
|
|
|
inner_html = pp.inner_html
|
|
|
|
pp.inner_html = inner_html + "<a href='/page_parts/#{number}/edit?page_id=#{page.id.to_s}#{(!$mobile.blank? ? '&mobile_view=1' : '')}'> </a>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if original_view != "home"
|
|
|
|
viewarea = doc.css("*[data-content='true']")[0]
|
|
|
|
if params["target_controller"].to_s == "page_contents"
|
|
|
|
viewarea_id = Page.where("page_id"=>params["page_id"].to_s).first.id.to_s
|
|
|
|
@page_contents = PageContext.where("page_id" => viewarea_id).last
|
|
|
|
viewarea.inner_html = @page_contents.content.to_s rescue ""
|
|
|
|
# change from px and pt and cm to em #start
|
|
|
|
have_change = false
|
|
|
|
if Site.all.first.page_sets.last.auto_convert_flag
|
|
|
|
if viewarea.inner_html.include? 'px'
|
|
|
|
have_change = true
|
|
|
|
inner_text = viewarea.inner_html
|
|
|
|
get_px = inner_text.enum_for(:scan,/:.*[+-]?(\d*[.])?\d+px[;\" ]/).map{Regexp.last_match.to_s}
|
|
|
|
get_px = get_px.uniq.sort_by(&:length).reverse!
|
|
|
|
get_px.each do |child_px|
|
|
|
|
convert_em = child_px.enum_for(:scan,/[+-]?(\d*[.])?\d+px/).map{Regexp.last_match.to_s}.sort_by(&:length).reverse!
|
|
|
|
calc_em = convert_em.collect{|v| "#{Float(v[0...v.length-2])/16}em"}
|
|
|
|
cp_child = child_px
|
|
|
|
(0...convert_em.length).each do |i|
|
|
|
|
cp_child = cp_child.gsub(convert_em[i],calc_em[i])
|
|
|
|
end
|
|
|
|
inner_text = inner_text.gsub(child_px,cp_child)
|
|
|
|
end
|
|
|
|
viewarea.inner_html = inner_text
|
|
|
|
end
|
|
|
|
if viewarea.inner_html.include? 'pt'
|
|
|
|
have_change = true
|
|
|
|
inner_text = viewarea.inner_html
|
|
|
|
get_pt = inner_text.enum_for(:scan,/:.*[+-]?(\d*[.])?\d+pt[;\" ]/).map{Regexp.last_match.to_s}
|
|
|
|
get_pt = get_pt.uniq.sort_by(&:length).reverse!
|
|
|
|
get_pt.each do |child_pt|
|
|
|
|
convert_em = child_pt.enum_for(:scan,/[+-]?(\d*[.])?\d+pt/).map{Regexp.last_match.to_s}.sort_by(&:length).reverse!
|
|
|
|
calc_em = convert_em.collect{|v| "#{Float(v[0...v.length-2])/12}em"}
|
|
|
|
cp_child = child_pt
|
|
|
|
(0...convert_em.length).each do |i|
|
|
|
|
cp_child = cp_child.gsub(convert_em[i],calc_em[i])
|
|
|
|
end
|
|
|
|
inner_text = inner_text.gsub(child_pt,cp_child)
|
|
|
|
end
|
|
|
|
viewarea.inner_html = inner_text
|
|
|
|
end
|
|
|
|
if viewarea.inner_html.include? 'cm'
|
|
|
|
have_change = true
|
|
|
|
inner_text = viewarea.inner_html
|
|
|
|
get_cm = inner_text.enum_for(:scan,/:.*[+-]?(\d*[.])?\d+cm[;\" ]/).map{Regexp.last_match.to_s}
|
|
|
|
get_cm = get_cm.uniq.sort_by(&:length).reverse!
|
|
|
|
get_cm.each do |child_cm|
|
|
|
|
convert_em = child_cm.enum_for(:scan,/[+-]?(\d*[.])?\d+cm/).map{Regexp.last_match.to_s}.sort_by(&:length).reverse!
|
|
|
|
calc_em = convert_em.collect{|v| "#{Float(v[0...v.length-2])*6/2.54}em"}
|
|
|
|
cp_child = child_cm
|
|
|
|
(0...convert_em.length).each do |i|
|
|
|
|
cp_child = cp_child.gsub(convert_em[i],calc_em[i])
|
|
|
|
end
|
|
|
|
inner_text = inner_text.gsub(child_cm,cp_child)
|
|
|
|
end
|
|
|
|
viewarea.inner_html = inner_text
|
|
|
|
end
|
|
|
|
# change from px and pt and cm to em #end
|
|
|
|
if have_change && (viewarea.inner_html != "")
|
|
|
|
@page_contents.content = viewarea.inner_html
|
|
|
|
@page_contents.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
viewarea.inner_html = render_to_string(original_view) rescue "<div></div>"
|
|
|
|
else
|
|
|
|
viewarea.inner_html = render_to_string(original_view) rescue "<div></div>"
|
|
|
|
end
|
|
|
|
head[0].inner_html = OrbitHelper.meta_tags_html + head.inner_html
|
|
|
|
end
|
|
|
|
head[0].inner_html = head.inner_html + OrbitHelper.get_css_to_render_in_head
|
|
|
|
link = doc.css("link")[0]
|
|
|
|
link.attributes["href"].value = current_site.favicon.url.nil? ? "/assets/favicon.ico" : current_site.favicon.url
|
|
|
|
final_html_for_render = doc.to_html
|
|
|
|
else
|
|
|
|
final_html_for_render = render_to_string(original_view) rescue "<div></div>"
|
|
|
|
end
|
|
|
|
final_html_for_render = change_to_language(final_html_for_render)
|
|
|
|
if @editmode
|
|
|
|
session[:mobile] = $temp_mobile
|
|
|
|
end
|
|
|
|
format_date(final_html_for_render,(original_view == "home" ? "home" : page.module)) rescue final_html_for_render
|
|
|
|
end
|
2020-01-31 13:46:35 +00:00
|
|
|
def updata_school_data
|
2020-02-02 11:25:42 +00:00
|
|
|
@readonly_fields = ['account_number','password','school_name','school_code','school_address','class_number','enrollment_limited']
|
|
|
|
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>params[:olympia_user_name]).first
|
|
|
|
redirect_to :back if @olympia_school_data_field.nil?
|
|
|
|
params['add_school_data'].keys.each do |field|
|
|
|
|
if !@readonly_fields.include?(field)
|
|
|
|
@olympia_school_data_field[field] = params['add_school_data'][field]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@olympia_school_data_field.save
|
|
|
|
redirect_to add_sign_up_student_data_olympiamanagements_path
|
|
|
|
#render_contents_in_index_page(@olympia_school_data_field.attributes.to_s)
|
2020-01-31 13:46:35 +00:00
|
|
|
end
|
|
|
|
def updata_student_data
|
|
|
|
#render :html => '123'
|
2020-01-22 14:03:38 +00:00
|
|
|
end
|
|
|
|
end
|