creates polling officers from admin
This commit is contained in:
32
app/controllers/admin/poll/officers_controller.rb
Normal file
32
app/controllers/admin/poll/officers_controller.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class Admin::Poll::OfficersController < Admin::BaseController
|
||||
load_and_authorize_resource :officer, class: "Poll::Officer"
|
||||
|
||||
def index
|
||||
@officers = @officers.page(params[:page])
|
||||
end
|
||||
|
||||
def search
|
||||
@user = User.find_by(email: params[:email])
|
||||
|
||||
respond_to do |format|
|
||||
if @user
|
||||
@officer = Poll::Officer.find_or_initialize_by(user: @user)
|
||||
format.js
|
||||
else
|
||||
format.js { render "user_not_found" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@officer.user_id = params[:user_id]
|
||||
@officer.save
|
||||
|
||||
redirect_to admin_poll_officers_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@officer.destroy
|
||||
redirect_to admin_poll_officers_path
|
||||
end
|
||||
end
|
||||
@@ -19,7 +19,7 @@ module AdminHelper
|
||||
private
|
||||
|
||||
def namespace
|
||||
controller.class.parent.name.downcase
|
||||
controller.class.parent.name.downcase.gsub("::", "/")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -38,6 +38,7 @@ module Abilities
|
||||
can [:search, :create, :index, :destroy], ::Moderator
|
||||
can [:search, :create, :index, :summary], ::Valuator
|
||||
can [:search, :create, :index, :destroy], ::Manager
|
||||
can [:search, :create, :index, :destroy], ::Poll::Officer
|
||||
|
||||
can :manage, Annotation
|
||||
|
||||
|
||||
2
app/models/poll.rb
Normal file
2
app/models/poll.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Poll < ActiveRecord::Base
|
||||
end
|
||||
8
app/models/poll/officer.rb
Normal file
8
app/models/poll/officer.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Poll
|
||||
class Officer < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
delegate :name, :email, to: :user
|
||||
|
||||
validates :user_id, presence: true, uniqueness: true
|
||||
end
|
||||
end
|
||||
@@ -83,6 +83,12 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= 'class=active' if controller_name == 'officers_controller' %>>
|
||||
<%= link_to admin_poll_officers_path do %>
|
||||
<span class="icon-user"></span><%= t('admin.menu.poll_officers') %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= 'class=active' if controller_name == 'activity' %>>
|
||||
<%= link_to admin_activity_path do %>
|
||||
<span class="icon-eye"></span><%= t('admin.menu.activity') %>
|
||||
|
||||
1
app/views/admin/poll/_menu.html.erb
Normal file
1
app/views/admin/poll/_menu.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render "admin/menu" %>
|
||||
26
app/views/admin/poll/officers/_officer.html.erb
Normal file
26
app/views/admin/poll/officers/_officer.html.erb
Normal file
@@ -0,0 +1,26 @@
|
||||
<div class="small-12 column">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<%= officer.name %>
|
||||
</td>
|
||||
<td>
|
||||
<%= officer.email %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<% if officer.persisted? %>
|
||||
<%= link_to t('admin.poll_officers.officer.delete'),
|
||||
admin_poll_officer_path(officer),
|
||||
method: :delete,
|
||||
class: "button hollow alert" %>
|
||||
<% else %>
|
||||
<%= link_to t('admin.poll_officers.officer.add'),{ controller: "admin/poll/officers", action: :create, user_id: officer.user_id },
|
||||
method: :post,
|
||||
class: "button success" %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
46
app/views/admin/poll/officers/index.html.erb
Normal file
46
app/views/admin/poll/officers/index.html.erb
Normal file
@@ -0,0 +1,46 @@
|
||||
<h2><%= t("admin.poll_officers.index.title") %></h2>
|
||||
|
||||
<div class="row">
|
||||
<%= form_tag search_admin_poll_officers_path, method: :get, remote: true do %>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :email, '', placeholder: t('admin.poll_officers.search.email_placeholder') %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= submit_tag t('admin.poll_officers.search.search'), class: 'button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="search-result" class="row"></div>
|
||||
|
||||
<h3><%= page_entries_info @officers %></h3>
|
||||
|
||||
<table id="officers">
|
||||
<% @officers.each do |officer| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= officer.name %>
|
||||
</td>
|
||||
<td>
|
||||
<%= officer.email %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<% if officer.persisted? %>
|
||||
<%= link_to t('admin.poll_officers.officer.delete'),
|
||||
admin_poll_officer_path(officer),
|
||||
method: :delete,
|
||||
class: "button hollow alert"
|
||||
%>
|
||||
<% else %>
|
||||
<%= link_to t('admin.poll_officers.officer.add'),
|
||||
{ controller: "admin/poll/officers", action: :create,
|
||||
user_id: officer.user_id },
|
||||
method: :post,
|
||||
class: "button success" %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @officers %>
|
||||
1
app/views/admin/poll/officers/search.js.erb
Normal file
1
app/views/admin/poll/officers/search.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-result").html("<%= j render 'officer', officer: @officer %>");
|
||||
1
app/views/admin/poll/officers/user_not_found.js.erb
Normal file
1
app/views/admin/poll/officers/user_not_found.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-result").html("<div class=\"small-12 column\"><div class=\"callout alert\"><%= j t('admin.officers.search.user_not_found') %></div></div>");
|
||||
Reference in New Issue
Block a user