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
if params["filefield"]["recovery_btn"] == "true"
@file_to_show.recovery = "true"
@file_to_show.update @file_to_show.update
redirect_to admin_patchfiles_path 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,6 +33,69 @@ class Filefield
return dir_str return dir_str
end end
def updatefile def updatefile
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| self.file_show.each do |key,value|
if value == 1 if value == 1
@model_path = Rails.root.to_s + '/app/models/' @model_path = Rails.root.to_s + '/app/models/'
@ -129,7 +192,7 @@ class Filefield
begin begin
FileUtils.cp('back_end.html.erb' , @views_path+'layouts/') FileUtils.cp('back_end.html.erb' , @views_path+'layouts/')
FileUtils.cp('_form.html.erb' , @views_path+'page_parts/') 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/') FileUtils.cp_r('jquery-ui-1.12.1/' ,Rails.root.to_s + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/')
rescue rescue
puts Dir.pwd puts Dir.pwd
Dir.chdir(Rails.root.to_s) Dir.chdir(Rails.root.to_s)
@ -141,5 +204,6 @@ class Filefield
end end
end 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){
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"); $("#hidden-delete").val("true");
$("#submitbtn").click(); $("#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>