From cf2d6f29d68fc92c20ab4c6fe010d7974861a7ff Mon Sep 17 00:00:00 2001 From: bohung Date: Fri, 19 Feb 2021 19:37:07 +0800 Subject: [PATCH] Add confirm delete text to ensure no mistakenly deleted. --- .../admin/site_panel_controller.rb | 5 +-- .../site_panel/_sites_list_table.html.erb | 43 +++++++++++++++++-- config/locales/en.yml | 5 ++- config/locales/zh_tw.yml | 5 ++- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index d45627d..1e6339a 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -132,11 +132,8 @@ class Admin::SitePanelController < OrbitAdminController @site = SiteConstruct.find(params[:id]) render 'see_detail_for_created_site' and return elsif params[:type] == 'change_server_name' - SiteConstruct.find(params[:id]).update_attributes(domain_name: params[:site_construct][:domain_name]) cmd = "bundle exec rake create_site:change_site_server_name[#{params[:id]},'#{params[:site_construct][:domain_name]}']" - Thread.new do - system(cmd) - end + system(cmd) redirect_to :back and return elsif params[:type] == 'delete_from_list' SiteConstruct.find(params[:id]).destroy diff --git a/app/views/admin/site_panel/_sites_list_table.html.erb b/app/views/admin/site_panel/_sites_list_table.html.erb index 75d950a..e0c9e0c 100644 --- a/app/views/admin/site_panel/_sites_list_table.html.erb +++ b/app/views/admin/site_panel/_sites_list_table.html.erb @@ -144,9 +144,46 @@ var item = this; if(window.confirm("Do you really want to delete this site?")){ if(window.confirm("Do you really want to delete this site?")){ - $.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'delete'}).done(function(){ - show_infos_dialog(item); - item.remove(); + if($("#dialog-confirm").length == 0){ + $("#main-wrap").before("
"+ + "
"+"Do you really want to "+$(this).attr('title')+"?
"+"\" style=\"width: 17em;\">"+"
"+ + "
"); + }else{ + $("#info_texts").html("Do you really want to "+$(this).attr('title')+"."); + $('#confirm_input').css('display','block'); + $('#confirm_input').val(''); + } + $( "#dialog-confirm" ).dialog({ + resizable: true, + minHeight: 200, + maxHeight: 400, + modal: true, + width: '80%', + open: function(){ + $('#confirm_input').blur(); + }, + close: function(){ + $('#confirm_input').css('display','none'); + $( this ).dialog( "close" ); + }, + buttons: { + "<%= t('client_management.confirm') %>": function(){ + if($('#confirm_input').val().match(/<%= t('client_management.confirm_delete') %>/gi)){ + $('#confirm_input').css('display','none'); + $.post("<%=admin_site_panel_edit_site_path%>",{'id':$(item).attr("data-id"),'type':'delete'}).done(function(data){ + show_infos_dialog(item); + item.remove(); + }); + }else{ + alert("<%= t('client_management.please_input_confirm_delete').html_safe %>"); + $('#confirm_input').focus(); + } + }, + "<%= t('client_management.cancel') %>": function(){ + $('#confirm_input').css('display','none'); + $( this ).dialog( "close" ); + } + } }); } } diff --git a/config/locales/en.yml b/config/locales/en.yml index dd51bbd..653fd8a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -58,4 +58,7 @@ en: create_site: Create Site sites_list: Site list server_manager: Server Manager - confirm: Confirm \ No newline at end of file + confirm: Confirm + cancel: Cancel + please_input_confirm_delete: "Please input 'Confirm delete' to here." + confirm_delete: Confirm delete \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a637a5b..db96df6 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -58,4 +58,7 @@ zh_tw: create_site: Create Site sites_list: Site list server_manager: Server Manager - confirm: Confirm \ No newline at end of file + confirm: Confirm + cancel: Cancel + please_input_confirm_delete: "請輸入'確認刪除'。" + confirm_delete: 確認刪除 \ No newline at end of file