add confirm box and recover file feature

This commit is contained in:
BOHUNG 2019-09-30 08:35:34 +08:00
parent 67ec45d3d0
commit 2695e0ff67
4 changed files with 363 additions and 129 deletions

View File

@ -24,8 +24,14 @@ class Admin::PatchfilesController < OrbitAdminController
@key = @file_to_show.file_show.keys[index]
@file_to_show.file_show[@key] = value.to_i
end
@file_to_show.update
redirect_to admin_patchfiles_path
if params["filefield"]["recovery_btn"] == "true"
@file_to_show.recovery = "true"
@file_to_show.update
redirect_to admin_patchfiles_path and return
else
@file_to_show.update
redirect_to admin_patchfiles_path and return
end
end
def showckeditor
end

View File

@ -33,111 +33,175 @@ class Filefield
return dir_str
end
def updatefile
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/' , ENV['PWD'] + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/')
rescue
puts Dir.pwd
Dir.chdir(Rails.root.to_s)
puts 'error copy'
if self.recovery == "true"
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"
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
puts 'recovery CKEDITOR'
begin
FileUtils.cd(@ckeditor_path)
FileUtils.cp('config.js.erb_back' , 'config.js.erb')
rescue
puts Dir.pwd
puts 'error recovery'
end
elsif key == "site-preference(two-site-logo)"
puts 'recovery site'
begin
FileUtils.cd(@model_path)
FileUtils.cp('site.rb_back' , 'site.rb')
FileUtils.cd(@helper_path)
FileUtils.cp('application_helper.rb_back' , 'application_helper.rb')
FileUtils.cd(@views_path+'admin/sites/')
FileUtils.cp('preference.html.erb_back','preference.html.erb')
rescue
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
Dir.chdir(Rails.root.to_s)
FileUtils.cd(Rails.root.to_s)
end
end
end

View File

@ -9,11 +9,11 @@
<% for @i in @arr %>
<div style="float:left;">
<% if @field.font_array[@i.to_s] == true%>
<%=fontfield.check_box @i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<%=fontfield.check_box @i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;",:class=>"checkbox"} %>
<% else %>
<%=fontfield.check_box @i.to_s,{:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<%=fontfield.check_box @i.to_s,{:id=>"checkbox"+@i.to_s,:style=>"float:left;",:class=>"checkbox"} %>
<% end %>
<%=fontfield.label @i.to_s ,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%>
<%=fontfield.label @i.to_s ,{:for=>"checkbox"+@i.to_s,:style=>"float:right;",:class=>"checklabel"}%>
</div>
<%end%>
<%end%>
@ -21,9 +21,9 @@
<div style="clear:both;"></div>
<div style="padding-left:1em"><label for="newfont" style="float:left;"><%=t(:newfont)%>:</label><%=f.text_field :new_add_font,{:id=>"newfont",:placeholder=>t(:newfont)}%></div>
<%=f.submit "#{t(:updatefont)}",{:id=>"submitbtn"}%>
<button id="initialbtn"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來恢復初始狀態" : "click to recovery initial state" %></button>
<button id="initialbtn" onclick="return initialfcn()"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來恢復初始狀態" : "click to recovery initial state" %></button>
<%=f.text_field :initial_btn, {:id=>"hidden-initial",:type => "hidden",:value=>"false"} %>
<button id="deletebtn"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來刪除所選字形" : "click to delete selected font" %></button>
<button id="deletebtn" onclick="return deletefcn()"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來刪除所選字形" : "click to delete selected font" %></button>
<%=f.text_field :delete_btn, {:id=>"hidden-delete",:type => "hidden",:value=>"false"} %>
<%end%>
<li id ="ckeditorFont" class="show_li">
@ -51,24 +51,89 @@
}
</style>
<script>
$("#initialbtn").off("click").on("click",function(){
$("#hidden-initial").val("true");
$("#submitbtn").click();
});
$("#deletebtn").off("click").on("click",function(){
$("#hidden-delete").val("true");
$("#submitbtn").click();
});
function deletefcn(){
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)
$( "#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 20px 0;'></span>"+
"按下確認鍵後,你將刪除你所選的字形。\n"+str+"</p>"
+"</div>");
}else{
$('body').after("<div id='dialog-confirm' title='Are you sure to delete'>"+
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+
"After click confirm button,you will delete the selected font.\n"+str+"</p>"
+"</div>");
}
var flag = 0;
$( "#dialog-confirm" ).dialog({
resizable: false,
height:200,
modal: true,
buttons: {
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
$("#hidden-delete").val("true");
$("#submitbtn").click();
$( this ).dialog( "close" );
},
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
$("#hidden-delete").val("false");
$( this ).dialog( "close" );
}
}
});
return false;
};
function initialfcn(){
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 20px 0;'></span>"+
"按下確認鍵後,你將初始化字形的列表和所擁有的字形。\n</p>"
+"</div>");
}else{
$('body').after("<div id='dialog-confirm' title='Are you sure to initialize'>"+
"<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+
"After click confirm button,you will initialize the font list and the fonts you have.\n</p>"
+"</div>");
}
$( "#dialog-confirm" ).dialog({
resizable: false,
height:200,
modal: true,
buttons: {
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
$("#hidden-initial").val("true");
$('#submitbtn').click();
$( this ).dialog( "close" );
},
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
$("#hidden-initial").val("false");
$( this ).dialog( "close" );
}
}
});
return false;
};
$("#clickall").off("click").on("click",function(){
for(var i =0;i<$(".allcheckbox input").length ; i++){
if($(".allcheckbox input").eq(i).is(":checked") == false)
$(".allcheckbox input").eq(i).click();
for(var i =0;i<$(".checkbox").length ; i++){
if($(".checkbox").eq(i).is(":checked") == false)
$(".checklabel").eq(i).click();
}
});
$("#unclickall").off("click").on("click",function(){
for(var i =0;i<$(".allcheckbox input").length ; i++){
if($(".allcheckbox input").eq(i).is(":checked") == true)
$(".allcheckbox input").eq(i).click();
for(var i =0;i<$(".checkbox").length ; i++){
if($(".checkbox").eq(i).is(":checked") == true)
$(".checklabel").eq(i).click();
}
});
$('.Toggleclass').off("click").on("click",function(){

View File

@ -1,20 +1,25 @@
<div style="clear:both;"></div>
<% @i = 0 %>
<button id="clickall"><%= (I18n.locale.to_s == "zh_tw") ? "全選" : "select all" %></button>
<button id="unclickall"><%= (I18n.locale.to_s == "zh_tw") ? "取消全選" : "unselect all" %></button>
<%=form_for @file_to_show ,:url=>{:controller=>"patchfiles" ,:action=>"edit"} do |file|%>
<%= file.fields_for :file_show do |filefield|%>
<div id="fileform">
<% @file_to_show.file_show.each do |show| %>
<%if show[1] == 1%>
<%=filefield.check_box "file_show"+@i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"}%>
<%=filefield.check_box "file_show"+@i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:class=>"checkbox",:style=>"float:left;"}%>
<%else%>
<%=filefield.check_box "file_show"+@i.to_s,{:checked=>false,:id=>"checkbox"+@i.to_s,:style=>"float:left;"}%>
<%=filefield.check_box "file_show"+@i.to_s,{:checked=>false,:id=>"checkbox"+@i.to_s,:class=>"checkbox",:style=>"float:left;"}%>
<%end%>
<label for="<%="checkbox"+@i.to_s%>" class="checklabel" style="float:left;"><%=show[0]%></label>
<% @i = @i+1 %>
<%=show[0]%>
<div style="clear:both;"></div>
<%end%>
</div>
<%end%>
<%=file.submit "#{t(:updatefont)}"%>
<button><%=(I18n.locale.to_s =="zh_tw") ? "復原到上次更新的檔案狀態" : "recovery to prev file status"%></button>
<%=file.submit "#{t(:updatefont)}",{:id=>"updatebtn",:onclick=>"return updatefcn()"}%>
<%=file.text_field :recovery_btn, {:id=>"hidden-recovery",:type => "hidden",:value=>"false"} %>
<button id="recoverybtn" onclick="return recoveryfcn()"><%=(I18n.locale.to_s =="zh_tw") ? "復原到上次更新的檔案狀態" : "recovery to prev file status"%></button>
<%end%>
<li id ="ckeditorFont" class="show_li">
<a title="CKEDITOR現有字形">CKEDITOR現有字形</a>
@ -44,4 +49,98 @@
$('.Toggleclass').off("click").on("click",function(){
$(this).parent().find(">ul").slideToggle();
});
$("#clickall").off("click").on("click",function(){
for(var i =0;i<$(".checkbox").length ; i++){
if($(".checkbox").eq(i).is(":checked") == false)
$(".checklabel").eq(i).click();
}
});
$("#unclickall").off("click").on("click",function(){
for(var i =0;i<$(".checkbox").length ; i++){
if($(".checkbox").eq(i).is(":checked") == true)
$(".checklabel").eq(i).click();
}
});
function updatefcn(){
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)
$( "#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 20px 0;'></span>"+
"按下確認鍵後,你將更新你所選的檔案。\n"+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 20px 0;'></span>"+
"After click confirm button,you will update the selected file.\n"+str+"</p>"
+"</div>");
}
var flag = 0;
$( "#dialog-confirm" ).dialog({
resizable: false,
height:200,
modal: true,
buttons: {
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
flag = 1;
$( this ).dialog( "close" );
},
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
$( this ).dialog( "close" );
}
}
});
if( flag == 1)
return true;
else
return false;
};
function recoveryfcn(){
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)
$( "#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 20px 0;'></span>"+
"按下確認鍵後,你將還原你所選的檔案。\n"+str+"</p>"
+"</div>");
}else{
$('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>"+
"After click confirm button,you will recover the selected file.\n"+str+"</p>"
+"</div>");
}
$( "#dialog-confirm" ).dialog({
resizable: false,
height:200,
modal: true,
buttons: {
<%=(I18n.locale == "zh_tw") ? "確認" : "confirm"%>: function(){
$('#hidden-recovery').val("true");
$('#updatebtn').click();
$( this ).dialog( "close" );
},
<%=(I18n.locale == "zh_tw") ? "取消" : "Cancel"%>: function() {
$('#hidden-recovery').val("false");
$( this ).dialog( "close" );
}
}
});
return false;
};
</script>