Updated.
This commit is contained in:
parent
e541d53b3b
commit
8db03faa6b
|
@ -1,189 +1,192 @@
|
|||
# encoding: utf-8
|
||||
require 'fileutils'
|
||||
class Filefield
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
|
||||
@model_path = Rails.root.to_s + '/app/models/'
|
||||
@helper_path = Rails.root.to_s + '/app/helpers/'
|
||||
@views_path = Rails.root.to_s + '/app/views/'
|
||||
@controller_path = Rails.root.to_s + '/app/controllers/'
|
||||
@app_path = File.expand_path(__dir__)
|
||||
def self.prevpath(dir_path)
|
||||
dir_path = dir_path.gsub('\\','/')
|
||||
dir_arr= dir_path.split('/')
|
||||
dir_str=''
|
||||
dir_arr.delete_at(-1)
|
||||
dir_arr.each_with_index do |path,index|
|
||||
dir_str = dir_str + path
|
||||
if index != dir_arr.count - 1
|
||||
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
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
|
||||
@model_path = Rails.root.to_s + '/app/models/'
|
||||
@helper_path = Rails.root.to_s + '/app/helpers/'
|
||||
@views_path = Rails.root.to_s + '/app/views/'
|
||||
@controller_path = Rails.root.to_s + '/app/controllers/'
|
||||
@app_path = File.expand_path(__dir__)
|
||||
def self.prevpath(dir_path)
|
||||
dir_path = dir_path.gsub('\\','/')
|
||||
dir_arr= dir_path.split('/')
|
||||
dir_str=''
|
||||
dir_arr.delete_at(-1)
|
||||
dir_arr.each_with_index do |path,index|
|
||||
dir_str = dir_str + path
|
||||
if index != dir_arr.count - 1
|
||||
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: {
|
||||
"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
|
||||
self.file_show.each do |name,property|
|
||||
if property[:status].to_i == 1
|
||||
puts 'copying all files of '+ name
|
||||
self.last_message += ('copying 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
|
||||
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
|
||||
if(@i != 0)
|
||||
puts 'copying part of files:'+ name
|
||||
self.last_message += ('copying part of files: '+name+'</br>')
|
||||
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
|
||||
property[:files].each do |file_name,sub_property|
|
||||
file_name = file_name.gsub("@",".")
|
||||
if sub_property[:status].to_i == 1
|
||||
puts 'backuping '+file_name
|
||||
self.last_message += ('backuping '+file_name+'</br>')
|
||||
begin
|
||||
backup_file(file_name,sub_property[:dest])
|
||||
puts 'finish backup</br>'
|
||||
self.last_message += '<span style="color:green;">finish backup</span></br>'
|
||||
rescue
|
||||
puts Dir.pwd
|
||||
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>'
|
||||
else
|
||||
self.file_show.each do |name,property|
|
||||
if property[:status].to_i == 1
|
||||
puts 'copying all files of '+ name
|
||||
self.last_message += ('copying 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
|
||||
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
|
||||
puts Dir.pwd
|
||||
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>'
|
||||
if(@i != 0)
|
||||
puts 'copying part of files:'+ name
|
||||
self.last_message += ('copying 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 'backuping '+file_name
|
||||
self.last_message += ('backuping '+file_name+'</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
|
||||
self.num = 1
|
||||
self.save
|
||||
end
|
||||
self.num = 1
|
||||
self.save
|
||||
Dir.chdir(Rails.root.to_s)
|
||||
end
|
||||
Dir.chdir(Rails.root.to_s)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,235 +1,235 @@
|
|||
class Patchfilefield
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include OrbitModel::Status
|
||||
include OrbitModel::Impression
|
||||
# encoding: utf-8
|
||||
include OrbitTag::Taggable
|
||||
include OrbitCategory::Categorizable
|
||||
field :font_array , :type => Hash, default:{}
|
||||
field :new_add_font, type: String, default:""
|
||||
field :delete_font, type: String, default:""
|
||||
field :used_font , :type => Array, default:[]
|
||||
field :un_used_font , :type => Array, default:[]
|
||||
field :title ,type:String ,default:""
|
||||
field :subtitle, localize: true
|
||||
field :text, localize: true
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include OrbitModel::Status
|
||||
include OrbitModel::Impression
|
||||
# encoding: utf-8
|
||||
include OrbitTag::Taggable
|
||||
include OrbitCategory::Categorizable
|
||||
field :font_array , :type => Hash, default:{}
|
||||
field :new_add_font, type: String, default:""
|
||||
field :delete_font, type: String, default:""
|
||||
field :used_font , :type => Array, default:[]
|
||||
field :un_used_font , :type => Array, default:[]
|
||||
field :title ,type:String ,default:""
|
||||
field :subtitle, localize: true
|
||||
field :text, localize: true
|
||||
# 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 :is_approved, ->{where(:approved => true)}
|
||||
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_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
||||
after_save :set_config
|
||||
#before_create :set_expire
|
||||
def delete_empty_font
|
||||
self.font_array.each do |font,istrue|
|
||||
if font.strip == ""
|
||||
self.font_array.delete(font)
|
||||
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)}
|
||||
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_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
||||
after_save :set_config
|
||||
#before_create :set_expire
|
||||
def delete_empty_font
|
||||
self.font_array.each do |font,istrue|
|
||||
if font.strip == ""
|
||||
self.font_array.delete(font)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_font_to_store
|
||||
@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
|
||||
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
|
||||
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
|
||||
def get_font_to_store
|
||||
@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
|
||||
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
|
||||
if @str_end != @str_start
|
||||
@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_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
|
||||
break if @i == 1
|
||||
end
|
||||
if @i == 0
|
||||
self.font_array = self.font_array.merge({font => true})
|
||||
if @str_end != @str_start
|
||||
@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
|
||||
if self.new_add_font.strip !=""
|
||||
@i = 0
|
||||
self.font_array.keys.each do |each_font|
|
||||
if each_font == self.new_add_font
|
||||
@i = 1
|
||||
if self.new_add_font.strip !=""
|
||||
@i = 0
|
||||
self.font_array.keys.each do |each_font|
|
||||
if each_font == self.new_add_font
|
||||
@i = 1
|
||||
end
|
||||
break if @i == 1
|
||||
end
|
||||
break if @i == 1
|
||||
end
|
||||
if @i == 0
|
||||
self.font_array = self.font_array.merge({self.new_add_font.strip => true})
|
||||
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
|
||||
if @i == 0
|
||||
self.font_array = self.font_array.merge({self.new_add_font.strip => true})
|
||||
end
|
||||
self.new_add_font = ""
|
||||
end
|
||||
end
|
||||
self.un_used_font = @un_use_font
|
||||
end
|
||||
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] == "\"")
|
||||
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_character = @filedata[@str_start]
|
||||
@str_end = @str_start+1
|
||||
if @str_start+1 < @filedata.length
|
||||
self.un_used_font = @un_use_font
|
||||
end
|
||||
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
|
||||
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
|
||||
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
|
||||
if @str_end != @str_start
|
||||
@font_str = @filedata[@str_start+1...@str_end]
|
||||
else
|
||||
@font_str = ""
|
||||
end
|
||||
end
|
||||
if @str_end != @str_start
|
||||
@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("")
|
||||
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)
|
||||
@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
|
||||
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
|
||||
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
|
||||
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
|
|
@ -59,6 +59,13 @@
|
|||
<br>
|
||||
<button id="clickall"><%= (I18n.locale.to_s == "zh_tw") ? "全選" : "select 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|%>
|
||||
<%= file.fields_for :file_show do |filefield|%>
|
||||
<div id="fileform">
|
||||
|
@ -170,14 +177,12 @@
|
|||
});
|
||||
$("#clickall").off("click").on("click",function(){
|
||||
for(var i =0;i<$(".sub_checkbox").length ; i++){
|
||||
if($(".checkbox").eq(i).is(":checked") == false)
|
||||
$(".checkbox").eq(i).click();
|
||||
$(".checkbox").prop('checked', true);
|
||||
}
|
||||
});
|
||||
$("#unclickall").off("click").on("click",function(){
|
||||
for(var i =0;i<$(".sub_checkbox").length ; i++){
|
||||
if($(".checkbox").eq(i).is(":checked") == true)
|
||||
$(".checkbox").eq(i).click();
|
||||
$(".checkbox").prop('checked', false);
|
||||
}
|
||||
});
|
||||
function seelogfcn(){
|
||||
|
|
Loading…
Reference in New Issue