app/controllers/admin/base_controller.rb in ab_admin-0.3.5 vs app/controllers/admin/base_controller.rb in ab_admin-0.3.6
- old
+ new
@@ -91,10 +91,14 @@
resource_class.batch_actions.include?(batch_action)
end
protected
+ def default_url_options
+ {format: nil}
+ end
+
def batch_action_list
self.class.batch_action_list ||= begin
resource_class.batch_actions.map do |a|
opts = a == :destroy ? {confirm: I18n.t('admin.delete_confirmation')} : {}
AbAdmin::Config::BatchAction.new(a, opts)
@@ -104,10 +108,11 @@
def self.inherited(base)
super
base.class_eval do
before_create :bind_current_user
+ before_save :bind_current_updater
end
end
def interpolation_options
return {} if collection_action? || resource.errors.empty?
@@ -124,20 +129,10 @@
def export_options
export_builder.render_options
end
- def set_title
- name_for_lookup = params[:custom_action] || action_name
- lookups = [:"admin.#{controller_name}.actions.#{name_for_lookup}.title",
- :"admin.#{controller_name}.actions.#{name_for_lookup}",
- :"admin.actions.#{name_for_lookup}.title",
- :"admin.actions.#{name_for_lookup}",
- name_for_lookup]
- @page_title ||= [resource_class.model_name.human(count: 1), t(lookups.shift, default: lookups)].join(' - ')
- end
-
def preview_resource_path(item)
nil
end
def settings
@@ -184,10 +179,20 @@
if params[:id] && resource.persisted?
@breadcrumbs << {name: AbAdmin.display_name(resource), url: resource_path}
end
end
+ def set_title
+ name_for_lookup = params[:custom_action] || action_name
+ lookups = [:"admin.#{controller_name}.actions.#{name_for_lookup}.title",
+ :"admin.#{controller_name}.actions.#{name_for_lookup}",
+ :"admin.actions.#{name_for_lookup}.title",
+ :"admin.actions.#{name_for_lookup}",
+ name_for_lookup]
+ @page_title ||= t(lookups.shift, default: lookups)
+ end
+
def parent_collection_path
{action: :index, controller: "admin/#{parent_class.model_name.plural}"}
end
def tree_node_renderer
@@ -213,13 +218,17 @@
params[:per_page] = cookies[:pp] || 50
end
end
def set_layout
- request.headers['X-PJAX'] ? false : 'admin/application'
+ pjax? ? false : 'admin/application'
end
+ def pjax?
+ request.headers['X-PJAX']
+ end
+
def back_or_collection
if params[:return_to].present? && (params[:return_to] != request.fullpath)
params[:return_to]
else
smart_collection_url
@@ -270,10 +279,14 @@
def bind_current_user(*args)
resource.user_id = current_user.id if resource.respond_to?(:user_id)
end
+ def bind_current_updater(*args)
+ resource.updater_id = current_user.id if resource.respond_to?(:updater_id)
+ end
+
def xhr?
request.xhr?
end
# roles logic
@@ -301,12 +314,15 @@
end
def render_unauthorized(exception)
Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}, user: #{current_user.try(:id)}"
- respond_to do |format|
- format.html { redirect_to (moderator? ? admin_root_path : root_path), alert: exception.message }
- format.any { head :unauthorized }
+ if pjax?
+ render partial: 'admin/shared/flash', locals: {flash: {alert: exception.message}}
+ elsif request.format.try(:html?)
+ redirect_to (moderator? ? admin_root_path : root_path), alert: exception.message
+ else
+ head :unauthorized
end
end
end
\ No newline at end of file