adds question, booth and officer tabs for a poll

This commit is contained in:
rgarcia
2016-11-29 11:46:02 +01:00
parent 20cb044015
commit c1ea074be4
6 changed files with 144 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
class Poll < ActiveRecord::Base
has_many :booths
has_many :voters, through: :booths, class_name: "Poll::Voter"
has_many :officers, through: :booths, class_name: "Poll::Officer"
has_many :questions
validates :name, presence: true

View File

@@ -0,0 +1,26 @@
<div class="row">
<div class="small-12 column">
<% if @poll.booths.empty? %>
<div class="callout primary text-center">
<%= t("admin.polls.show.no_booths") %>
</div>
<% else %>
<h2><%= t("admin.polls.show.booths_title") %></h2>
<table>
<thead>
<th><%= t("admin.polls.show.name") %></th>
<th><%= t("admin.polls.show.location") %></th>
<th><%= t("admin.polls.show.officers") %></th>
<th>&nbsp;</th>
</thead>
<tbody>
<% @poll.booths.each do |booth| %>
<%= render partial: "admin/poll/booths/booth", locals: { booth: booth } %>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,33 @@
<div class="row">
<div class="small-12 column">
<ul class="tabs" data-tabs id="example-tabs">
<li class="tabs-title is-active">
<%= link_to "#tab-questions" do %>
<h2>
<%# t("proposals.show.comments_tab") %>
Preguntas
<span class="js-comments-count">(<%= @poll.questions.count %>)</span>
</h2>
<% end %>
</li>
<li class="tabs-title">
<%= link_to "#tab-booths" do %>
<h2>
<%# t("proposals.show.notifications_tab") %>
Urnas
(<%= @poll.booths.count %>)
</h2>
<% end %>
</li>
<li class="tabs-title">
<%= link_to "#tab-officers" do %>
<h2>
<%# t("proposals.show.notifications_tab") %>
Presidentes
(<%= @poll.officers.count %>)
</h2>
<% end %>
</li>
</ul>
</div>
</div>

View File

@@ -0,0 +1,43 @@
<div class="row">
<div class="small-12 column">
<% if @poll.officers.empty? %>
<div class="callout primary text-center">
<%= t("admin.polls.show.no_booths") %>
</div>
<% else %>
<h2><%= t("admin.polls.show.booths_title") %></h2>
<table>
<thead>
<th><%= t("admin.polls.show.name") %></th>
<th><%= t("admin.polls.show.location") %></th>
<th><%= t("admin.polls.show.officers") %></th>
<th>&nbsp;</th>
</thead>
<tbody>
<% @poll.officers.each do |officer| %>
<tr id="officer_<%= officer.id %>" class="officer">
<td>
<strong>
<%= link_to officer.name, admin_poll_officer_path(@poll, booth) %>
</strong>
</td>
<td>
<%= officer.name %>
</td>
<td>
N <%= t("admin.booths.index.officers") %>
</td>
<td class="text-right">
<%= link_to t("admin.actions.edit"),
edit_admin_poll_officer_path(@poll, officer),
class: "button hollow" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,29 @@
<div class="row">
<div class="small-12 column">
<%= link_to "Añadir pregunta",
new_admin_question_path(poll_id: @poll.id),
class: "button success" %>
</div>
<% if @poll.questions.count == 0 %>
<div class="callout primary text-center">
<%= t('admin.questions.index.no_questions') %>
</div>
<% else %>
<table>
<% @poll.questions.each do |question| %>
<tr id="<%= dom_id(question) %>">
<td><%= link_to question.title, admin_question_path(question) %></td>
<td class="text-right">
<%= link_to t('shared.edit'),
edit_admin_question_path(question),
class: "button hollow" %>
<%= link_to t('shared.delete'),
admin_question_path(question),
class: "button hollow alert",
method: :delete %>
</td>
</tr>
<% end %>
</table>
<% end %>
</div>

View File

@@ -9,28 +9,18 @@
edit_admin_poll_path(@poll),
class: "button hollow float-right" %>
<%= link_to t("admin.polls.show.add_booth"),
new_admin_poll_booth_path(@poll),
class: "button success" %>
<div class="tabs-content" data-tabs-content="example-tabs">
<%= render "filter_subnav" %>
<% if @poll.booths.empty? %>
<div class="callout primary">
<%= t("admin.polls.show.no_booths") %>
<div class="tabs-panel is-active" id="tab-questions">
<%= render "questions" %>
</div>
<% else %>
<h2><%= t("admin.polls.show.booths_title") %></h2>
<table>
<thead>
<th><%= t("admin.polls.show.name") %></th>
<th><%= t("admin.polls.show.location") %></th>
<th><%= t("admin.polls.show.officers") %></th>
<th>&nbsp;</th>
</thead>
<tbody>
<% @poll.booths.each do |booth| %>
<%= render partial: "admin/poll/booths/booth", locals: { booth: booth } %>
<% end %>
</tbody>
</table>
<% end %>
<div class="tabs-panel" id="tab-booths">
<%= render "booths" %>
</div>
<div class="tabs-panel" id="tab-officers">
<%= render 'officers' %>
</div>
</div>