fix all bugs and simplify code and add the feature that user can see the file logs on the web
This commit is contained in:
parent
2695e0ff67
commit
5977c8224d
|
@ -20,18 +20,25 @@ class Admin::PatchfilesController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def edit
|
def edit
|
||||||
params["filefield"]["file_show"].each_with_index do |(key,value),index|
|
params["filefield"]["file_show"].each do |name,status|
|
||||||
@key = @file_to_show.file_show.keys[index]
|
@file_to_show.file_show[name][:status] = status.to_i
|
||||||
@file_to_show.file_show[@key] = value.to_i
|
end
|
||||||
|
params["filefield"]["sub_file_fields"].each do |name,files|
|
||||||
|
files.each do |index,file_and_status|
|
||||||
|
file_and_status.each do |file_name,status|
|
||||||
|
@file_to_show["file_show"][name]["files"][file_name]["status"] = status.to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if params["filefield"]["recovery_btn"] == "true"
|
if params["filefield"]["recovery_btn"] == "true"
|
||||||
@file_to_show.recovery = "true"
|
@file_to_show.recovery = "true"
|
||||||
@file_to_show.update
|
|
||||||
redirect_to admin_patchfiles_path and return
|
|
||||||
else
|
else
|
||||||
@file_to_show.update
|
@file_to_show.recovery = "false"
|
||||||
redirect_to admin_patchfiles_path and return
|
|
||||||
end
|
end
|
||||||
|
@file_to_show.num = 0
|
||||||
|
@file_to_show.update
|
||||||
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
||||||
|
redirect_to admin_patchfiles_path and return
|
||||||
end
|
end
|
||||||
def showckeditor
|
def showckeditor
|
||||||
end
|
end
|
||||||
|
@ -203,13 +210,22 @@ class Admin::PatchfilesController < OrbitAdminController
|
||||||
else
|
else
|
||||||
@default_field = Filefield.new()
|
@default_field = Filefield.new()
|
||||||
@file_to_show = Filefield.where("title"=>@app_title).first
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
||||||
@default_field.file_show.each do |check,istrue|
|
@default_field.file_show.each do |name,property|
|
||||||
if @file_to_show.file_show[check] == nil
|
if @file_to_show.file_show[name] == nil
|
||||||
@file_to_show.file_show[check] = istrue
|
@file_to_show.file_show[name] = property
|
||||||
@file_to_show.save
|
@file_to_show.save
|
||||||
@file_to_show = Filefield.where("title"=>@app_title).first
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@default_field.file_show.each do |name,property|
|
||||||
|
property[:files].each do |file_name,sub_property|
|
||||||
|
if @file_to_show.file_show[name][:files][file_name] == nil
|
||||||
|
@file_to_show.file_show[name][:files][file_name] = sub_property
|
||||||
|
@file_to_show.save
|
||||||
|
@file_to_show = Filefield.where("title"=>@app_title).first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,25 +1,15 @@
|
||||||
# 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/'
|
||||||
|
@model_path = Rails.root.to_s + '/app/models/'
|
||||||
field :title, :type=> String ,default:"patchfile"
|
@helper_path = Rails.root.to_s + '/app/helpers/'
|
||||||
field :file_show, :type=> Hash ,default:{"ckeditor"=>0,"site-preference(two-site-logo)"=>0,"member"=>0,"accessibility"=>0}
|
@views_path = Rails.root.to_s + '/app/views/'
|
||||||
field :recovery, :type=> String , default:"false"
|
@controller_path = Rails.root.to_s + '/app/controllers/'
|
||||||
after_update :updatefile
|
@app_path = File.expand_path(__dir__)
|
||||||
|
def self.prevpath(dir_path)
|
||||||
|
|
||||||
def enabled_for?(lang)
|
|
||||||
if lang.nil?
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return self.choose_lang.include?(lang)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def lastpath 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=''
|
||||||
|
@ -32,178 +22,154 @@ class Filefield
|
||||||
end
|
end
|
||||||
return dir_str
|
return dir_str
|
||||||
end
|
end
|
||||||
def updatefile
|
@app_path = self.prevpath(@app_path)
|
||||||
if self.recovery == "true"
|
@app_path = self.prevpath(@app_path)
|
||||||
self.file_show.each do |key,value|
|
field :title, :type=> String ,default:"patchfile"
|
||||||
if value == 1
|
#field :file_show, :type=> Hash ,default:{"ckeditor"=>0,"site-preference(two-site-logo)"=>0,"member"=>0,"accessibility"=>0}
|
||||||
@model_path = Rails.root.to_s + '/app/models/'
|
field :file_show, :type=> Hash ,default:{"ckeditor"=>{:files=>{'config@js@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=> @ckeditor_path}},:status=>0} ,
|
||||||
@helper_path = Rails.root.to_s + '/app/helpers/'
|
"site-preference(two-site-logo)"=>{:files=>{'site@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
|
||||||
@views_path = Rails.root.to_s + '/app/views/'
|
'application_helper@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@helper_path},
|
||||||
@controller_path = Rails.root.to_s + '/app/controllers/'
|
'preference@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/sites/'}
|
||||||
if key == "ckeditor"
|
},:status=>0} ,
|
||||||
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
|
"member"=>{:files=>{'member_profile@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/', :dest=>@model_path},
|
||||||
puts 'recovery CKEDITOR'
|
'members_controller@rb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@controller_path+'admin/'},
|
||||||
begin
|
'_user_basic_passwd@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/admin/', :dest=>@views_path+'admin/members/'}
|
||||||
FileUtils.cd(@ckeditor_path)
|
},:status=>0} ,
|
||||||
FileUtils.cp('config.js.erb_back' , 'config.js.erb')
|
"accessibility"=>{:files=>{'back_end@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'layouts/'},
|
||||||
rescue
|
'_form@html@erb'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>@views_path+'page_parts/'},
|
||||||
puts Dir.pwd
|
'jquery-ui-1@12@1/'=>{:status=>0, :sc=>@app_path+'/updatefiles/accessibility/', :dest=>Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/'}
|
||||||
puts 'error recovery'
|
},:status=>0}
|
||||||
end
|
}
|
||||||
elsif key == "site-preference(two-site-logo)"
|
field :recovery, :type=> String , default:"false"
|
||||||
puts 'recovery site'
|
field :last_message , :type=> String , default:""
|
||||||
begin
|
field :num , default: 0
|
||||||
FileUtils.cd(@model_path)
|
after_update :updatefile
|
||||||
FileUtils.cp('site.rb_back' , 'site.rb')
|
def enabled_for?(lang)
|
||||||
FileUtils.cd(@helper_path)
|
if lang.nil?
|
||||||
FileUtils.cp('application_helper.rb_back' , 'application_helper.rb')
|
return true
|
||||||
FileUtils.cd(@views_path+'admin/sites/')
|
else
|
||||||
FileUtils.cp('preference.html.erb_back','preference.html.erb')
|
return self.choose_lang.include?(lang)
|
||||||
rescue
|
end
|
||||||
puts Dir.pwd
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
puts 'error recovery'
|
|
||||||
end
|
|
||||||
elsif key == "member"
|
|
||||||
puts 'recovery member'
|
|
||||||
begin
|
|
||||||
FileUtils.cd(@model_path)
|
|
||||||
FileUtils.cp('member_profile.rb_back' , 'member_profile.rb')
|
|
||||||
FileUtils.cd(@controller_path+'admin/')
|
|
||||||
FileUtils.cp('members_controller.rb_back' , 'members_controller.rb')
|
|
||||||
FileUtils.cd(@views_path+'admin/members/')
|
|
||||||
FileUtils.cp('_user_basic_passwd.html.erb_back' , '_user_basic_passwd.html.erb')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
puts 'error recovery'
|
|
||||||
end
|
|
||||||
elsif key == "accessibility"
|
|
||||||
puts 'recovery accessibility'
|
|
||||||
begin
|
|
||||||
FileUtils.cd(@views_path+'layouts/')
|
|
||||||
FileUtils.cp('back_end.html.erb_back' , 'back_end.html.erb')
|
|
||||||
FileUtils.cd(@views_path+'page_parts/')
|
|
||||||
FileUtils.cp('_form.html.erb_back' , '_form.html.erb')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
puts 'error recovery'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
FileUtils.cd(Rails.root.to_s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.file_show.each do |key,value|
|
|
||||||
if value == 1
|
|
||||||
@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/'
|
|
||||||
if key == "ckeditor"
|
|
||||||
@app_path = File.expand_path(__dir__)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
|
|
||||||
puts 'copying CKEDITOR'
|
|
||||||
begin
|
|
||||||
Dir.chdir(@ckeditor_path)
|
|
||||||
File.rename('config.js.erb','config.js.erb_back')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
end
|
|
||||||
FileUtils.cd(@app_path+'/updatefiles/')
|
|
||||||
begin
|
|
||||||
FileUtils.cp('config.js.erb' , @ckeditor_path)
|
|
||||||
puts @ckeditor_path
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
puts 'error copy'
|
|
||||||
end
|
|
||||||
elsif key == "site-preference(two-site-logo)"
|
|
||||||
@app_path = File.expand_path(__dir__)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
puts @app_path
|
|
||||||
puts 'copying site'
|
|
||||||
begin
|
|
||||||
Dir.chdir(@model_path)
|
|
||||||
File.rename('site.rb','site.rb_back')
|
|
||||||
Dir.chdir(@helper_path)
|
|
||||||
File.rename('application_helper.rb','application_helper.rb_back')
|
|
||||||
Dir.chdir(@views_path+'admin/sites/')
|
|
||||||
File.rename('preference.html.erb','preference.html.erb_back')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
end
|
|
||||||
FileUtils.cd(@app_path+'/updatefiles/')
|
|
||||||
begin
|
|
||||||
FileUtils.cp('site.rb' , @model_path)
|
|
||||||
FileUtils.cp('application_helper.rb' , @helper_path)
|
|
||||||
FileUtils.cd('admin/')
|
|
||||||
FileUtils.cp('preference.html.erb',@views_path+'admin/sites/')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
puts 'error copy'
|
|
||||||
end
|
|
||||||
elsif key == "member"
|
|
||||||
@app_path = File.expand_path(__dir__)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
begin
|
|
||||||
Dir.chdir(@model_path)
|
|
||||||
File.rename('member_profile.rb','member_profile.rb_back')
|
|
||||||
Dir.chdir(@controller_path+'admin/')
|
|
||||||
File.rename('members_controller.rb','members_controller.rb_back')
|
|
||||||
Dir.chdir(@views_path+'admin/members/')
|
|
||||||
File.rename('_user_basic_passwd.html.erb','_user_basic_passwd.html.erb_back')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
end
|
|
||||||
FileUtils.cd(@app_path+'/updatefiles/')
|
|
||||||
puts 'copying member'
|
|
||||||
begin
|
|
||||||
FileUtils.cp('member_profile.rb' , @model_path)
|
|
||||||
FileUtils.cd('admin/')
|
|
||||||
FileUtils.cp('members_controller.rb' , @controller_path+'admin/')
|
|
||||||
FileUtils.cp('_user_basic_passwd.html.erb' , @views_path+'admin/members/')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
puts 'error copy'
|
|
||||||
end
|
|
||||||
elsif key == "accessibility"
|
|
||||||
@app_path = File.expand_path(__dir__)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
@app_path = lastpath(@app_path)
|
|
||||||
begin
|
|
||||||
Dir.chdir(@views_path+'layouts/')
|
|
||||||
File.rename('back_end.html.erb','back_end.html.erb_back')
|
|
||||||
Dir.chdir(@views_path+'page_parts/')
|
|
||||||
File.rename('_form.html.erb','_form.html.erb_back')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
end
|
|
||||||
FileUtils.cd(@app_path+'/updatefiles/accessibility/')
|
|
||||||
puts 'copying accessibility'
|
|
||||||
begin
|
|
||||||
FileUtils.cp('back_end.html.erb' , @views_path+'layouts/')
|
|
||||||
FileUtils.cp('_form.html.erb' , @views_path+'page_parts/')
|
|
||||||
FileUtils.cp_r('jquery-ui-1.12.1/' ,Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/')
|
|
||||||
rescue
|
|
||||||
puts Dir.pwd
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
puts 'error copy'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Dir.chdir(Rails.root.to_s)
|
|
||||||
FileUtils.cd(Rails.root.to_s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def backup_file(file_name,file_path)
|
||||||
|
FileUtils.cd(file_path)
|
||||||
|
if (file_name.include? "/") == false
|
||||||
|
FileUtils.cp(file_name , file_name+'_back')
|
||||||
|
else
|
||||||
|
@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.include? "/") == false
|
||||||
|
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/"
|
||||||
|
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.include? "/") == false
|
||||||
|
FileUtils.cp(file_name , dest_file_path)
|
||||||
|
else
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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</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>'
|
||||||
|
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>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.num = 1
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
Dir.chdir(Rails.root.to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,20 +5,41 @@
|
||||||
<%=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">
|
||||||
<% @file_to_show.file_show.each do |show| %>
|
|
||||||
<%if show[1] == 1%>
|
<% @file_to_show.file_show.each do |name,property| %>
|
||||||
<%=filefield.check_box "file_show"+@i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:class=>"checkbox",:style=>"float:left;"}%>
|
<span style="clear:both;">
|
||||||
|
<%if property[:status].to_i == 1%>
|
||||||
|
<%=filefield.check_box name,{:checked=>true,:id=>"checkbox"+@i.to_s,:class=>"checkbox",:style=>"float:left;"}%>
|
||||||
<%else%>
|
<%else%>
|
||||||
<%=filefield.check_box "file_show"+@i.to_s,{:checked=>false,:id=>"checkbox"+@i.to_s,:class=>"checkbox",:style=>"float:left;"}%>
|
<%=filefield.check_box name,{:checked=>false,:id=>"checkbox"+@i.to_s,:class=>"checkbox",:style=>"float:left;"}%>
|
||||||
<%end%>
|
<%end%>
|
||||||
<label for="<%="checkbox"+@i.to_s%>" class="checklabel" style="float:left;"><%=show[0]%></label>
|
<label for="<%="checkbox"+@i.to_s%>" class="checklabel" style="float:left;"><%=name%></label>
|
||||||
<% @i = @i+1 %>
|
|
||||||
<div style="clear:both;"></div>
|
<div style="clear:both;"></div>
|
||||||
|
<% @i = @i+1 %>
|
||||||
|
<% @j = 0 %>
|
||||||
|
<%= file.fields_for :sub_file_fields do |each_files|%>
|
||||||
|
<%= each_files.fields_for name do |each_file|%>
|
||||||
|
<% property[:files].each do |file_name,sub_property| %>
|
||||||
|
<%if sub_property[:status].to_i == 1%>
|
||||||
|
<%=each_file.check_box file_name,{:checked=>true,:id=>"checkbox"+@i.to_s,:class=>"sub_checkbox",:style=>"float:left;margin-left:1em;",:index=>@j}%>
|
||||||
|
<%else%>
|
||||||
|
<%=each_file.check_box file_name,{:checked=>false,:id=>"checkbox"+@i.to_s,:class=>"sub_checkbox",:style=>"float:left;margin-left:1em;",:index=>@j}%>
|
||||||
|
<%end%>
|
||||||
|
<% file_name = file_name.gsub("@",".") %>
|
||||||
|
<label for="<%="checkbox"+@i.to_s%>" class="sub_checklabel" style="float:left;"><%=file_name%></label>
|
||||||
|
<div style="clear:both;"></div>
|
||||||
|
<% @i = @i+1 %>
|
||||||
|
<% @j = @j+1 %>
|
||||||
|
<% end %>
|
||||||
|
<%end%>
|
||||||
|
<%end%>
|
||||||
|
</span>
|
||||||
<%end%>
|
<%end%>
|
||||||
</div>
|
</div>
|
||||||
<%end%>
|
<%end%>
|
||||||
<%=file.submit "#{t(:updatefont)}",{:id=>"updatebtn",:onclick=>"return updatefcn()"}%>
|
<%=file.submit "#{t(:updatefont)}",{:id=>"updatebtn",:onclick=>"return updatefcn()"}%>
|
||||||
<%=file.text_field :recovery_btn, {:id=>"hidden-recovery",:type => "hidden",:value=>"false"} %>
|
<%=file.text_field :recovery_btn, {:id=>"hidden-recovery",:type => "hidden",:value=>"false"} %>
|
||||||
|
<button id="seemessage" onclick="return seelogfcn()"><%=(I18n.locale.to_s =="zh_tw") ? "查看上次更新的logs" : "see logs of prev update "%></button>
|
||||||
<button id="recoverybtn" onclick="return recoveryfcn()"><%=(I18n.locale.to_s =="zh_tw") ? "復原到上次更新的檔案狀態" : "recovery to prev file status"%></button>
|
<button id="recoverybtn" onclick="return recoveryfcn()"><%=(I18n.locale.to_s =="zh_tw") ? "復原到上次更新的檔案狀態" : "recovery to prev file status"%></button>
|
||||||
<%end%>
|
<%end%>
|
||||||
<li id ="ckeditorFont" class="show_li">
|
<li id ="ckeditorFont" class="show_li">
|
||||||
|
@ -49,48 +70,65 @@
|
||||||
$('.Toggleclass').off("click").on("click",function(){
|
$('.Toggleclass').off("click").on("click",function(){
|
||||||
$(this).parent().find(">ul").slideToggle();
|
$(this).parent().find(">ul").slideToggle();
|
||||||
});
|
});
|
||||||
|
$('.checkbox').off('click').on('click',function(){
|
||||||
|
for(var i = 0;i<$(this).parent().find('.sub_checkbox').length;i++){
|
||||||
|
if($(this).is(":checked") == false){
|
||||||
|
if($(this).parent().find('.sub_checkbox').eq(i).is(":checked") == true)
|
||||||
|
$(this).parent().find('.sub_checkbox').eq(i).click();
|
||||||
|
}else{
|
||||||
|
if($(this).parent().find('.sub_checkbox').eq(i).is(":checked") == false)
|
||||||
|
$(this).parent().find('.sub_checkbox').eq(i).click();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
$('.sub_checkbox').off('click').on('click',function(){
|
||||||
|
var num = 0;
|
||||||
|
var index = 0;
|
||||||
|
for(var i = 0;i<$(this).parent().find('.sub_checkbox').length;i++){
|
||||||
|
if($(this).parent().find('.sub_checkbox').eq(i).is(":checked") == true){
|
||||||
|
num += 1;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
if( num == $(this).parent().find('.sub_checkbox').length){
|
||||||
|
if( $(this).parent().find('.checkbox').is(":checked") == false)
|
||||||
|
$(this).parent().find('.checkbox').click();
|
||||||
|
}else{
|
||||||
|
if( $(this).parent().find('.checkbox').is(":checked") == true){
|
||||||
|
$(this).parent().find('.checkbox').click();
|
||||||
|
for(var i = 0;i<$(this).parent().find('.sub_checkbox').length;i++){
|
||||||
|
if($(this).parent().find('.sub_checkbox').eq(i).attr('id') != $(this).attr('id'))
|
||||||
|
$(this).parent().find('.sub_checkbox').eq(i).click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
$("#clickall").off("click").on("click",function(){
|
$("#clickall").off("click").on("click",function(){
|
||||||
for(var i =0;i<$(".checkbox").length ; i++){
|
for(var i =0;i<$(".sub_checkbox").length ; i++){
|
||||||
if($(".checkbox").eq(i).is(":checked") == false)
|
if($(".checkbox").eq(i).is(":checked") == false)
|
||||||
$(".checklabel").eq(i).click();
|
$(".checkbox").eq(i).click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#unclickall").off("click").on("click",function(){
|
$("#unclickall").off("click").on("click",function(){
|
||||||
for(var i =0;i<$(".checkbox").length ; i++){
|
for(var i =0;i<$(".sub_checkbox").length ; i++){
|
||||||
if($(".checkbox").eq(i).is(":checked") == true)
|
if($(".checkbox").eq(i).is(":checked") == true)
|
||||||
$(".checklabel").eq(i).click();
|
$(".checkbox").eq(i).click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function updatefcn(){
|
function seelogfcn(){
|
||||||
var str="";
|
|
||||||
var num =1;
|
|
||||||
for(var i =0;i<$(".checkbox").length ; i++){
|
|
||||||
if($(".checkbox").eq(i).is(":checked") == true){
|
|
||||||
str += ("<i style='color:red;'>"+num+". "+$(".checklabel").eq(i).html()+"\n"+"</i>");
|
|
||||||
num += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($( "#dialog-confirm" ).length != 0)
|
if($( "#dialog-confirm" ).length != 0)
|
||||||
$( "#dialog-confirm" ).remove();
|
$( "#dialog-confirm" ).remove();
|
||||||
if(I18n.locale == "zh_tw"){
|
if(I18n.locale == "zh_tw"){
|
||||||
$('body').after("<div id='dialog-confirm' title='你確定要更新嗎?'>"+
|
$('body').after("<div id='dialog-confirm' title='上次更新的logs'></div>");
|
||||||
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+
|
|
||||||
"按下確認鍵後,你將更新你所選的檔案。\n"+str+"</p>"
|
|
||||||
+"</div>");
|
|
||||||
}else{
|
}else{
|
||||||
$('body').after("<div id='dialog-confirm' title='Are you sure to update?'>"+
|
$('body').after("<div id='dialog-confirm' title='logs of prev update?'></div>");
|
||||||
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+
|
};
|
||||||
"After click confirm button,you will update the selected file.\n"+str+"</p>"
|
$( "#dialog-confirm" ).append($.parseHTML("<%= @file_to_show.last_message.gsub("\"","\'").html_safe %>"));
|
||||||
+"</div>");
|
|
||||||
}
|
|
||||||
var flag = 0;
|
|
||||||
$( "#dialog-confirm" ).dialog({
|
$( "#dialog-confirm" ).dialog({
|
||||||
resizable: false,
|
resizable: true,
|
||||||
height:200,
|
height:200,
|
||||||
modal: true,
|
modal: true,
|
||||||
buttons: {
|
buttons: {
|
||||||
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
|
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
|
||||||
flag = 1;
|
|
||||||
$( this ).dialog( "close" );
|
$( this ).dialog( "close" );
|
||||||
},
|
},
|
||||||
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
|
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
|
||||||
|
@ -98,17 +136,52 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if( flag == 1)
|
return false;
|
||||||
return true;
|
};
|
||||||
else
|
function updatefcn(){
|
||||||
return false;
|
var str="";
|
||||||
|
var num =1;
|
||||||
|
for(var i =0;i<$(".sub_checkbox").length ; i++){
|
||||||
|
if($(".sub_checkbox").eq(i).is(":checked") == true){
|
||||||
|
str += ("</br><i style='color:red;'>"+num+". "+$(".sub_checklabel").eq(i).html()+"</i>");
|
||||||
|
num += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($( "#dialog-confirm" ).length != 0)
|
||||||
|
$( "#dialog-confirm" ).remove();
|
||||||
|
if(I18n.locale == "zh_tw"){
|
||||||
|
$('body').after("<div id='dialog-confirm' title='你確定要更新嗎?'>"+
|
||||||
|
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 0 0;'></span>"+
|
||||||
|
"按下確認鍵後,你將更新你所選的檔案。"+str+"</p>"
|
||||||
|
+"</div>");
|
||||||
|
}else{
|
||||||
|
$('body').after("<div id='dialog-confirm' title='Are you sure to update?'>"+
|
||||||
|
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 0 0;'></span>"+
|
||||||
|
"After click confirm button,you will update the selected file."+str+"</p>"
|
||||||
|
+"</div>");
|
||||||
|
};
|
||||||
|
$( "#dialog-confirm" ).dialog({
|
||||||
|
resizable: true,
|
||||||
|
height:200,
|
||||||
|
modal: true,
|
||||||
|
buttons: {
|
||||||
|
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
|
||||||
|
$( this ).dialog( "close" );
|
||||||
|
$('.edit_filefield').submit();
|
||||||
|
},
|
||||||
|
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
|
||||||
|
$( this ).dialog( "close" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
function recoveryfcn(){
|
function recoveryfcn(){
|
||||||
var str="";
|
var str="";
|
||||||
var num =1;
|
var num =1;
|
||||||
for(var i =0;i<$(".checkbox").length ; i++){
|
for(var i =0;i<$(".sub_checkbox").length ; i++){
|
||||||
if($(".checkbox").eq(i).is(":checked") == true){
|
if($(".sub_checkbox").eq(i).is(":checked") == true){
|
||||||
str += ("<i style='color:red;'>"+num+". "+$(".checklabel").eq(i).html()+"\n"+"</i>");
|
str += ("</br><i style='color:red;'>"+num+". "+$(".sub_checklabel").eq(i).html()+"</i>");
|
||||||
num += 1;
|
num += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,24 +189,24 @@
|
||||||
$( "#dialog-confirm" ).remove();
|
$( "#dialog-confirm" ).remove();
|
||||||
if(I18n.locale == "zh_tw"){
|
if(I18n.locale == "zh_tw"){
|
||||||
$('body').after("<div id='dialog-confirm' title='你確定要還原嗎?'>"+
|
$('body').after("<div id='dialog-confirm' title='你確定要還原嗎?'>"+
|
||||||
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+
|
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 0 0;'></span>"+
|
||||||
"按下確認鍵後,你將還原你所選的檔案。\n"+str+"</p>"
|
"按下確認鍵後,你將還原你所選的檔案。"+str+"</p>"
|
||||||
+"</div>");
|
+"</div>");
|
||||||
}else{
|
}else{
|
||||||
$('body').after("<div id='dialog-confirm' title='Are you sure to recover?'>"+
|
$('body').after("<div id='dialog-confirm' title='Are you sure to recover?'>"+
|
||||||
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+
|
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 0 0;'></span>"+
|
||||||
"After click confirm button,you will recover the selected file.\n"+str+"</p>"
|
"After click confirm button,you will recover the selected file."+str+"</p>"
|
||||||
+"</div>");
|
+"</div>");
|
||||||
}
|
}
|
||||||
$( "#dialog-confirm" ).dialog({
|
$( "#dialog-confirm" ).dialog({
|
||||||
resizable: false,
|
resizable: true,
|
||||||
height:200,
|
height:200,
|
||||||
modal: true,
|
modal: true,
|
||||||
buttons: {
|
buttons: {
|
||||||
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
|
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
|
||||||
$('#hidden-recovery').val("true");
|
$('#hidden-recovery').val("true");
|
||||||
$('#updatebtn').click();
|
|
||||||
$( this ).dialog( "close" );
|
$( this ).dialog( "close" );
|
||||||
|
$('.edit_filefield').submit();
|
||||||
},
|
},
|
||||||
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
|
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
|
||||||
$('#hidden-recovery').val("false");
|
$('#hidden-recovery').val("false");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
在 目前專案/app/assets/stylesheets/lib中插入jquery-ui-12.1資料夾
|
在 目前專案/app/assets/stylesheets/lib中插入jquery-ui-12.1資料夾
|
||||||
在 目前專案/app/views/layouts/back_end.html.erb和
|
在 目前專案/app/views/layouts/back_end.html.erb和
|
||||||
目前專案/app/views/page_parts_form.html.erb中插入以下內容
|
目前專案/app/views/page_parts/_form.html.erb中插入以下內容
|
||||||
<script src="/assets/lib/jquery-ui-1.12.1/jquery-ui.min.js"></script>
|
<script src="/assets/lib/jquery-ui-1.12.1/jquery-ui.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
/* 修正bootstap.js和jquery-ui.js間的衝突,使tab按鈕能正常運作 */
|
/* 修正bootstap.js和jquery-ui.js間的衝突,使tab按鈕能正常運作 */
|
||||||
|
|
Loading…
Reference in New Issue