Class: CmAdmin::Models::Action

Inherits:
Object
  • Object
show all
Includes:
CmAdmin::Models::Actions::Blocks
Defined in:
lib/cm_admin/models/action.rb

Direct Known Subclasses

CustomAction

Constant Summary collapse

VALID_SORT_DIRECTION =
Set[:asc, :desc].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CmAdmin::Models::Actions::Blocks

#set_layout, #set_partial, #set_title

Constructor Details

#initialize(attributes = {}, &block) ⇒ Action

Returns a new instance of Action.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cm_admin/models/action.rb', line 13

def initialize(attributes = {}, &block)
  if attributes[:layout_type].present? && attributes[:layout].nil? && attributes[:partial].nil?
    case attributes[:layout_type]
    when 'cm_association_index'
      attributes[:layout] = '/cm_admin/main/associated_index'
      attributes[:partial] = '/cm_admin/main/associated_table'
    when 'cm_association_show'
      attributes[:layout] = '/cm_admin/main/associated_show'
    end
  end
  set_default_values
  attributes.each do |key, value|
    self.send("#{key.to_s}=", value)
  end
  self.send("code_block=", block) if block_given?
end

Instance Attribute Details

#action_typeObject

Returns the value of attribute action_type.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def action_type
  @action_type
end

#child_recordsObject

Returns the value of attribute child_records.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def child_records
  @child_records
end

#code_blockObject

Returns the value of attribute code_block.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def code_block
  @code_block
end

#display_ifObject

Returns the value of attribute display_if.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def display_if
  @display_if
end

#display_typeObject

Returns the value of attribute display_type.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def display_type
  @display_type
end

#icon_nameObject

Returns the value of attribute icon_name.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def icon_name
  @icon_name
end

#is_nested_fieldObject

Returns the value of attribute is_nested_field.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def is_nested_field
  @is_nested_field
end

#layoutObject

Returns the value of attribute layout.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def layout
  @layout
end

#layout_typeObject

Returns the value of attribute layout_type.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def layout_type
  @layout_type
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def name
  @name
end

#nested_table_nameObject

Returns the value of attribute nested_table_name.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def nested_table_name
  @nested_table_name
end

#page_descriptionObject

Returns the value of attribute page_description.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def page_description
  @page_description
end

#page_titleObject

Returns the value of attribute page_title.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def page_title
  @page_title
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def parent
  @parent
end

#partialObject

Returns the value of attribute partial.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def partial
  @partial
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def path
  @path
end

#redirection_urlObject

Returns the value of attribute redirection_url.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def redirection_url
  @redirection_url
end

#route_typeObject

Returns the value of attribute route_type.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def route_type
  @route_type
end

#sort_columnObject

Returns the value of attribute sort_column.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def sort_column
  @sort_column
end

#sort_directionObject

Returns the value of attribute sort_direction.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def sort_direction
  @sort_direction
end

#verbObject

Returns the value of attribute verb.



7
8
9
# File 'lib/cm_admin/models/action.rb', line 7

def verb
  @verb
end

Class Method Details

.find_by(model, search_hash) ⇒ Object



57
58
59
# File 'lib/cm_admin/models/action.rb', line 57

def find_by(model, search_hash)
  model.available_actions.find { |i| i.name == search_hash[:name] }
end

Instance Method Details

#controller_action_nameObject



46
47
48
49
50
51
52
53
54
# File 'lib/cm_admin/models/action.rb', line 46

def controller_action_name
  if self.action_type == :custom
    'cm_custom_method'
  elsif self.parent
    'cm_' + self.parent
  else
    'cm_' + name
  end
end

#set_default_valuesObject



30
31
32
33
34
35
36
37
38
# File 'lib/cm_admin/models/action.rb', line 30

def set_default_values
  self.is_nested_field = false
  self.display_if = lambda { |arg| return true }
  self.display_type = :button
  self.action_type = :default
  self.sort_column = :created_at
  self.sort_direction = :desc
  self.icon_name = 'fa fa-th-large'
end

#set_values(page_title, page_description, partial) ⇒ Object



40
41
42
43
44
# File 'lib/cm_admin/models/action.rb', line 40

def set_values(page_title, page_description, partial)
  self.page_title = page_title
  self.page_description = page_description
  self.partial = partial
end