Module: Effective::Resources::Controller
- Included in:
- Effective::Resource
- Defined in:
- app/models/effective/resources/controller.rb
Instance Method Summary collapse
- #buttons ⇒ Object
-
#fallback_resource_actions ⇒ Object
Used by datatables.
- #ons ⇒ Object
-
#resource_actions ⇒ Object
This is the fallback for render_resource_actions when no actions are specified It is used by datatables.
-
#resource_klass_actions ⇒ Object
This is the fallback for render_resource_actions when no actions are specified, but a class is given Used by Datatables new.
-
#submits ⇒ Object
Used by effective_form_submit The actions we would use to commit.
Instance Method Details
#buttons ⇒ Object
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 |
# File 'app/models/effective/resources/controller.rb', line 27 def {}.tap do || member_get_actions.each do |action| # default true means it will be overwritten by dsl methods [action.to_s.titleize] = { action: action, default: true } end (member_post_actions - crud_actions).each do |action| # default true means it will be overwritten by dsl methods action_name = action.to_s.titleize [action_name] = case action when :archive { action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => "Really #{action_name} @resource?"} when :unarchive { action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => "Really #{action_name} @resource?" } else { action: action, default: true, 'data-method' => :post, 'data-confirm' => "Really #{action_name} @resource?"} end end member_delete_actions.each do |action| action_name = action.to_s.titleize if action == :destroy ['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" } else [action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" } end end if collection_get_actions.find { |a| a == :index } ["All #{human_plural_name}".titleize] = { action: :index, default: true } end if collection_get_actions.find { |a| a == :new } ["New #{human_name}".titleize] = { action: :new, default: true } end (collection_get_actions - crud_actions).each do |action| [action.to_s.titleize] = { action: action, default: true } end end end |
#fallback_resource_actions ⇒ Object
Used by datatables
112 113 114 115 116 117 118 |
# File 'app/models/effective/resources/controller.rb', line 112 def fallback_resource_actions { 'Show': { action: :show, default: true }, 'Edit': { action: :edit, default: true }, 'Delete': { action: :destroy, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" } } end |
#ons ⇒ Object
138 139 140 |
# File 'app/models/effective/resources/controller.rb', line 138 def ons {} end |
#resource_actions ⇒ Object
This is the fallback for render_resource_actions when no actions are specified It is used by datatables
72 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 109 |
# File 'app/models/effective/resources/controller.rb', line 72 def resource_actions {}.tap do |actions| member_get_actions.reverse_each do |action| next unless crud_actions.include?(action) actions[action.to_s.titleize] = { action: action, default: true } end member_get_actions.each do |action| next if crud_actions.include?(action) actions[action.to_s.titleize] = { action: action, default: true } end member_post_actions.each do |action| next if crud_actions.include?(action) action_name = action.to_s.titleize actions[action_name] = case action when :archive { action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => "Really #{action_name} @resource?"} when :unarchive { action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => "Really #{action_name} @resource?" } else { action: action, default: true, 'data-method' => :post, 'data-confirm' => "Really #{action_name} @resource?" } end end member_delete_actions.each do |action| action_name = action.to_s.titleize if action == :destroy actions['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" } else actions[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" } end end end end |
#resource_klass_actions ⇒ Object
This is the fallback for render_resource_actions when no actions are specified, but a class is given Used by Datatables new
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/effective/resources/controller.rb', line 122 def resource_klass_actions {}.tap do || if collection_get_actions.find { |a| a == :index } ["All #{human_plural_name}".titleize] = { action: :index, default: true } end if collection_get_actions.find { |a| a == :new } ["New #{human_name}".titleize] = { action: :new, default: true } end (collection_get_actions - crud_actions).each do |action| [action.to_s.titleize] = { action: action, default: true } end end end |
#submits ⇒ Object
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 |