Extract link to toggle selection to a component
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
<%= link_to_toggle_proposal_selection %>
|
||||||
26
app/components/admin/proposals/toggle_selection_component.rb
Normal file
26
app/components/admin/proposals/toggle_selection_component.rb
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
|
||||||
|
attr_reader :proposal
|
||||||
|
|
||||||
|
def initialize(proposal)
|
||||||
|
@proposal = proposal
|
||||||
|
end
|
||||||
|
|
||||||
|
def link_to_toggle_proposal_selection
|
||||||
|
if proposal.selected?
|
||||||
|
button_text = t("admin.proposals.index.selected")
|
||||||
|
html_class = "button expanded"
|
||||||
|
else
|
||||||
|
button_text = t("admin.proposals.index.select")
|
||||||
|
html_class = "button hollow expanded"
|
||||||
|
end
|
||||||
|
|
||||||
|
case proposal.class.to_s
|
||||||
|
when "Proposal"
|
||||||
|
path = toggle_selection_admin_proposal_path(proposal)
|
||||||
|
when "Legislation::Proposal"
|
||||||
|
path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal)
|
||||||
|
end
|
||||||
|
|
||||||
|
link_to button_text, path, remote: true, method: :patch, class: html_class
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -64,25 +64,6 @@ module ProposalsHelper
|
|||||||
proposals_current_view == "default" ? "minimal" : "default"
|
proposals_current_view == "default" ? "minimal" : "default"
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_toggle_proposal_selection(proposal)
|
|
||||||
if proposal.selected?
|
|
||||||
button_text = t("admin.proposals.index.selected")
|
|
||||||
html_class = "button expanded"
|
|
||||||
else
|
|
||||||
button_text = t("admin.proposals.index.select")
|
|
||||||
html_class = "button hollow expanded"
|
|
||||||
end
|
|
||||||
|
|
||||||
case proposal.class.to_s
|
|
||||||
when "Proposal"
|
|
||||||
path = toggle_selection_admin_proposal_path(proposal)
|
|
||||||
when "Legislation::Proposal"
|
|
||||||
path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal)
|
|
||||||
end
|
|
||||||
|
|
||||||
link_to button_text, path, remote: true, method: :patch, class: html_class
|
|
||||||
end
|
|
||||||
|
|
||||||
def css_for_proposal_info_row(proposal)
|
def css_for_proposal_info_row(proposal)
|
||||||
if proposal.image.present?
|
if proposal.image.present?
|
||||||
if params[:selected].present?
|
if params[:selected].present?
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<td class="text-center"><%= proposal.id %></td>
|
<td class="text-center"><%= proposal.id %></td>
|
||||||
<td><%= proposal.title %></td>
|
<td><%= proposal.title %></td>
|
||||||
<td class="text-center"><%= proposal.votes_score %></td>
|
<td class="text-center"><%= proposal.votes_score %></td>
|
||||||
<td class="select"><%= render "select_proposal", proposal: proposal %></td>
|
<td class="select"><%= render Admin::Proposals::ToggleSelectionComponent.new(proposal) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<%= link_to_toggle_proposal_selection(proposal) %>
|
|
||||||
@@ -1 +1,3 @@
|
|||||||
$("#<%= dom_id(@proposal) %> .select").html("<%= j render("select_proposal", proposal: @proposal) %>");
|
$("#<%= dom_id(@proposal) %> .select").html(
|
||||||
|
"<%= j render(Admin::Proposals::ToggleSelectionComponent.new(@proposal)) %>"
|
||||||
|
);
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<%= link_to_toggle_proposal_selection(proposal) %>
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<td><%= link_to proposal.title, admin_proposal_path(proposal) %></td>
|
<td><%= link_to proposal.title, admin_proposal_path(proposal) %></td>
|
||||||
<td><%= proposal.author.username %></td>
|
<td><%= proposal.author.username %></td>
|
||||||
<td><%= proposal.milestones.count %></td>
|
<td><%= proposal.milestones.count %></td>
|
||||||
<td class="js-select"><%= render "select_proposal", proposal: proposal %></td>
|
<td class="js-select"><%= render Admin::Proposals::ToggleSelectionComponent.new(proposal) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
$("#<%= dom_id(@proposal) %> .js-select").html("<%= j render("select_proposal", proposal: @proposal) %>");
|
$("#<%= dom_id(@proposal) %> .js-select").html(
|
||||||
|
"<%= j render(Admin::Proposals::ToggleSelectionComponent.new(@proposal)) %>"
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user