Extract methods in toggle selection component
This commit is contained in:
@@ -1 +1 @@
|
||||
<%= link_to_toggle_proposal_selection %>
|
||||
<%= link_to text, path, options %>
|
||||
|
||||
@@ -5,22 +5,34 @@ class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
|
||||
@proposal = proposal
|
||||
end
|
||||
|
||||
def link_to_toggle_proposal_selection
|
||||
private
|
||||
|
||||
def text
|
||||
if proposal.selected?
|
||||
button_text = t("admin.proposals.index.selected")
|
||||
html_class = "button expanded"
|
||||
t("admin.proposals.index.selected")
|
||||
else
|
||||
button_text = t("admin.proposals.index.select")
|
||||
html_class = "button hollow expanded"
|
||||
t("admin.proposals.index.select")
|
||||
end
|
||||
end
|
||||
|
||||
def path
|
||||
case proposal.class.to_s
|
||||
when "Proposal"
|
||||
path = toggle_selection_admin_proposal_path(proposal)
|
||||
toggle_selection_admin_proposal_path(proposal)
|
||||
when "Legislation::Proposal"
|
||||
path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal)
|
||||
toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal)
|
||||
end
|
||||
end
|
||||
|
||||
link_to button_text, path, remote: true, method: :patch, class: html_class
|
||||
def options
|
||||
{ remote: true, method: :patch, class: html_class }
|
||||
end
|
||||
|
||||
def html_class
|
||||
if proposal.selected?
|
||||
"button expanded"
|
||||
else
|
||||
"button hollow expanded"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user