adds map validations

This commit is contained in:
rgarcia
2017-12-19 20:32:55 +01:00
parent 94445d831a
commit 19a084c0c7
4 changed files with 36 additions and 2 deletions

View File

@@ -104,7 +104,7 @@ module Budgets
def investment_params def investment_params
params.require(:budget_investment) params.require(:budget_investment)
.permit(:title, :description, :external_url, :heading_id, :tag_list, .permit(:title, :description, :external_url, :heading_id, :tag_list,
:organization_name, :location, :terms_of_service, :organization_name, :location, :terms_of_service, :skip_map,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom]) map_location_attributes: [:latitude, :longitude, :zoom])

View File

@@ -80,7 +80,7 @@ class ProposalsController < ApplicationController
def proposal_params def proposal_params
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url,
:responsible_name, :tag_list, :terms_of_service, :geozone_id, :responsible_name, :tag_list, :terms_of_service, :geozone_id, :skip_map,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom]) map_location_attributes: [:latitude, :longitude, :zoom])

View File

@@ -2,8 +2,29 @@ module Mappable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
attr_accessor :skip_map
has_one :map_location, dependent: :destroy has_one :map_location, dependent: :destroy
accepts_nested_attributes_for :map_location, allow_destroy: true accepts_nested_attributes_for :map_location, allow_destroy: true
validate :map_must_be_valid, if: :feature_maps?
def map_must_be_valid
return true if skip_map?
unless map_location.try(:available?)
errors.add(:skip_map, I18n.t('activerecord.errors.models.map_location.attributes.map.invalid'))
end
end
def feature_maps?
Setting["feature.map"].present?
end
def skip_map?
skip_map == "1"
end
end end
end end

View File

@@ -16,4 +16,17 @@
<%= m_l_fields.hidden_field :zoom, <%= m_l_fields.hidden_field :zoom,
value: map_location.zoom, value: map_location.zoom,
id: map_location_input_id(parent_class, 'zoom') %> id: map_location_input_id(parent_class, 'zoom') %>
<div>
<%= form.label :skip_map do %>
<%= form.check_box :skip_map,
title: t("proposals.form.map_skip_checkbox"),
label: false,
class: 'js-toggle-map' %>
<span class="checkbox">
<%= t("proposals.form.map_skip_checkbox") %>
</span>
<% end %>
</div>
<% end %> <% end %>