adds complete Booth management to admin
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
class Admin::Poll::BoothsController < Admin::BaseController
|
||||
load_and_authorize_resource :poll
|
||||
load_and_authorize_resource class: 'Poll::Booth', through: :poll
|
||||
|
||||
before_action :load_polls, only: :index
|
||||
load_and_authorize_resource class: 'Poll::Booth'
|
||||
|
||||
def index
|
||||
@booths = @booths.order(name: :asc).page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@officers = Poll::Officer.all
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -16,7 +13,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
|
||||
|
||||
def create
|
||||
if @booth.save
|
||||
redirect_to admin_poll_booth_path(@poll, @booth), notice: t("flash.actions.create.poll_booth")
|
||||
redirect_to admin_booths_path, notice: t("flash.actions.create.poll_booth")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -27,7 +24,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
|
||||
|
||||
def update
|
||||
if @booth.update(booth_params)
|
||||
redirect_to admin_poll_booth_path(@poll, @booth), notice: t("flash.actions.update.poll_booth")
|
||||
redirect_to admin_booth_path(@booth), notice: t("flash.actions.update.poll_booth")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -36,11 +33,7 @@ class Admin::Poll::BoothsController < Admin::BaseController
|
||||
private
|
||||
|
||||
def booth_params
|
||||
params.require(:poll_booth).permit(:name, :location, officer_ids: [])
|
||||
end
|
||||
|
||||
def load_polls
|
||||
@polls = Poll.all
|
||||
params.require(:poll_booth).permit(:name, :location)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,18 +1,15 @@
|
||||
<tr id="booth_<%= booth.id %>" class="booth">
|
||||
<td>
|
||||
<strong>
|
||||
<%= link_to booth.name, admin_poll_booth_path(@poll, booth) %>
|
||||
<%= link_to booth.name, admin_booth_path(booth) %>
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
<%= booth.location %>
|
||||
</td>
|
||||
<td>
|
||||
N <%= t("admin.booths.index.officers") %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<%= link_to t("admin.actions.edit"),
|
||||
edit_admin_poll_booth_path(@poll, booth),
|
||||
edit_admin_booth_path(booth),
|
||||
class: "button hollow" %>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= render 'shared/back_link' %>
|
||||
<%= back_link_to admin_booths_path %>
|
||||
|
||||
<h2><%= t("admin.booths.edit.title", poll: @poll.name) %>: <%= t("admin.booths.edit.subtitle") %></h2>
|
||||
<h2><%= t("admin.booths.edit.title") %></h2>
|
||||
|
||||
<%= form_for @booth, url: admin_poll_booth_path(@poll, @booth) do |f| %>
|
||||
<%= form_for @booth, url: admin_booth_path(@booth) do |f| %>
|
||||
<%= render "form", f: f %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
<h2><%= t("admin.booths.index.title") %></h2>
|
||||
|
||||
<div class="small-12 medium-6">
|
||||
<%= form_tag '', method: :get do %>
|
||||
<%= select_tag "poll_id",
|
||||
options_for_select(@polls.collect {|poll|
|
||||
[poll.name, admin_poll_booths_path(poll)]
|
||||
}),
|
||||
prompt: t("admin.booths.index.select_poll"),
|
||||
class: "js-location-changer" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h3><%= t("admin.booths.index.title_list", poll: @poll.name) %></h3>
|
||||
|
||||
<% if @booths.empty? %>
|
||||
<div class="callout primary">
|
||||
<%= t("admin.booths.index.no_booths") %>
|
||||
@@ -20,19 +7,22 @@
|
||||
<% end %>
|
||||
|
||||
<%= link_to t("admin.booths.index.add_booth"),
|
||||
new_admin_poll_booth_path(@poll),
|
||||
new_admin_booth_path,
|
||||
class: "button success" %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<th><%= t("admin.booths.index.name") %></th>
|
||||
<th><%= t("admin.booths.index.location") %></th>
|
||||
<th><%= t("admin.booths.index.officers") %></th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @booths.each do |booth| %>
|
||||
<%= render partial: "booth", locals: { booth: booth } %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% if @booths.any? %>
|
||||
<table>
|
||||
<thead>
|
||||
<th><%= t("admin.booths.index.name") %></th>
|
||||
<th><%= t("admin.booths.index.location") %></th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @booths.each do |booth| %>
|
||||
<%= render partial: "booth", locals: { booth: booth } %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= paginate @booths %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= render 'shared/back_link' %>
|
||||
<%= back_link_to admin_booths_path %>
|
||||
|
||||
<h2><%= t("admin.booths.new.title", poll: @poll.name) %>: <%= t("admin.booths.new.subtitle") %></h2>
|
||||
<h2><%= t("admin.booths.new.title") %></h2>
|
||||
|
||||
<%= form_for @booth, url: admin_poll_booths_path(@poll) do |f| %>
|
||||
<%= form_for @booth, url: admin_booths_path(@booth) do |f| %>
|
||||
<%= render "form", f: f %>
|
||||
<% end %>
|
||||
@@ -1,55 +1,15 @@
|
||||
<%= render 'shared/back_link' %>
|
||||
<%= back_link_to admin_booths_path %>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
<h2 class="inline-block">
|
||||
<%= @booth.name %>
|
||||
</h2>
|
||||
<%= link_to t("admin.actions.edit"),
|
||||
edit_admin_poll_booth_path(@poll, @booth),
|
||||
edit_admin_booth_path(@booth),
|
||||
class: "button hollow float-right" %>
|
||||
|
||||
<p>
|
||||
<strong><%= t("admin.booths.show.location") %></strong>:
|
||||
<%= @booth.location %>
|
||||
</p>
|
||||
|
||||
<h3><%= t("admin.booths.show.officers_list") %></h3>
|
||||
|
||||
<% if @booth.officers.empty? %>
|
||||
<div class="callout primary">
|
||||
<%= t("admin.booths.show.no_officers") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= form_for @booth, url: admin_poll_booth_path(@poll, @booth) do |f| %>
|
||||
|
||||
<%= f.label :officer_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
|
||||
<%= f.collection_check_boxes :officer_ids, @officers, :id, :email do |b| %>
|
||||
<% b.label { b.check_box + truncate(officer_label(b.object), length: 60) } %>
|
||||
<% end %>
|
||||
|
||||
<%= f.submit t("admin.booths.show.assign_officer"), class: "button success" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<table id="assigned_officers">
|
||||
<% @booth.officers.each do |officer| %>
|
||||
<tr id="officer_<%= officer.id %>" class="officer">
|
||||
<td>
|
||||
<%= officer.name %>
|
||||
</td>
|
||||
<td>
|
||||
<%= officer.email %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<%= link_to t('admin.poll_officers.officer.delete'), "#", class: "button hollow alert" %>
|
||||
<%# link_to t('admin.poll_officers.officer.delete'),
|
||||
admin_poll_officer_path(Poll.last, officer),
|
||||
method: :delete,
|
||||
class: "button hollow alert"
|
||||
%>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
Reference in New Issue
Block a user