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] @key = @file_to_show.file_show.keys[index]
@file_to_show.file_show[@key] = value.to_i @file_to_show.file_show[@key] = value.to_i
end end
@file_to_show.update if params["filefield"]["recovery_btn"] == "true"
redirect_to admin_patchfiles_path @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 end
def showckeditor def showckeditor
end end

View File

@ -33,111 +33,175 @@ class Filefield
return dir_str return dir_str
end end
def updatefile def updatefile
self.file_show.each do |key,value| if self.recovery == "true"
if value == 1 self.file_show.each do |key,value|
@model_path = Rails.root.to_s + '/app/models/' if value == 1
@helper_path = Rails.root.to_s + '/app/helpers/' @model_path = Rails.root.to_s + '/app/models/'
@views_path = Rails.root.to_s + '/app/views/' @helper_path = Rails.root.to_s + '/app/helpers/'
@controller_path = Rails.root.to_s + '/app/controllers/' @views_path = Rails.root.to_s + '/app/views/'
if key == "ckeditor" @controller_path = Rails.root.to_s + '/app/controllers/'
@app_path = File.expand_path(__dir__) if key == "ckeditor"
@app_path = lastpath(@app_path) @ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
@app_path = lastpath(@app_path) puts 'recovery CKEDITOR'
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/' begin
puts 'copying CKEDITOR' FileUtils.cd(@ckeditor_path)
begin FileUtils.cp('config.js.erb_back' , 'config.js.erb')
Dir.chdir(@ckeditor_path) rescue
File.rename('config.js.erb','config.js.erb_back') puts Dir.pwd
rescue puts 'error recovery'
puts Dir.pwd end
end elsif key == "site-preference(two-site-logo)"
FileUtils.cd(@app_path+'/updatefiles/') puts 'recovery site'
begin begin
FileUtils.cp('config.js.erb' , @ckeditor_path) FileUtils.cd(@model_path)
puts @ckeditor_path FileUtils.cp('site.rb_back' , 'site.rb')
rescue FileUtils.cd(@helper_path)
puts Dir.pwd FileUtils.cp('application_helper.rb_back' , 'application_helper.rb')
puts 'error copy' FileUtils.cd(@views_path+'admin/sites/')
end FileUtils.cp('preference.html.erb_back','preference.html.erb')
elsif key == "site-preference(two-site-logo)" rescue
@app_path = File.expand_path(__dir__) puts Dir.pwd
@app_path = lastpath(@app_path) Dir.chdir(Rails.root.to_s)
@app_path = lastpath(@app_path) puts 'error recovery'
puts @app_path end
puts 'copying site' elsif key == "member"
begin puts 'recovery member'
Dir.chdir(@model_path) begin
File.rename('site.rb','site.rb_back') FileUtils.cd(@model_path)
Dir.chdir(@helper_path) FileUtils.cp('member_profile.rb_back' , 'member_profile.rb')
File.rename('application_helper.rb','application_helper.rb_back') FileUtils.cd(@controller_path+'admin/')
Dir.chdir(@views_path+'admin/sites/') FileUtils.cp('members_controller.rb_back' , 'members_controller.rb')
File.rename('preference.html.erb','preference.html.erb_back') FileUtils.cd(@views_path+'admin/members/')
rescue FileUtils.cp('_user_basic_passwd.html.erb_back' , '_user_basic_passwd.html.erb')
puts Dir.pwd rescue
end puts Dir.pwd
FileUtils.cd(@app_path+'/updatefiles/') Dir.chdir(Rails.root.to_s)
begin puts 'error recovery'
FileUtils.cp('site.rb' , @model_path) end
FileUtils.cp('application_helper.rb' , @helper_path) elsif key == "accessibility"
FileUtils.cd('admin/') puts 'recovery accessibility'
FileUtils.cp('preference.html.erb',@views_path+'admin/sites/') begin
rescue FileUtils.cd(@views_path+'layouts/')
puts Dir.pwd FileUtils.cp('back_end.html.erb_back' , 'back_end.html.erb')
Dir.chdir(Rails.root.to_s) FileUtils.cd(@views_path+'page_parts/')
puts 'error copy' FileUtils.cp('_form.html.erb_back' , '_form.html.erb')
end rescue
elsif key == "member" puts Dir.pwd
@app_path = File.expand_path(__dir__) Dir.chdir(Rails.root.to_s)
@app_path = lastpath(@app_path) puts 'error recovery'
@app_path = lastpath(@app_path) end
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'
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
Dir.chdir(Rails.root.to_s)
FileUtils.cd(Rails.root.to_s)
end end
end end
end end

View File

@ -9,11 +9,11 @@
<% for @i in @arr %> <% for @i in @arr %>
<div style="float:left;"> <div style="float:left;">
<% if @field.font_array[@i.to_s] == true%> <% 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 %> <% 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 %> <% 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> </div>
<%end%> <%end%>
<%end%> <%end%>
@ -21,9 +21,9 @@
<div style="clear:both;"></div> <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> <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"}%> <%=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"} %> <%=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"} %> <%=f.text_field :delete_btn, {:id=>"hidden-delete",:type => "hidden",:value=>"false"} %>
<%end%> <%end%>
<li id ="ckeditorFont" class="show_li"> <li id ="ckeditorFont" class="show_li">
@ -51,24 +51,89 @@
} }
</style> </style>
<script> <script>
$("#initialbtn").off("click").on("click",function(){ function deletefcn(){
$("#hidden-initial").val("true"); var str="";
$("#submitbtn").click(); var num =1;
}); for(var i =0;i<$(".checkbox").length ; i++){
$("#deletebtn").off("click").on("click",function(){ if($(".checkbox").eq(i).is(":checked") == true){
$("#hidden-delete").val("true"); str += ("<i style='color:red;'>"+num+". "+$(".checklabel").eq(i).html()+"\n"+"</i>");
$("#submitbtn").click(); 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(){ $("#clickall").off("click").on("click",function(){
for(var i =0;i<$(".allcheckbox input").length ; i++){ for(var i =0;i<$(".checkbox").length ; i++){
if($(".allcheckbox input").eq(i).is(":checked") == false) if($(".checkbox").eq(i).is(":checked") == false)
$(".allcheckbox input").eq(i).click(); $(".checklabel").eq(i).click();
} }
}); });
$("#unclickall").off("click").on("click",function(){ $("#unclickall").off("click").on("click",function(){
for(var i =0;i<$(".allcheckbox input").length ; i++){ for(var i =0;i<$(".checkbox").length ; i++){
if($(".allcheckbox input").eq(i).is(":checked") == true) if($(".checkbox").eq(i).is(":checked") == true)
$(".allcheckbox input").eq(i).click(); $(".checklabel").eq(i).click();
} }
}); });
$('.Toggleclass').off("click").on("click",function(){ $('.Toggleclass').off("click").on("click",function(){

View File

@ -1,20 +1,25 @@
<div style="clear:both;"></div> <div style="clear:both;"></div>
<% @i = 0 %> <% @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|%> <%=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">
<% @file_to_show.file_show.each do |show| %> <% @file_to_show.file_show.each do |show| %>
<%if show[1] == 1%> <%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%> <%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%> <%end%>
<label for="<%="checkbox"+@i.to_s%>" class="checklabel" style="float:left;"><%=show[0]%></label>
<% @i = @i+1 %> <% @i = @i+1 %>
<%=show[0]%>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<%end%> <%end%>
</div>
<%end%> <%end%>
<%=file.submit "#{t(:updatefont)}"%> <%=file.submit "#{t(:updatefont)}",{:id=>"updatebtn",:onclick=>"return updatefcn()"}%>
<button><%=(I18n.locale.to_s =="zh_tw") ? "復原到上次更新的檔案狀態" : "recovery to prev file status"%></button> <%=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%> <%end%>
<li id ="ckeditorFont" class="show_li"> <li id ="ckeditorFont" class="show_li">
<a title="CKEDITOR現有字形">CKEDITOR現有字形</a> <a title="CKEDITOR現有字形">CKEDITOR現有字形</a>
@ -44,4 +49,98 @@
$('.Toggleclass').off("click").on("click",function(){ $('.Toggleclass').off("click").on("click",function(){
$(this).parent().find(">ul").slideToggle(); $(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> </script>