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
60
61
62
63
|
# File 'app/models/effective/resources/controller.rb', line 25
def buttons
{}.tap do |buttons|
member_get_actions.each do |action| buttons[action.to_s.titleize] = { action: action, default: true }
end
(member_post_actions - crud_actions).each do |action| buttons[action.to_s.titleize] = case action
when :archive
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => "Really #{action} @resource?"}
when :unarchive
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => "Really #{action} @resource?" }
else
{ action: action, default: true, 'data-method' => :post, 'data-confirm' => "Really #{action} @resource?"}
end
end
member_delete_actions.each do |action|
if action == :destroy
next if buttons.values.find { |v| v[:action] == :archive }.present?
buttons['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
else
buttons[action.to_s.titleize] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action} @resource?" }
end
end
if collection_get_actions.find { |a| a == :index }
buttons["All #{human_plural_name}".titleize] = { action: :index, default: true }
end
if collection_get_actions.find { |a| a == :new }
buttons["New #{human_name}".titleize] = { action: :new, default: true }
end
(collection_get_actions - crud_actions).each do |action|
buttons[action.to_s.titleize] = { action: action, default: true }
end
end
end
|