Remove instruction page will disapeared when the time not in the registation setting time.

This commit is contained in:
BoHung Chiu 2020-03-10 16:13:14 +08:00
parent 5b110f98bb
commit 2cad391fa7
1 changed files with 26 additions and 20 deletions

View File

@ -84,29 +84,35 @@ class OlympiamanagementsController < ApplicationController
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}
if @instructions_pages.count == 0 #auto create instruction page
@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
case OrbitHelper.params[:layout_type]
when "olympia_managements_instructions_index"
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,:@title=>I18n.t('olympiamanagement.sign_up_title')})
@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>'
#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,:@title=>I18n.t('olympiamanagement.sign_up_title')})
@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>'
#end
{
"olympiamanagement" => [],
"extras"=>{"instructions"=> @olympiamanagement_instruction}