Module: Effective::Resources::Controller

Included in:
Effective::Resource
Defined in:
app/models/effective/resources/controller.rb

Instance Method Summary collapse

Instance Method Details

#buttonsObject



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
64
65
66
67
68
69
# File 'app/models/effective/resources/controller.rb', line 27

def buttons
  human_index = EffectiveResources.et("effective_resources.actions.index")
  human_new = EffectiveResources.et("effective_resources.actions.new")

  {}.tap do |buttons|
    member_get_actions.each do |action| # default true means it will be overwritten by dsl methods
      buttons[human_action_name(action)] = { action: action, default: true }
    end

    (member_post_actions - crud_actions).each do |action| # default true means it will be overwritten by dsl methods
      name = human_action_name(action)
      confirm = human_action_confirm(action)

      buttons[name] = case action
      when :archive
        { action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => confirm }
      when :unarchive
        { action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => confirm }
      else
        { action: action, default: true, 'data-method' => :post, 'data-confirm' => confirm }
      end
    end

    member_delete_actions.each do |action|
      name = human_action_name(action)
      confirm = human_action_confirm(action)

      buttons[name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => confirm }
    end

    if collection_get_actions.find { |a| a == :index }
      buttons["#{human_index} #{human_plural_name}"] = { action: :index, default: true }
    end

    if collection_get_actions.find { |a| a == :new }
      buttons["#{human_new} #{human_name}"] = { action: :new, default: true }
    end

    (collection_get_actions - crud_actions).each do |action|
      buttons[human_action_name(action)] = { action: action, default: true }
    end
  end
end

#fallback_resource_actionsObject

Used by datatables



111
112
113
114
115
116
117
# File 'app/models/effective/resources/controller.rb', line 111

def fallback_resource_actions
  {
    human_action_name(:show) => { action: :show, default: true },
    human_action_name(:edit) => { action: :edit, default: true },
    human_action_name(:destroy) => { action: :destroy, default: true, 'data-method' => :delete, 'data-confirm' => human_action_confirm(:destroy) }
  }
end

#onsObject



140
141
142
# File 'app/models/effective/resources/controller.rb', line 140

def ons
  {}
end

#resource_actionsObject

This is the fallback for render_resource_actions when no actions are specified It is used by datatables



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/models/effective/resources/controller.rb', line 73

def resource_actions
  {}.tap do |actions|
    member_get_actions.reverse_each do |action|
      next unless crud_actions.include?(action)
      actions[human_action_name(action)] = { action: action, default: true }
    end

    member_get_actions.each do |action|
      next if crud_actions.include?(action)
      actions[human_action_name(action)] = { action: action, default: true }
    end

    member_post_actions.each do |action|
      next if crud_actions.include?(action)

      name = human_action_name(action)
      confirm = human_action_confirm(action)

      actions[name] = case action
      when :archive
        { action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => confirm }
      when :unarchive
        { action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => confirm }
      else
        { action: action, default: true, 'data-method' => :post, 'data-confirm' => confirm }
      end
    end

    member_delete_actions.each do |action|
      name = human_action_name(action)
      confirm = human_action_confirm(action)

      actions[name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => confirm }
    end
  end
end

#resource_klass_actionsObject

This is the fallback for render_resource_actions when no actions are specified, but a class is given Used by Datatables new



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/models/effective/resources/controller.rb', line 121

def resource_klass_actions
  human_index = EffectiveResources.et("effective_resources.actions.index")
  human_new = EffectiveResources.et("effective_resources.actions.new")

  {}.tap do |buttons|
    if collection_get_actions.find { |a| a == :index }
      buttons["#{human_index} #{human_plural_name}"] = { action: :index, default: true }
    end

    if collection_get_actions.find { |a| a == :new }
      buttons["#{human_new} #{human_name}"] = { action: :new, default: true }
    end

    (collection_get_actions - crud_actions).each do |action|
      buttons[human_action_name(action)] = { action: action, default: true }
    end
  end
end

#submitsObject

Used by effective_form_submit The actions we would use to commit. For link_to { ‘Save’: { action: :save }, ‘Continue’: { action: :save }, ‘Add New’: { action: :save }, ‘Approve’: { action: :approve } } Saves a list of commit actions…



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/effective/resources/controller.rb', line 11

def submits
  {}.tap do |submits|
    if actions.find { |a| a == :create || a == :update } && EffectiveResources.default_submits['Save']
      submits['Save'] = { action: :save, default: true }
    end

    if actions.find { |a| a == :index } && EffectiveResources.default_submits['Continue']
      submits['Continue'] = { action: :save, redirect: :index, default: true, unless: -> { params[:_datatable_id].present? } }
    end

    if actions.find { |a| a == :new } && EffectiveResources.default_submits['Add New']
      submits['Add New'] = { action: :save, redirect: :new, default: true, unless: -> { params[:_datatable_id].present? } }
    end
  end
end