adds map validations
This commit is contained in:
@@ -104,7 +104,7 @@ module Budgets
|
||||
def investment_params
|
||||
params.require(:budget_investment)
|
||||
.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],
|
||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||
map_location_attributes: [:latitude, :longitude, :zoom])
|
||||
|
||||
@@ -80,7 +80,7 @@ class ProposalsController < ApplicationController
|
||||
|
||||
def proposal_params
|
||||
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],
|
||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||
map_location_attributes: [:latitude, :longitude, :zoom])
|
||||
|
||||
@@ -2,8 +2,29 @@ module Mappable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
attr_accessor :skip_map
|
||||
|
||||
has_one :map_location, dependent: :destroy
|
||||
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
|
||||
|
||||
@@ -16,4 +16,17 @@
|
||||
<%= m_l_fields.hidden_field :zoom,
|
||||
value: map_location.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 %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user