Skip to content

Commit

Permalink
Now we can delete a translation of a record
Browse files Browse the repository at this point in the history
- Add delete_translation button to form_actions
- Add crud method `delete_translation`
- Add `delete_translation` :post route in engines images, pages and
resources
- Add delete_translation locales
- Fix CSS
  • Loading branch information
Brice Sanchez committed Jul 17, 2017
1 parent ffce888 commit f754f0b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
2 changes: 0 additions & 2 deletions core/app/assets/stylesheets/refinery/sections/_layout.scss
Expand Up @@ -1287,8 +1287,6 @@ input.button.close_dialog:active, a.button.close_dialog:active, #content a.butto
}
.form-actions a.confirm-delete, #content .form-actions a.confirm-delete {
background: #ee1100;
position: absolute;
right: 0px;
}
.form-actions a.confirm-delete:hover, #content .form-actions a.confirm-delete:hover {
background: #ff3322;
Expand Down
20 changes: 20 additions & 0 deletions core/app/views/refinery/admin/_form_actions.html.erb
Expand Up @@ -24,6 +24,11 @@
(f.object.respond_to?(:deletable?) && !f.object.deletable?))
end

if !defined?(hide_delete_translation).presence
hide_delete_translation = hide_delete ||
(Refinery::I18n.frontend_locales.many? && !f.object.translations.many?)
end

unless hide_delete
delete_button_text ||= t('.delete')
delete_title ||= nil
Expand All @@ -32,6 +37,15 @@
# we have to use eval rather than refinery.send because this url may not exist for HTTP GET
delete_url ||= eval("refinery.#{Refinery.route_for_model(f.object.class)}(#{f.object.id})")
end

unless hide_delete_translation
delete_translation_button_text ||= t('.delete_translation')
delete_translation_title ||= nil
delete_translation_confirmation ||= nil
delete_translation_button_id ||= "delete_translation_button"
# we have to use eval rather than refinery.send because this url may not exist for HTTP GET
delete_translation_url ||= eval("refinery.delete_translation_#{Refinery.route_for_model(f.object.class)}(#{f.object.id}, locale_to_delete: :#{Globalize.locale})")
end
-%>
<% if from_dialog? %>
<input type='hidden' name='modal' value='true' />
Expand Down Expand Up @@ -61,6 +75,12 @@
</div>
<div class='form-actions-right'>
<%= local_assigns[:before_delete_button] -%>
<%= link_to(delete_translation_button_text, delete_translation_url,
method: :post,
data: {
confirm: delete_translation_confirmation
},
class: "button confirm-delete") unless hide_delete_translation %>
<%= link_to(delete_button_text, delete_url,
:title => delete_title,
:id => delete_button_id,
Expand Down
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Expand Up @@ -16,6 +16,7 @@ en:
created: '%{what} was successfully added.'
updated: '%{what} was successfully updated.'
destroyed: '%{what} was successfully removed.'
delete_translation_success: "%{what} page's translation was successfully removed."
site_bar:
log_out: Log out
switch_to_your_website: Switch to your website
Expand All @@ -35,6 +36,7 @@ en:
cancel: Cancel
cancel_lose_changes: If you cancel you will lose any changes you have made here
delete: Remove
delete_translation: Remove this translation
close: Close
image_picker:
none_selected: No image selected, please click here to add one.
Expand Down
8 changes: 8 additions & 0 deletions core/lib/refinery/crud.rb
Expand Up @@ -107,6 +107,14 @@ def destroy
redirect_to redirect_url
end
def delete_translation
find_#{singular_name}
record = @#{singular_name}.translations.find_by_locale(params[:locale_to_delete])
record.destroy
flash[:notice] = t('delete_translation_success', scope: 'refinery.crudify', what: "'\#{record.#{options[:title_attribute]}}'")
redirect_to redirect_url
end
# Finds one single result based on the id params.
def find_#{singular_name}
@#{singular_name} = find_#{singular_name}_scope.find(params[:id])
Expand Down
12 changes: 8 additions & 4 deletions images/config/routes.rb
@@ -1,9 +1,13 @@
Refinery::Core::Engine.routes.draw do
get '/system/images/*dragonfly', :to => Dragonfly.app(:refinery_images)
get '/system/images/*dragonfly', to: Dragonfly.app(:refinery_images)

namespace :admin, :path => Refinery::Core.backend_route do
resources :images, :except => :show do
get :insert, :on => :collection
namespace :admin, path: Refinery::Core.backend_route do
resources :images, except: :show do
get :insert, on: :collection

member do
post :delete_translation
end
end
end
end
4 changes: 4 additions & 0 deletions pages/config/routes.rb
Expand Up @@ -19,6 +19,10 @@

resources :pages, except: :show do
post :update_positions, on: :collection

member do
post :delete_translation
end
end

resources :pages_dialogs, only: [] do
Expand Down
12 changes: 8 additions & 4 deletions resources/config/routes.rb
@@ -1,9 +1,13 @@
Refinery::Core::Engine.routes.draw do
get '/system/resources/*dragonfly', :to => Dragonfly.app(:refinery_resources)
get '/system/resources/*dragonfly', to: Dragonfly.app(:refinery_resources)

namespace :admin, :path => Refinery::Core.backend_route do
resources :resources, :except => :show do
get :insert, :on => :collection
namespace :admin, path: Refinery::Core.backend_route do
resources :resources, except: :show do
get :insert, on: :collection

member do
post :delete_translation
end
end
end
end

0 comments on commit f754f0b

Please sign in to comment.