Class: Coalla::ActionsColumnDefinition
Instance Attribute Summary
#align, #edit, #sort, #title, #value_extractor
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ActionsColumnDefinition.
3
4
5
6
|
# File 'lib/coalla/builders/actions_column_definition.rb', line 3
def initialize
self.title = I18n.t('admin.common.actions')
@actions = []
end
|
Instance Method Details
#action(method, options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/coalla/builders/actions_column_definition.rb', line 31
def action(method, options = {})
@actions << case method
when :edit
[->(item) { edit_link(url_for(action: :edit, id: item)) }, options.merge(action_name: :edit)]
when :delete
[->(item) { delete_link(url_for(action: :destroy, id: item)) }, options.merge(action_name: :destroy)]
when Proc
[method, options]
else
raise "unsupported method: #{method.inspect}"
end
end
|
#col_class ⇒ Object
12
13
14
|
# File 'lib/coalla/builders/actions_column_definition.rb', line 12
def col_class
"col-xs-#{cols}"
end
|
#cols ⇒ Object
8
9
10
|
# File 'lib/coalla/builders/actions_column_definition.rb', line 8
def cols
@cols || @actions.size % 2 + @actions.size / 2
end
|
#cols=(value) ⇒ Object
16
17
18
|
# File 'lib/coalla/builders/actions_column_definition.rb', line 16
def cols=(value)
@cols = value
end
|
#value(item, context = self) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/coalla/builders/actions_column_definition.rb', line 20
def value(item, context = self)
@actions.collect do |action|
options = action.second
if options[:if]
context.instance_exec(item, &action.first) if options[:if].call(item)
else
context.instance_exec(item, &action.first)
end
end.compact.join(' ').html_safe
end
|