fix
This commit is contained in:
parent
ca31360f65
commit
42150a399e
|
@ -437,7 +437,11 @@ class Admin::OlympiamanagementsController < OrbitAdminController
|
|||
@sign_up_setting = SignUpSetting.where(:active=>true).last
|
||||
else
|
||||
@sign_up_setting = SignUpSetting.find(session[:sign_up_setting_id]) rescue nil
|
||||
@sign_up_setting = SignUpSetting.where(:active=>true).last if @sign_up_setting.nil?
|
||||
end
|
||||
if SignUpSetting.where(:active=>true).last.nil?
|
||||
@sign_up_setting = SignUpSetting.last if @sign_up_setting.nil?
|
||||
@sign_up_setting.active = true
|
||||
@sign_up_setting.save
|
||||
end
|
||||
end
|
||||
def download_import_file
|
||||
|
|
|
@ -179,7 +179,12 @@ class OlympiamanagementsController < ApplicationController
|
|||
@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
|
||||
else
|
||||
begin
|
||||
redirect_to :back
|
||||
rescue
|
||||
@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
|
||||
end
|
||||
end
|
||||
def add_sign_up_student_data
|
||||
|
@ -540,6 +545,90 @@ class OlympiamanagementsController < ApplicationController
|
|||
session[:mobile] = $temp_mobile
|
||||
end
|
||||
format_date(final_html_for_render,(original_view == "home" ? "home" : page.module)) rescue final_html_for_render
|
||||
end
|
||||
def render_widget_for_frontend(controller_name, widget_method, widget_file, subpart_id=nil)
|
||||
def widget_parsing_repeats_again(elements,d,level)
|
||||
newhtml = []
|
||||
oldhtml = []
|
||||
elements.each do |el|
|
||||
html_to_render = ""
|
||||
data_name = el.attr("data-list")
|
||||
wrap_elements = el.css("*[data-list][data-level='#{level}']")
|
||||
if d["#{data_name}"]
|
||||
d["#{data_name}"].each_with_index do |item,i|
|
||||
element = el.inner_html
|
||||
if wrap_elements.count > 0
|
||||
htmls = widget_parsing_repeats_again(wrap_elements,d["#{data_name}"][i], level + 1)
|
||||
htmls[0].each_with_index do |html,i|
|
||||
element = element.gsub(html,htmls[1][i])
|
||||
end
|
||||
end
|
||||
item.each do |key,value|
|
||||
if !value.kind_of?(Array)
|
||||
value = value.nil? ? "" : value
|
||||
element = element.gsub("{{#{key}}}",value.to_s.html_safe)
|
||||
element = element.gsub("%7B%7B#{key}%7D%7D",value.to_s)
|
||||
end
|
||||
end
|
||||
html_to_render = html_to_render + element
|
||||
end
|
||||
temp = el.to_s
|
||||
oldhtml << temp
|
||||
temp = temp.gsub(el.inner_html, html_to_render)
|
||||
newhtml << temp
|
||||
end
|
||||
end
|
||||
[oldhtml,newhtml]
|
||||
end
|
||||
@key = Site.first.template if @key.nil?
|
||||
controller_name = controller_name.downcase.singularize
|
||||
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', "#{controller_name}", "_#{widget_file}.html.erb");
|
||||
if !File.exists?f
|
||||
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'widgets', "#{controller_name}", "_#{widget_file}.html.erb");
|
||||
if !File.exists?f
|
||||
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', "#{controller_name}", "_widget.html.erb");
|
||||
if File.exists?f
|
||||
f = File.join("#{@key}", 'modules', "#{controller_name}", "_widget.html.erb");
|
||||
else
|
||||
return "<div class='well'>Maybe the administrator has changed the theme, please select the widget design again from the page settings.</div>".html_safe
|
||||
end
|
||||
else
|
||||
f = File.join("#{@key}", 'widgets', "#{controller_name}", "_#{widget_file}.html.erb");
|
||||
end
|
||||
else
|
||||
f = File.join("#{@key}", 'modules', "#{controller_name}", "_#{widget_file}.html.erb");
|
||||
end
|
||||
s = render_to_string(f)
|
||||
doc = Nokogiri::HTML(s, nil, "UTF-8")
|
||||
if !subpart_id.nil?
|
||||
doc.css("body").children.first.set_attribute("data-subpart-id", subpart_id) rescue nil
|
||||
end
|
||||
wrap_elements = doc.css("*[data-repeat]")
|
||||
controller = "#{controller_name.capitalize.pluralize}_controller".classify.constantize.new
|
||||
OrbitHelper.set_current_widget_module controller_name
|
||||
begin
|
||||
data = controller.send("#{widget_method}") #rescue nil
|
||||
rescue Exception => e
|
||||
write_widget_debug_file(e,controller_name,widget_method,subpart_id) if Site::DEBUG
|
||||
end
|
||||
if !data.nil?
|
||||
wrap_elements = doc.css("*[data-list][data-level='0']")
|
||||
htmls = widget_parsing_repeats_again(wrap_elements,data,1)
|
||||
html = doc.to_s
|
||||
htmls[0].each_with_index do |h,i|
|
||||
html = html.gsub(h,htmls[1][i])
|
||||
end
|
||||
extras = data['extras'] || {}
|
||||
extras["subpart-id"] = subpart_id if !subpart_id.nil?
|
||||
extras["widget-title"] = OrbitHelper.widget_title
|
||||
extras.each do |key,value|
|
||||
html = html.gsub("{{#{key}}}",value.to_s.html_safe)
|
||||
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
|
||||
end
|
||||
html.html_safe
|
||||
else
|
||||
return "<div class='well'>No content to show.</div>".html_safe
|
||||
end
|
||||
end
|
||||
def update_school_data
|
||||
@readonly_fields = ['account_number','password','school_name','school_code','school_address','class_number','enrollment_limited']
|
||||
|
|
|
@ -4,8 +4,6 @@ class OlympiaSchoolDataFields
|
|||
include OrbitModel::Status
|
||||
include OrbitModel::Impression
|
||||
# encoding: utf-8
|
||||
include OrbitTag::Taggable
|
||||
include OrbitCategory::Categorizable
|
||||
field :account_number , type: String , default: ''
|
||||
field :password , type: String , default: ''
|
||||
field :school_name , type: String , default: ''
|
||||
|
@ -19,9 +17,9 @@ class OlympiaSchoolDataFields
|
|||
field :fax , type: String , default: ''
|
||||
field :mobile_number , type: String , default: ''
|
||||
field :email , type: String , default: ''
|
||||
field :enrollment , type: Hash , default: 0
|
||||
field :enrollment , type: Fixnum , default: 0
|
||||
field :approved , type: Boolean , default: true
|
||||
field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s
|
||||
field :sign_up_setting_id , type: String , default: (SignUpSetting.where(:active=>true).last.id.to_s rescue "")
|
||||
after_destroy do |record|
|
||||
OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id).destroy_all
|
||||
end
|
||||
|
@ -49,10 +47,6 @@ class OlympiaSchoolDataFields
|
|||
self.sign_up_setting_id = SignUpSetting.where(:active=>true).last.id.to_s
|
||||
self.save!
|
||||
end
|
||||
sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil
|
||||
if sign_up_setting.nil?
|
||||
self.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -39,7 +39,17 @@ class SignUpSetting
|
|||
:en=>""}
|
||||
field :active , type: Boolean , default: true
|
||||
after_save :change_all_password , :check_active
|
||||
after_create :auto_create_schools
|
||||
after_destroy do |record|
|
||||
OlympiaSchoolDataFields.where(:sign_up_setting_id => record.id).destroy_all
|
||||
end
|
||||
after_create do |record|
|
||||
SignUpSetting.where(:id.ne=>record.id).each{|record| record.update(:active=>false)}
|
||||
@sign_up_setting = SignUpSetting.where(:id.ne=>record.id).last
|
||||
@schools = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).take_while{true}
|
||||
@schools.each do |school|
|
||||
OlympiaSchoolDataFields.create(school.attributes.except(*['_id','enrollment',"view_count","created_at","updated_at","sign_up_setting_id"]).merge({:sign_up_setting_id => record.id}))
|
||||
end
|
||||
end
|
||||
def change_all_password
|
||||
if self.set_default_password && !self.default_password.blank?
|
||||
OlympiaSchoolDataFields.where(:sign_up_setting_id=>self.id).each do |school_field|
|
||||
|
@ -50,13 +60,6 @@ class SignUpSetting
|
|||
self.save
|
||||
end
|
||||
end
|
||||
def auto_create_schools
|
||||
@sign_up_setting = SignUpSetting.where(:id.ne=>self.id).last
|
||||
@schools = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id)
|
||||
@schools.each do |school|
|
||||
OlympiaSchoolDataFields.create(school.attributes.except(*['_id','enrollment']))
|
||||
end
|
||||
end
|
||||
def check_active
|
||||
if self.active
|
||||
SignUpSetting.where(:id.ne=>self.id).each do |setting|
|
||||
|
|
|
@ -4,7 +4,7 @@ module Olympiamanagement
|
|||
initializer "olympiamanagement" do
|
||||
OrbitApp.registration "Olympiamanagement", :type => "ModuleApp" do
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
taggable "olympiamanagementfields"
|
||||
set_keyword_contstraints ['/olympiamanagements/']
|
||||
categorizable
|
||||
authorizable
|
||||
widget_methods ["widget"]
|
||||
|
|
Loading…
Reference in New Issue