Module: Effective::Resources::Controller
- Included in:
- Effective::Resource
- Defined in:
- app/models/effective/resources/controller.rb
Instance Method Summary collapse
- #buttons ⇒ Object
- #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
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 {}.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.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 .values.find { |v| v[:action] == :archive }.present? ['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" } else [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 } ["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 |
#ons ⇒ Object
119 120 121 |
# File 'app/models/effective/resources/controller.rb', line 119 def ons {} end |
#resource_actions ⇒ Object
This is the fallback for render_resource_actions when no actions are specified It is used by datatables
67 68 69 70 71 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 |
# File 'app/models/effective/resources/controller.rb', line 67 def resource_actions {}.tap do |actions| (member_get_actions & crud_actions).reverse_each do |action| actions[action.to_s.titleize] = { action: action, default: true } end (member_get_actions - crud_actions).each do |action| actions[action.to_s.titleize] = { action: action, default: true } end (member_post_actions - crud_actions).each do |action| actions[action.to_s.titleize] = { action: action, default: true, 'data-method' => :post, 'data-confirm' => "Really #{action} @resource?" } actions[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 actions.values.find { |v| v[:action] == :archive }.present? actions['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" } else actions[action.to_s.titleize] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action} @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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/effective/resources/controller.rb', line 103 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…
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/effective/resources/controller.rb', line 9 def submits {}.tap do |submits| if (actions.find { |a| a == :create } || actions.find { |a| a == :update }) submits['Save'] = { action: :save, default: true } end if actions.find { |a| a == :index } submits['Continue'] = { action: :save, redirect: :index, default: true, unless: -> { params[:_datatable_id].present? } } end if actions.find { |a| a == :new } submits['Add New'] = { action: :save, redirect: :new, default: true, unless: -> { params[:_datatable_id].present? } } end end end |