Skip to content

Commit

Permalink
Merge pull request #25 from bys-control/master
Browse files Browse the repository at this point in the history
Add I18n
  • Loading branch information
Fivell authored Jul 17, 2017
2 parents 3191e5e + 92611b2 commit 77f1dac
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
11 changes: 11 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
en:
active_admin_scoped_collection_actions:
sidebar_msg: 'This batch operations affect selected records. Or if none is selected, it will involve all records by current filters and scopes.'
confirm_action_message: 'Are you sure?'
actions:
delete: 'Delete batch'
update: 'Update batch'
no_permissions_msg: 'Access denied'
batch_update_status_msg: 'Batch update done'
batch_destroy_status_msg: 'Batch destroy done'
fail_on_destroy_msg: 'Cant be destroyed'
11 changes: 11 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
es:
active_admin_scoped_collection_actions:
sidebar_msg: 'Estas operaciones afectan las filas seleccionadas o en caso que no halla seleccionado ninguna, afectará a todo los registros afectados por los filtros aplicados.'
confirm_action_message: '¿Está seguro que quiere realizar esta acción?'
actions:
delete: 'Batch Borrado'
update: 'Batch Actualizado'
no_permissions_msg: 'Permiso denegado'
batch_update_status_msg: 'Batch actualizado correctamente'
batch_destroy_status_msg: 'Batch destruido correctamente'
fail_on_destroy_msg: 'No se puede eliminar'
17 changes: 10 additions & 7 deletions lib/active_admin_scoped_collection_actions/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module DSL

def scoped_collection_action(name, options = {}, &block)
if name == :scoped_collection_destroy
options[:title] = 'Delete batch' if options[:title].nil?



options[:title] = I18n.t('active_admin_scoped_collection_actions.actions.delete') if options[:title].nil?
add_scoped_collection_action_default_destroy(options, &block)
elsif name == :scoped_collection_update
options[:title] = 'Update batch' if options[:title].nil?
options[:title] = I18n.t('active_admin_scoped_collection_actions.actions.update') if options[:title].nil?
add_scoped_collection_action_default_update(options, &block)
else
batch_action(name, if: proc { false }, &block)
Expand All @@ -19,7 +22,7 @@ def scoped_collection_action(name, options = {}, &block)
def add_scoped_collection_action_default_update(options, &block)
batch_action :scoped_collection_update, if: proc { false } do
unless authorized?(:batch_edit, resource_class)
flash[:error] = 'Access denied'
flash[:error] = I18n.t('active_admin_scoped_collection_actions.actions.no_permissions_msg')
render nothing: true, status: :no_content and next
end
if !params.has_key?(:changes) || params[:changes].empty?
Expand All @@ -36,7 +39,7 @@ def add_scoped_collection_action_default_update(options, &block)
end
end
if errors.empty?
flash[:notice] = 'Batch update done'
flash[:notice] = I18n.t('active_admin_scoped_collection_actions.batch_update_status_msg')
else
flash[:error] = errors.join(". ")
end
Expand All @@ -49,7 +52,7 @@ def add_scoped_collection_action_default_update(options, &block)
def add_scoped_collection_action_default_destroy(_, &block)
batch_action :scoped_collection_destroy, if: proc { false } do |_|
unless authorized?(:batch_destroy, resource_class)
flash[:error] = 'Access denied'
flash[:error] = I18n.t('active_admin_scoped_collection_actions.actions.no_permissions_msg')
render nothing: true, status: :no_content and next
end
if block_given?
Expand All @@ -58,11 +61,11 @@ def add_scoped_collection_action_default_destroy(_, &block)
errors = []
scoped_collection_records.find_each do |record|
unless destroy_resource(record)
errors << "#{record.attributes[resource_class.primary_key]} | Cant be destroyed}"
errors << "#{record.attributes[resource_class.primary_key]} | #{I18n.t('active_admin_scoped_collection_actions.fail_on_destroy_msg')}}"
end
end
if errors.empty?
flash[:notice] = 'Batch destroy done'
flash[:notice] = I18n.t('active_admin_scoped_collection_actions.batch_destroy_status_msg')
else
flash[:error] = errors.join(". ")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def scoped_collection_sidebar_condition
def scoped_collection_actions_sidebar_section
ActiveAdmin::SidebarSection.new :collection_actions, only: :index, if: scoped_collection_sidebar_condition do

div 'This batch operations affect selected records. Or if none is selected, it will involve all records by current filters and scopes.'
div I18n.t('active_admin_scoped_collection_actions.sidebar_msg')

active_admin_config.scoped_collection_actions.each do |key, options={}|
b_title = options.fetch(:title, ::ActiveSupport::Inflector.humanize(key))
Expand All @@ -64,7 +64,7 @@ def scoped_collection_actions_sidebar_section
if options[:form].present?
b_data[:inputs] = options[:form].is_a?(Proc) ? options[:form].call : options[:form]
end
b_data[:confirm] = options.fetch(:confirm, 'Are you sure?')
b_data[:confirm] = options.fetch(:confirm, I18n.t('active_admin_scoped_collection_actions.confirm_action_message'))
b_options[:data] = b_data.to_json
button b_title, b_options
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin_scoped_collection_actions/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveAdminScopedCollectionActions
VERSION = "0.3.0"
VERSION = "0.3.2"
end

0 comments on commit 77f1dac

Please sign in to comment.