adds searching for officers when creating shifts
This commit is contained in:
@@ -2,20 +2,21 @@ class Admin::Poll::ShiftsController < Admin::BaseController
|
|||||||
|
|
||||||
before_action :load_booth
|
before_action :load_booth
|
||||||
before_action :load_polls
|
before_action :load_polls
|
||||||
|
before_action :load_officer
|
||||||
|
|
||||||
def new
|
def new
|
||||||
load_officers
|
|
||||||
load_shifts
|
load_shifts
|
||||||
@shift = ::Poll::Shift.new
|
@shift = ::Poll::Shift.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@shift = ::Poll::Shift.new(shift_params)
|
@shift = ::Poll::Shift.new(shift_params)
|
||||||
|
@officer = @shift.officer
|
||||||
|
|
||||||
if @shift.save
|
if @shift.save
|
||||||
notice = t("admin.poll_shifts.flash.create")
|
notice = t("admin.poll_shifts.flash.create")
|
||||||
redirect_to new_admin_booth_shift_path(@shift.booth), notice: notice
|
redirect_to new_admin_booth_shift_path(@shift.booth), notice: notice
|
||||||
else
|
else
|
||||||
load_officers
|
|
||||||
load_shifts
|
load_shifts
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
@@ -28,6 +29,10 @@ class Admin::Poll::ShiftsController < Admin::BaseController
|
|||||||
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_officers
|
||||||
|
@officers = User.search(params[:search]).order(username: :asc)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_booth
|
def load_booth
|
||||||
@@ -38,14 +43,16 @@ class Admin::Poll::ShiftsController < Admin::BaseController
|
|||||||
@polls = ::Poll.current_or_incoming
|
@polls = ::Poll.current_or_incoming
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_officers
|
|
||||||
@officers = ::Poll::Officer.all
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_shifts
|
def load_shifts
|
||||||
@shifts = @booth.shifts
|
@shifts = @booth.shifts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_officer
|
||||||
|
if params[:officer_id].present?
|
||||||
|
@officer = ::Poll::Officer.find(params[:officer_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def shift_params
|
def shift_params
|
||||||
params.require(:shift).permit(:booth_id, :officer_id, :date)
|
params.require(:shift).permit(:booth_id, :officer_id, :date)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<th><%= t("admin.poll_officer_assignments.index.table_name") %></th>
|
<th><%= t("admin.poll_officer_assignments.index.table_name") %></th>
|
||||||
<th><%= t("admin.poll_officer_assignments.index.table_email") %></th>
|
<th><%= t("admin.poll_officer_assignments.index.table_email") %></th>
|
||||||
<th class="text-right"><%= t("admin.actions.actions") %></th>
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @officers.each do |officer| %>
|
<% @officers.each do |officer| %>
|
||||||
@@ -28,11 +27,6 @@
|
|||||||
<td>
|
<td>
|
||||||
<%= officer.email %>
|
<%= officer.email %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
|
||||||
<%= link_to t("admin.poll_officer_assignments.index.edit_officer_assignments"),
|
|
||||||
by_officer_admin_poll_officer_assignments_path(@poll, officer_id: officer.id),
|
|
||||||
class: "button hollow" %>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
29
app/views/admin/poll/shifts/_form.html.erb
Normal file
29
app/views/admin/poll/shifts/_form.html.erb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<%= form_for @shift, as: :shift, url: admin_booth_shifts_path do |f| %>
|
||||||
|
<%= render "shared/errors", resource: @shift %>
|
||||||
|
|
||||||
|
<fieldset class="fieldset">
|
||||||
|
<legend>
|
||||||
|
<%= t("admin.poll_shifts.new.new_shift") %>
|
||||||
|
</legend>
|
||||||
|
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
Officer: <%= @officer.name %>
|
||||||
|
<%= f.hidden_field :officer_id, value: @officer.id %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<label><%= t("admin.poll_shifts.new.date") %></label>
|
||||||
|
<%= f.select :date,
|
||||||
|
shift_dates_select_options(@polls),
|
||||||
|
prompt: t("admin.poll_shifts.new.select_date"),
|
||||||
|
label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.hidden_field :booth_id, value: @booth.id %>
|
||||||
|
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<%= f.submit t("admin.poll_shifts.new.add_shift"),
|
||||||
|
class: "button expanded hollow margin-top" %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
||||||
19
app/views/admin/poll/shifts/_search_officers.html.erb
Normal file
19
app/views/admin/poll/shifts/_search_officers.html.erb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= form_tag search_officers_admin_booth_shifts_path,
|
||||||
|
method: :get, remote: true do |f| %>
|
||||||
|
<div class="input-group">
|
||||||
|
<%= text_field_tag :search,
|
||||||
|
@search,
|
||||||
|
placeholder: t("admin.poll_shifts.new.search_officer_placeholder"),
|
||||||
|
id: "search-officers" %>
|
||||||
|
<div class="input-group-button">
|
||||||
|
<%= submit_tag t("admin.poll_shifts.new.search_officer_button"),
|
||||||
|
class: "button" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="search-officers-results"></div>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<% if @officers.blank? %>
|
||||||
|
<div class="callout alert margin-bottom">
|
||||||
|
<%= t('admin.shared.no_search_results') %>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<h3><%= t('admin.shared.search_results') %></h3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.poll_shifts.new.table_name") %></th>
|
||||||
|
<th><%= t("admin.poll_shifts.new.table_email") %></th>
|
||||||
|
<th class="text-center">
|
||||||
|
<%= t("admin.poll_shifts.new.table_shift") %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @officers.each do |user| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= user.name %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= user.email %>
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<%= link_to t("admin.poll_shifts.new.edit_shifts"),
|
||||||
|
new_admin_booth_shift_path(officer_id: user.poll_officer.id),
|
||||||
|
class: "button hollow alert" %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<h3><%= t("admin.poll_shifts.new.assignments") %></h3>
|
<h3><%= t("admin.poll_shifts.new.shifts") %></h3>
|
||||||
<table class="fixed">
|
<table class="fixed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t("admin.poll_shifts.new.date") %></th>
|
<th><%= t("admin.poll_shifts.new.date") %></th>
|
||||||
<th><%= t("admin.poll_shifts.new.officer") %></th>
|
<th><%= t("admin.poll_shifts.new.officer") %></th>
|
||||||
<th class="text-right"><%= t("admin.poll_shifts.new.assignment") %></th>
|
<th class="text-right"><%= t("admin.poll_shifts.new.shift") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<td><%= l(shift.date.to_date, format: :long) %></td>
|
<td><%= l(shift.date.to_date, format: :long) %></td>
|
||||||
<td><%= shift.officer.name %></td>
|
<td><%= shift.officer.name %></td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<%= link_to t("admin.poll_shifts.new.remove_assignment"),
|
<%= link_to t("admin.poll_shifts.new.remove_shift"),
|
||||||
admin_booth_shift_path(@booth, shift),
|
admin_booth_shift_path(@booth, shift),
|
||||||
method: :delete,
|
method: :delete,
|
||||||
class: "button hollow alert" %>
|
class: "button hollow alert" %>
|
||||||
|
|||||||
@@ -2,43 +2,17 @@
|
|||||||
|
|
||||||
<h2><%= @booth.name %></h2>
|
<h2><%= @booth.name %></h2>
|
||||||
|
|
||||||
<%= form_for @shift, as: :shift, url: admin_booth_shifts_path do |f| %>
|
<% if @officer.blank? %>
|
||||||
<%= render "shared/errors", resource: @shift %>
|
<%= t("admin.poll_shifts.new.search_officer_text") %>
|
||||||
|
<%= render "search_officers" %>
|
||||||
<fieldset class="fieldset">
|
<% else %>
|
||||||
<legend>
|
<%= render "form" %>
|
||||||
<%= t("admin.poll_shifts.new.new_assignment") %>
|
<% end %>
|
||||||
</legend>
|
|
||||||
|
|
||||||
<div class="small-12 medium-4 column">
|
|
||||||
<label><%= t("admin.poll_shifts.new.date") %></label>
|
|
||||||
<%= f.select :date,
|
|
||||||
shift_dates_select_options(@polls),
|
|
||||||
prompt: t("admin.poll_shifts.new.select_date"),
|
|
||||||
label: false %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="small-12 medium-4 column">
|
|
||||||
<label><%= t("admin.poll_shifts.new.officer") %></label>
|
|
||||||
<%= f.select :officer_id,
|
|
||||||
officer_select_options(@officers),
|
|
||||||
prompt: t("admin.poll_shifts.new.select_officer"),
|
|
||||||
label: false %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<%= f.hidden_field :booth_id, value: @booth.id %>
|
|
||||||
|
|
||||||
<div class="small-12 medium-4 column">
|
|
||||||
<%= f.submit t("admin.poll_shifts.new.add_assignment"),
|
|
||||||
class: "button expanded hollow margin-top" %>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div id="shifts">
|
<div id="shifts">
|
||||||
<% if @shifts.empty? %>
|
<% if @shifts.empty? %>
|
||||||
<div class="callout primary margin-top">
|
<div class="callout primary margin-top">
|
||||||
<%= t("admin.poll_shifts.new.no_assignments") %>
|
<%= t("admin.poll_shifts.new.no_shifts") %>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render "shifts" %>
|
<%= render "shifts" %>
|
||||||
|
|||||||
1
app/views/admin/poll/shifts/search_officers.js.erb
Normal file
1
app/views/admin/poll/shifts/search_officers.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#search-officers-results").html("<%= j render 'search_officers_results' %>");
|
||||||
@@ -287,7 +287,9 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :booths do
|
resources :booths do
|
||||||
resources :shifts
|
resources :shifts do
|
||||||
|
get :search_officers, on: :collection
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :questions
|
resources :questions
|
||||||
|
|||||||
Reference in New Issue
Block a user