creates polling officers from admin

This commit is contained in:
rgarcia
2016-09-14 13:53:35 +02:00
committed by kikito
parent f24ced329f
commit 1ca821c520
19 changed files with 215 additions and 1 deletions

View 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

View File

@@ -19,7 +19,7 @@ module AdminHelper
private
def namespace
controller.class.parent.name.downcase
controller.class.parent.name.downcase.gsub("::", "/")
end
end

View File

@@ -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
View File

@@ -0,0 +1,2 @@
class Poll < ActiveRecord::Base
end

View 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

View File

@@ -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') %>

View File

@@ -0,0 +1 @@
<%= render "admin/menu" %>

View 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>

View 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 %>

View File

@@ -0,0 +1 @@
$("#search-result").html("<%= j render 'officer', officer: @officer %>");

View 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>");