This commit is contained in:
BoHung Chiu 2022-10-16 19:56:14 +08:00
parent e541d53b3b
commit 8db03faa6b
3 changed files with 395 additions and 387 deletions

View File

@ -1,189 +1,192 @@
# encoding: utf-8 # encoding: utf-8
require 'fileutils' require 'fileutils'
class Filefield class Filefield
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/' @ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
@model_path = Rails.root.to_s + '/app/models/' @model_path = Rails.root.to_s + '/app/models/'
@helper_path = Rails.root.to_s + '/app/helpers/' @helper_path = Rails.root.to_s + '/app/helpers/'
@views_path = Rails.root.to_s + '/app/views/' @views_path = Rails.root.to_s + '/app/views/'
@controller_path = Rails.root.to_s + '/app/controllers/' @controller_path = Rails.root.to_s + '/app/controllers/'
@app_path = File.expand_path(__dir__) @app_path = File.expand_path(__dir__)
def self.prevpath(dir_path) def self.prevpath(dir_path)
dir_path = dir_path.gsub('\\','/') dir_path = dir_path.gsub('\\','/')
dir_arr= dir_path.split('/') dir_arr= dir_path.split('/')
dir_str='' dir_str=''
dir_arr.delete_at(-1) dir_arr.delete_at(-1)
dir_arr.each_with_index do |path,index| dir_arr.each_with_index do |path,index|
dir_str = dir_str + path dir_str = dir_str + path
if index != dir_arr.count - 1 if index != dir_arr.count - 1
dir_str = dir_str +"/" dir_str = dir_str +"/"
end
end
return dir_str
end
@app_path = self.prevpath(@app_path)
@app_path = self.prevpath(@app_path)
field :title, :type=> String ,default:"patchfile"
#field :file_show, :type=> Hash ,default:{"ckeditor"=>0,"site-preference(two-site-logo)"=>0,"member"=>0,"accessibility"=>0}
field :file_show, :type=> Hash ,default:{"ckeditor"=>{:files=>{'config@js@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=> @ckeditor_path},
'ckeditor@js'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=> @ckeditor_path}
},:status=>0} ,
"site-preference(two-site-logo)"=>{:files=>{'site@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
'application_helper@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@helper_path},
'preference@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/sites/'}
},:status=>0} ,
"member"=>{:files=>{'member_profile@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
'admin/members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@controller_path},
'members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@controller_path},
'_user_basic_passwd@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/members/'},
'attribute_value@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path}
},:status=>0} ,
"accessibility"=>{:files=>{'back_end@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'layouts/'},
'_form@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'page_parts/'},
'jquery-ui-1@13@2/'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.13.2/'},
'orbit_bar/'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'orbit_bar/'}
},:status=>0}
}
field :recovery, :type=> String , default:"false"
field :last_message , :type=> String , default:""
field :num , default: 0
after_update :updatefile
def enabled_for?(lang)
if lang.nil?
return true
else
return self.choose_lang.include?(lang)
end
end
def backup_file(file_name,file_path)
FileUtils.cd(file_path)
if file_name[-1] != "/"
FileUtils.cp(file_name , file_name+'_back')
else
FileUtils.cd('..')
@back_foler =file_path.dup #very important,don't just use '=',it will change original value when it change
@back_foler[-1] = "_back/"
FileUtils.cp_r(file_name+'.' , @back_foler)
end
end
def recover_file(file_name,file_path)
FileUtils.cd(file_path)
if file_name[-1] != "/"
FileUtils.cp(file_name+'_back', file_name)
else
FileUtils.cd('..')
@back_foler = file_name.dup #very important,don't just use '=',it will change original value when it change
@back_foler[-1] = "_back/."
if !Dir.exist?(file_name)
FileUtils.mkdir_p file_name
end
FileUtils.cp_r(@back_foler, file_name)
end
end
def copy_file(file_name,source_file_path,dest_file_path)
FileUtils.cd(source_file_path)
if file_name[-1] != "/"
@file_name = Pathname.new(file_name)
FileUtils.cd(@file_name.dirname.to_s)
FileUtils.cp(@file_name.basename.to_s , dest_file_path+@file_name.dirname.to_s)
else
if !Dir.exist?(dest_file_path)
FileUtils.mkdir_p dest_file_path
end
FileUtils.cp_r(file_name , dest_file_path+'..')
end
end
def updatefile
if self.num == 0
self.last_message = ""
if self.recovery == "true"
self.file_show.each do |name,property|
if property[:status].to_i == 1
puts 'recovering all files of '+ name
self.last_message += ('recovering all files of '+ name+'</br>')
else
@i = 0
property[:files].each do |file_name,sub_property|
if sub_property[:status].to_i == 1
@i = @i + 1
end
end
if(@i != 0)
puts 'recovering part of files:'+ name
self.last_message += ('recovering part of files:'+ name+'</br>')
end
end
property[:files].each do |file_name,sub_property|
file_name = file_name.gsub("@",".")
if sub_property[:status].to_i == 1
puts 'recovering '+file_name
self.last_message += ('recovering '+file_name+'</br>')
begin
recover_file(file_name,sub_property[:dest])
puts 'finish recovery'
self.last_message += '<span style="color:green;">finish recovery</span></br>'
rescue
puts Dir.pwd
puts 'error recovery'
self.last_message += ('<span style="color:red;">Dir: '+Dir.pwd+'</span></br>')
self.last_message += '<span style="color:red;">error recovery</span></br>'
end
end
end
end end
end
return dir_str
end
@app_path = self.prevpath(@app_path)
@app_path = self.prevpath(@app_path)
field :title, :type=> String ,default:"patchfile"
#field :file_show, :type=> Hash ,default:{"ckeditor"=>0,"site-preference(two-site-logo)"=>0,"member"=>0,"accessibility"=>0}
field :file_show, :type=> Hash ,default: {
"accessibility"=>{:files=>{
'jquery-ui-1@13@2/'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.13.2/'},
},:status=>0}
}
# field :file_show, :type=> Hash ,default:{"ckeditor"=>{:files=>{'config@js@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=> @ckeditor_path},
# 'ckeditor@js'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=> @ckeditor_path}
# },:status=>0} ,
# "site-preference(two-site-logo)"=>{:files=>{'site@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
# 'application_helper@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@helper_path},
# 'preference@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/sites/'}
# },:status=>0} ,
# "member"=>{:files=>{'member_profile@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
# 'admin/members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@controller_path},
# 'members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@controller_path},
# '_user_basic_passwd@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/members/'},
# 'attribute_value@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path}
# },:status=>0} ,
# "accessibility"=>{:files=>{'back_end@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'layouts/'},
# '_form@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'page_parts/'},
# 'jquery-ui-1@13@2/'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.13.2/'},
# 'orbit_bar/'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'orbit_bar/'}
# },:status=>0}
# }
field :recovery, :type=> String , default:"false"
field :last_message , :type=> String , default:""
field :num , default: 0
after_update :updatefile
def enabled_for?(lang)
if lang.nil?
return true
else else
self.file_show.each do |name,property| return self.choose_lang.include?(lang)
if property[:status].to_i == 1 end
puts 'copying all files of '+ name end
self.last_message += ('copying all files of '+name+'</br>')
else def backup_file(file_name,file_path)
@i = 0 FileUtils.cd(file_path)
property[:files].each do |file_name,sub_property| if file_name[-1] != "/"
if sub_property[:status].to_i == 1 FileUtils.cp(file_name , file_name+'_back')
@i = @i + 1 else
FileUtils.cd('..')
@back_foler =file_path.dup #very important,don't just use '=',it will change original value when it change
@back_foler[-1] = "_back/"
FileUtils.cp_r(file_name+'.' , @back_foler)
end
end
def recover_file(file_name,file_path)
FileUtils.cd(file_path)
if file_name[-1] != "/"
FileUtils.cp(file_name+'_back', file_name)
else
FileUtils.cd('..')
@back_foler = file_name.dup #very important,don't just use '=',it will change original value when it change
@back_foler[-1] = "_back/."
if !Dir.exist?(file_name)
FileUtils.mkdir_p file_name
end
FileUtils.cp_r(@back_foler, file_name)
end
end
def copy_file(file_name,source_file_path,dest_file_path)
FileUtils.cd(source_file_path)
if file_name[-1] != "/"
@file_name = Pathname.new(file_name)
FileUtils.cd(@file_name.dirname.to_s)
FileUtils.cp(@file_name.basename.to_s , dest_file_path+@file_name.dirname.to_s)
else
if !Dir.exist?(dest_file_path)
FileUtils.mkdir_p dest_file_path
end
FileUtils.cp_r(file_name , dest_file_path+'..')
end
end
def updatefile
if self.num == 0
self.last_message = ""
if self.recovery == "true"
self.file_show.each do |name,property|
if property[:status].to_i == 1
puts 'recovering all files of '+ name
self.last_message += ('recovering all files of '+ name+'</br>')
else
@i = 0
property[:files].each do |file_name,sub_property|
if sub_property[:status].to_i == 1
@i = @i + 1
end
end
if(@i != 0)
puts 'recovering part of files:'+ name
self.last_message += ('recovering part of files:'+ name+'</br>')
end end
end end
if(@i != 0) property[:files].each do |file_name,sub_property|
puts 'copying part of files:'+ name file_name = file_name.gsub("@",".")
self.last_message += ('copying part of files: '+name+'</br>') if sub_property[:status].to_i == 1
puts 'recovering '+file_name
self.last_message += ('recovering '+file_name+'</br>')
begin
recover_file(file_name,sub_property[:dest])
puts 'finish recovery'
self.last_message += '<span style="color:green;">finish recovery</span></br>'
rescue
puts Dir.pwd
puts 'error recovery'
self.last_message += ('<span style="color:red;">Dir: '+Dir.pwd+'</span></br>')
self.last_message += '<span style="color:red;">error recovery</span></br>'
end
end
end end
end end
property[:files].each do |file_name,sub_property| else
file_name = file_name.gsub("@",".") self.file_show.each do |name,property|
if sub_property[:status].to_i == 1 if property[:status].to_i == 1
puts 'backuping '+file_name puts 'copying all files of '+ name
self.last_message += ('backuping '+file_name+'</br>') self.last_message += ('copying all files of '+name+'</br>')
begin else
backup_file(file_name,sub_property[:dest]) @i = 0
puts 'finish backup</br>' property[:files].each do |file_name,sub_property|
self.last_message += '<span style="color:green;">finish backup</span></br>' if sub_property[:status].to_i == 1
rescue @i = @i + 1
puts Dir.pwd end
puts 'error backup</br>'
self.last_message += ('<span style="color:red;">Dir: '+Dir.pwd+'</span></br>')
self.last_message += '<span style="color:red;">error backup</span></br>'
end end
puts 'copying '+file_name if(@i != 0)
self.last_message += ('copying '+file_name+'</br>') puts 'copying part of files:'+ name
begin self.last_message += ('copying part of files: '+name+'</br>')
copy_file(file_name,sub_property[:sc],sub_property[:dest]) end
puts 'finish copy' end
self.last_message += '<span style="color:green;">finish copy</span></br>' property[:files].each do |file_name,sub_property|
rescue file_name = file_name.gsub("@",".")
puts Dir.pwd if sub_property[:status].to_i == 1
self.last_message += ('<span style="color:red;">Dir: '+Dir.pwd+'</span></br>') puts 'backuping '+file_name
puts 'error copy' self.last_message += ('backuping '+file_name+'</br>')
self.last_message += '<span style="color:red;">error copy</span></br>' begin
backup_file(file_name,sub_property[:dest])
puts 'finish backup'
self.last_message += '<span style="color:green;">finish backup</span></br>'
rescue
puts 'error backup'
self.last_message += ('<span style="color:red;">Dir: '+Dir.pwd+'</span></br>')
self.last_message += '<span style="color:red;">error backup</span></br>'
end
puts 'copying '+file_name
self.last_message += ('copying '+file_name+'</br>')
begin
copy_file(file_name,sub_property[:sc],sub_property[:dest])
puts 'finish copy'
self.last_message += '<span style="color:green;">finish copy</span></br>'
rescue
self.last_message += ('<span style="color:red;">Dir: '+Dir.pwd+'</span></br>')
puts 'error copy'
self.last_message += '<span style="color:red;">error copy</span></br>'
end
end end
end end
end end
end end
self.num = 1
self.save
end end
self.num = 1 Dir.chdir(Rails.root.to_s)
self.save
end end
Dir.chdir(Rails.root.to_s)
end
end end

View File

@ -1,235 +1,235 @@
class Patchfilefield class Patchfilefield
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include OrbitModel::Status include OrbitModel::Status
include OrbitModel::Impression include OrbitModel::Impression
# encoding: utf-8 # encoding: utf-8
include OrbitTag::Taggable include OrbitTag::Taggable
include OrbitCategory::Categorizable include OrbitCategory::Categorizable
field :font_array , :type => Hash, default:{} field :font_array , :type => Hash, default:{}
field :new_add_font, type: String, default:"" field :new_add_font, type: String, default:""
field :delete_font, type: String, default:"" field :delete_font, type: String, default:""
field :used_font , :type => Array, default:[] field :used_font , :type => Array, default:[]
field :un_used_font , :type => Array, default:[] field :un_used_font , :type => Array, default:[]
field :title ,type:String ,default:"" field :title ,type:String ,default:""
field :subtitle, localize: true field :subtitle, localize: true
field :text, localize: true field :text, localize: true
# before_destroy :destroy_email # before_destroy :destroy_email
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])} scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
scope :is_approved, ->{where(:approved => true)} scope :is_approved, ->{where(:approved => true)}
before_create :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font before_create :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
before_update :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font before_update :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
before_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font before_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
after_save :set_config after_save :set_config
#before_create :set_expire #before_create :set_expire
def delete_empty_font def delete_empty_font
self.font_array.each do |font,istrue| self.font_array.each do |font,istrue|
if font.strip == "" if font.strip == ""
self.font_array.delete(font) self.font_array.delete(font)
end
end end
end end
end def get_font_to_store
def get_font_to_store @ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor' @filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return
@filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return @name_to_search ="config.font_names"
@name_to_search ="config.font_names" @index_of_font = @filedata.index(@name_to_search)
@index_of_font = @filedata.index(@name_to_search) @font_str = ""
@font_str = "" @end_character
@end_character if @index_of_font != nil
if @index_of_font != nil @inex_start_to_search = @index_of_font + @name_to_search.length
@inex_start_to_search = @index_of_font + @name_to_search.length @str_start = @inex_start_to_search
@str_start = @inex_start_to_search if (@filedata[@inex_start_to_search] != "\'" && @filedata[@inex_start_to_search] != "\"")
if (@filedata[@inex_start_to_search] != "\'" && @filedata[@inex_start_to_search] != "\"") for @str_start in @inex_start_to_search..@filedata.length
for @str_start in @inex_start_to_search..@filedata.length break if (@filedata[@str_start] == "\'" || @filedata[@str_start] == "\"")
break if (@filedata[@str_start] == "\'" || @filedata[@str_start] == "\"")
end
end
@end_character = @filedata[@str_start]
@str_end = @str_start+1
if @str_start+1 < @filedata.length
@str_end = @str_start+1
for @str_end in @str_start+1..@filedata.length
break if @filedata[@str_end] == @end_character || @str_end == @str_start
if @filedata[@str_end] == "="
@str_end = @str_start
break
end end
end end
if @str_end != @str_start @end_character = @filedata[@str_start]
@font_str = @filedata[@str_start+1...@str_end] @str_end = @str_start+1
else if @str_start+1 < @filedata.length
@font_str = "" @str_end = @str_start+1
end for @str_end in @str_start+1..@filedata.length
end break if @filedata[@str_end] == @end_character || @str_end == @str_start
@font_array = @font_str.split("\;") if @filedata[@str_end] == "="
@font_array.map!{|i| i.strip} @str_end = @str_start
@font_array.delete("") break
@font_array.each do |font|
@i = 0
if font != self.delete_font
self.font_array.keys.each do |each_font|
if each_font == font
@i = 1
end end
break if @i == 1
end end
if @i == 0 if @str_end != @str_start
self.font_array = self.font_array.merge({font => true}) @font_str = @filedata[@str_start+1...@str_end]
else
@font_str = ""
end
end
@font_array = @font_str.split("\;")
@font_array.map!{|i| i.strip}
@font_array.delete("")
@font_array.each do |font|
@i = 0
if font != self.delete_font
self.font_array.keys.each do |each_font|
if each_font == font
@i = 1
end
break if @i == 1
end
if @i == 0
self.font_array = self.font_array.merge({font => true})
end
end end
end end
end end
end if self.new_add_font.strip !=""
if self.new_add_font.strip !="" @i = 0
@i = 0 self.font_array.keys.each do |each_font|
self.font_array.keys.each do |each_font| if each_font == self.new_add_font
if each_font == self.new_add_font @i = 1
@i = 1 end
break if @i == 1
end end
break if @i == 1 if @i == 0
end self.font_array = self.font_array.merge({self.new_add_font.strip => true})
if @i == 0 end
self.font_array = self.font_array.merge({self.new_add_font.strip => true}) self.new_add_font = ""
end
self.new_add_font = ""
end
end
def set_un_used_font
@un_use_font = []
self.font_array.each do |font,istrue|
if istrue == false
@un_use_font.push font.strip
end end
end end
self.un_used_font = @un_use_font def set_un_used_font
end @un_use_font = []
def set_used_font self.font_array.each do |font,istrue|
@use_font = [] if istrue == false
self.font_array.each do |font,istrue| @un_use_font.push font.strip
if istrue == true
@use_font.push font.strip
end
end
@use_font.delete("")
self.used_font = @use_font
end
def check_font_state
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
@filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return
@name_to_search ="config.font_names"
@index_of_font = @filedata.index(@name_to_search)
@font_str = ""
@end_character
@str_start
@str_end
@font_array
if @index_of_font != nil
@inex_start_to_search = @index_of_font + @name_to_search.length
@str_start = @inex_start_to_search
if (@filedata[@inex_start_to_search] != "\'" && @filedata[@inex_start_to_search] != "\"")
for @str_start in @inex_start_to_search..@filedata.length
break if (@filedata[@str_start] == "\'" || @filedata[@str_start] == "\"")
end end
end end
@end_character = @filedata[@str_start] self.un_used_font = @un_use_font
@str_end = @str_start+1 end
if @str_start+1 < @filedata.length def set_used_font
@use_font = []
self.font_array.each do |font,istrue|
if istrue == true
@use_font.push font.strip
end
end
@use_font.delete("")
self.used_font = @use_font
end
def check_font_state
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
@filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return
@name_to_search ="config.font_names"
@index_of_font = @filedata.index(@name_to_search)
@font_str = ""
@end_character
@str_start
@str_end
@font_array
if @index_of_font != nil
@inex_start_to_search = @index_of_font + @name_to_search.length
@str_start = @inex_start_to_search
if (@filedata[@inex_start_to_search] != "\'" && @filedata[@inex_start_to_search] != "\"")
for @str_start in @inex_start_to_search..@filedata.length
break if (@filedata[@str_start] == "\'" || @filedata[@str_start] == "\"")
end
end
@end_character = @filedata[@str_start]
@str_end = @str_start+1 @str_end = @str_start+1
for @str_end in @str_start+1..@filedata.length if @str_start+1 < @filedata.length
break if @filedata[@str_end] == @end_character || @str_end == @str_start @str_end = @str_start+1
if @filedata[@str_end] == "=" for @str_end in @str_start+1..@filedata.length
@str_end = @str_start break if @filedata[@str_end] == @end_character || @str_end == @str_start
break if @filedata[@str_end] == "="
@str_end = @str_start
break
end
end
if @str_end != @str_start
@font_str = @filedata[@str_start+1...@str_end]
else
@font_str = ""
end end
end end
if @str_end != @str_start @font_array = @font_str.split("\;")
@font_str = @filedata[@str_start+1...@str_end] @font_array.map!{|i| i.strip}
else @font_array.delete("")
@font_str = "" if !check_eql_array(@font_array,self.used_font)
end
end
@font_array = @font_str.split("\;")
@font_array.map!{|i| i.strip}
@font_array.delete("")
if !check_eql_array(@font_array,self.used_font)
return false
else
return true
end
end
end
def set_config
@istrue = check_font_state
if @istrue == false
@delete_font_array = []
self.un_used_font.each do |font_to_delete|
if @font_array.include? font_to_delete.strip
@delete_font_array.push font_to_delete.strip
end
end
@delete_font_array.push(self.delete_font) if self.delete_font != ""
self.delete_font = ""
@add_font_array = []
@use_font = self.used_font rescue []
@use_font.each do |font_to_add|
if !(@font_array.include? font_to_add.strip)
@add_font_array.push font_to_add.strip
end
end
if @add_font_array != [] || @delete_font_array != []
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
Dir.chdir(@ckeditor_path) do
File.open("custom_fonts.txt","w+") do |f|
f.write(self.used_font.join(";"))
end
puts "writing........."
File.open("config.js.erb","a+") do |f|
f.puts ""
end
end
end
end
end
def check_eql_array(array1,array2)
if array1.count == array2.count
array1.each do |item|
if !(array2.include? item)
return false return false
else
return true
end end
end end
return true
else
return false
end end
end def set_config
def update_user @istrue = check_font_state
User.find(update_user_id) rescue nil if @istrue == false
end @delete_font_array = []
def update_user=(user) self.un_used_font.each do |font_to_delete|
self.update_user_id = user.id if @font_array.include? font_to_delete.strip
end @delete_font_array.push font_to_delete.strip
def email_members end
MemberProfile.find(self.email_member_ids) rescue [] end
end @delete_font_array.push(self.delete_font) if self.delete_font != ""
def email_addresses self.delete_font = ""
addresses = self.email_members.collect{|member| member.email} rescue [] @add_font_array = []
addresses = addresses +[self.other_mailaddress] if !self.other_mailaddress.blank? @use_font = self.used_font rescue []
addresses.flatten @use_font.each do |font_to_add|
end if !(@font_array.include? font_to_add.strip)
def email @add_font_array.push font_to_add.strip
mail = Email.find(self.email_id) rescue nil end
end end
def expired? if @add_font_array != [] || @delete_font_array != []
(self.deadline < Time.now) rescue false @ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
end Dir.chdir(@ckeditor_path) do
def destroy_email File.open("custom_fonts.txt","w+") do |f|
mail = Email.find(self.email_id) rescue nil f.write(self.used_font.join(";"))
mail.destroy if !mail.nil? end
end puts "writing........."
def self.remove_expired_status File.open("config.js.erb","a+") do |f|
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b| f.puts ""
b.is_top = false end
b.top_end_date = nil end
b.save end
end end
end end
def check_eql_array(array1,array2)
if array1.count == array2.count
array1.each do |item|
if !(array2.include? item)
return false
end
end
return true
else
return false
end
end
def update_user
User.find(update_user_id) rescue nil
end
def update_user=(user)
self.update_user_id = user.id
end
def email_members
MemberProfile.find(self.email_member_ids) rescue []
end
def email_addresses
addresses = self.email_members.collect{|member| member.email} rescue []
addresses = addresses +[self.other_mailaddress] if !self.other_mailaddress.blank?
addresses.flatten
end
def email
mail = Email.find(self.email_id) rescue nil
end
def expired?
(self.deadline < Time.now) rescue false
end
def destroy_email
mail = Email.find(self.email_id) rescue nil
mail.destroy if !mail.nil?
end
def self.remove_expired_status
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b|
b.is_top = false
b.top_end_date = nil
b.save
end
end
end end

View File

@ -59,6 +59,13 @@
<br> <br>
<button id="clickall"><%= (I18n.locale.to_s == "zh_tw") ? "全選" : "select all" %></button> <button id="clickall"><%= (I18n.locale.to_s == "zh_tw") ? "全選" : "select all" %></button>
<button id="unclickall"><%= (I18n.locale.to_s == "zh_tw") ? "取消全選" : "unselect all" %></button> <button id="unclickall"><%= (I18n.locale.to_s == "zh_tw") ? "取消全選" : "unselect all" %></button>
<%
default_file_show = @file_to_show..fields['file_show'].options[:default]
if @file_to_show.file_show.count != default_file_show.count
@file_to_show.file_show = default_file_show
@file_to_show.save
end
%>
<%=form_for @file_to_show ,:url=>{:controller=>"patchfiles" ,:action=>"edit"} do |file|%> <%=form_for @file_to_show ,:url=>{:controller=>"patchfiles" ,:action=>"edit"} do |file|%>
<%= file.fields_for :file_show do |filefield|%> <%= file.fields_for :file_show do |filefield|%>
<div id="fileform"> <div id="fileform">
@ -170,14 +177,12 @@
}); });
$("#clickall").off("click").on("click",function(){ $("#clickall").off("click").on("click",function(){
for(var i =0;i<$(".sub_checkbox").length ; i++){ for(var i =0;i<$(".sub_checkbox").length ; i++){
if($(".checkbox").eq(i).is(":checked") == false) $(".checkbox").prop('checked', true);
$(".checkbox").eq(i).click();
} }
}); });
$("#unclickall").off("click").on("click",function(){ $("#unclickall").off("click").on("click",function(){
for(var i =0;i<$(".sub_checkbox").length ; i++){ for(var i =0;i<$(".sub_checkbox").length ; i++){
if($(".checkbox").eq(i).is(":checked") == true) $(".checkbox").prop('checked', false);
$(".checkbox").eq(i).click();
} }
}); });
function seelogfcn(){ function seelogfcn(){