Sha256: 6e2ef1417aa55e8da78f6d6c16db68aea1c6e8ce9e1542bcb422886c8e3590da

Contents?: true

Size: 1.67 KB

Versions: 28

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # A form object to be used when admin users want to create a proposal.
      class ProposalForm < Decidim::Form
        mimic :proposal

        attribute :title, String
        attribute :body, String
        attribute :address, String
        attribute :latitude, Float
        attribute :longitude, Float
        attribute :category_id, Integer
        attribute :scope_id, Integer
        attribute :attachment, AttachmentForm

        validates :title, :body, presence: true
        validates :address, geocoding: true, if: -> { current_feature.settings.geocoding_enabled? }
        validates :category, presence: true, if: ->(form) { form.category_id.present? }
        validates :scope, presence: true, if: ->(form) { form.scope_id.present? }

        delegate :categories, to: :current_feature, prefix: false

        def map_model(model)
          return unless model.categorization

          self.category_id = model.categorization.decidim_category_id
        end

        def organization_scopes
          current_organization.scopes
        end

        def process_scope
          current_feature.participatory_space.scope
        end

        alias feature current_feature

        # Finds the Category from the category_id.
        #
        # Returns a Decidim::Category
        def category
          @category ||= categories.where(id: category_id).first
        end

        # Finds the Scope from the scope_id.
        #
        # Returns a Decidim::Scope
        def scope
          @scope ||= organization_scopes.where(id: scope_id).first || process_scope
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
decidim-proposals-0.8.4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.8.3 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.8.2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.8.1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.8.0 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.7.4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.7.3 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.7.2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.7.1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.7.0 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.6.8 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-0.6.8 decidim-proposals/app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.6.7 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-0.6.7 decidim-proposals/app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.6.6 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-0.6.6 decidim-proposals/app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.6.5 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-0.6.5 decidim-proposals/app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.6.4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-0.6.4 decidim-proposals/app/forms/decidim/proposals/admin/proposal_form.rb