Module: ActiveAdmin::ActsAsList::ActiveAdminHelper

Defined in:
lib/active_admin/acts_as_list/active_admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#sortable_columnsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/active_admin/acts_as_list/active_admin_helper.rb', line 4

def sortable_columns
  column "▲▲".html_safe do |resource|
    link_to("▲▲".html_safe, self.send(:"move_to_top_admin_#{resource.class.model_name.underscore.gsub("/", "_")}_path", resource), :class => "arrow") unless resource.first?
  end
  column "▲".html_safe do |resource|
    link_to("▲".html_safe, self.send(:"move_up_admin_#{resource.class.model_name.underscore.gsub("/", "_")}_path", resource), :class => "arrow") unless resource.first?
  end
  column "▼".html_safe do |resource|
    link_to("▼".html_safe, self.send(:"move_down_admin_#{resource.class.model_name.underscore.gsub("/", "_")}_path", resource), :class => "arrow") unless resource.last?
  end
  column "▼▼".html_safe do |resource|
    link_to("▼▼".html_safe, self.send(:"move_to_bottom_admin_#{resource.class.model_name.underscore.gsub("/", "_")}_path", resource), :class => "arrow") unless resource.last?
  end
end

#sortable_member_actionsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_admin/acts_as_list/active_admin_helper.rb', line 19

def sortable_member_actions
 member_action :move_to_top do
    if resource.first?
      redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_to_top', :resource => resource_class.to_s.camelize.constantize.model_name.human ) 
      return
    end  
    
    resource.move_to_top
    redirect_to :back, :notice => I18n.t('acts_as_list.moved_to_top', :resource => resource_class.to_s.camelize.constantize.model_name.human )
  end
  
  member_action :move_to_bottom do
    if resource.last?
      redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_to_bottom', :resource => resource_class.to_s.camelize.constantize.model_name.human ) 
      return
    end  
    
    resource.move_to_bottom
    redirect_to :back, :notice => I18n.t('acts_as_list.moved_to_bottom', :resource => resource_class.to_s.camelize.constantize.model_name.human )
  end

  member_action :move_up do
    if resource.first?
      redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_up', :resource => resource_class.to_s.camelize.constantize.model_name.human ) 
      return
    end  
    
    resource.move_higher
    redirect_to :back, :notice => I18n.t('acts_as_list.moved_up', :resource => resource_class.to_s.camelize.constantize.model_name.human )
  end

  member_action :move_down do
    if resource.last?
      redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_down', :resource => resource_class.to_s.camelize.constantize.model_name.human ) 
      return
    end  
    
    resource.move_lower
    redirect_to :back, :notice => I18n.t('acts_as_list.moved_down', :resource => resource_class.to_s.camelize.constantize.model_name.human )
  end    
end