Merge branch 'master' into legislation-module-stable

This commit is contained in:
Amaia Castro
2016-12-15 11:26:22 +01:00
16 changed files with 355 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
class Admin::GeozonesController < Admin::BaseController
respond_to :html
load_and_authorize_resource
def index
@geozones = Geozone.all.order("LOWER(name)")
end
def new
end
def edit
end
def create
@geozone = Geozone.new(geozone_params)
if @geozone.save
redirect_to admin_geozones_path
else
render :new
end
end
def update
if @geozone.update(geozone_params)
redirect_to admin_geozones_path
else
render :edit
end
end
def destroy
if @geozone.safe_to_destroy?
@geozone.destroy
redirect_to admin_geozones_path, notice: t('admin.geozones.delete.success')
else
redirect_to admin_geozones_path, flash: { error: t('admin.geozones.delete.error') }
end
end
private
def geozone_params
params.require(:geozone).permit(:name, :external_code, :census_code, :html_map_coordinates)
end
end

View File

@@ -44,6 +44,8 @@ module Abilities
can [:read, :update, :destroy, :summary], SpendingProposal
can [:search, :edit, :update, :create, :index, :destroy], Banner
can [:index, :create, :edit, :update, :destroy], Geozone
can [:manage], ::Legislation::Process
can [:manage], ::Legislation::DraftVersion
end

View File

@@ -1,9 +1,17 @@
class Geozone < ActiveRecord::Base
has_many :proposals
has_many :spending_proposals
has_many :debates
has_many :users
validates :name, presence: true
def self.names
Geozone.pluck(:name)
end
def safe_to_destroy?
Geozone.reflect_on_all_associations(:has_many).all? do |association|
association.klass.where(geozone: self).empty?
end
end
end

View File

@@ -91,6 +91,12 @@
<% end %>
</li>
<li <%= 'class=active' if controller_name == 'geozones' %>>
<%= link_to admin_geozones_path do %>
<span class="icon-settings"></span><%= t('admin.menu.geozones') %>
<% 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,15 @@
<% if @geozone.errors.any? %>
<div id="error_explanation" data-alert class="callout alert" data-closable>
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
<span aria-hidden="true">&times;</span>
</button>
<strong>
<%= @geozone.errors.count %>
<%= t("admin.geozones.errors.form.error", count: @geozone.errors.count) %>
</strong>
</div>
<% end %>

View File

@@ -0,0 +1,29 @@
<%= form_for [:admin, @geozone] do |f| %>
<%= render 'errors' %>
<div clas="row">
<div class="small-12 medium-6 large-4 column">
<%= f.label :name, t("admin.geozones.geozone.name") %>
<%= f.text_field :name, label: false %>
</div>
<div class="small-12 medium-6 large-4 column">
<%= f.label :html_map_coordinates, t("admin.geozones.geozone.coordinates") %>
<%= f.text_field :html_map_coordinates, label: false %>
</div>
<div class="small-12 medium-6 large-2 column">
<%= f.label :external_code, t("admin.geozones.geozone.external_code") %>
<%= f.text_field :external_code, label: false %>
</div>
<div class="small-12 medium-6 large-2 column">
<%= f.label :census_code, t("admin.geozones.geozone.census_code") %>
<%= f.text_field :census_code, label: false %>
</div>
</div>
<div class="row">
<div class="actions small-12 large-3 medium-3 column">
<%= f.submit(class: "button expanded", value: t("admin.geozones.edit.form.submit_button")) %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,13 @@
<div class="row">
<div class="small-12 column">
<%= link_to admin_geozones_path, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("admin.geozones.edit.back") %>
<% end %>
<h1><%= t("admin.geozones.edit.editing") %></h1>
<%= render "form" %>
</div>
</div>

View File

@@ -0,0 +1,33 @@
<%= link_to t("admin.geozones.index.create"),
new_admin_geozone_path, class: "button success float-right" %>
<h2 class="inline-block"><%= t("admin.geozones.index.title") %></h2>
<table>
<thead>
<tr>
<th><%= t("admin.geozones.geozone.name") %></th>
<th><%= t("admin.geozones.geozone.external_code") %></th>
<th><%= t("admin.geozones.geozone.census_code") %></th>
<th><%= t("admin.geozones.geozone.coordinates") %></th>
<th colspan="2"></th>
</tr>
</thead>
<tbody>
<% @geozones.each do |geozone| %>
<tr id="<%= dom_id(geozone) %>">
<td><%= geozone.name %></td>
<td><%= geozone.external_code %></td>
<td><%= geozone.census_code %></td>
<td><%= geozone.html_map_coordinates %></td>
<td>
<%= link_to t("admin.geozones.index.edit"), edit_admin_geozone_path(geozone), class: 'edit-banner button hollow' %>
</td>
<td>
<%= link_to t("admin.geozones.index.delete"), admin_geozone_path(geozone), method: :delete, class: 'button hollow alert' %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,13 @@
<div class="geozone-new row">
<div class="small-12 column">
<%= link_to admin_geozones_path, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("admin.geozones.new.back") %>
<% end %>
<h1><%= t("admin.geozones.new.creating") %></h1>
<%= render "form" %>
</div>
</div>