Sha256: 8217cb475ddd6e187dbbe48ac6c19ad90cfafe78d7cda8a83554e00c072e6b0a
Contents?: true
Size: 1.41 KB
Versions: 6
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true module Decidim module Budgets module Admin # This class holds a Form to create/update budgets from Decidim's admin panel. class BudgetForm < Decidim::Form include TranslatableAttributes mimic :budget translatable_attribute :title, String attribute :weight, Integer, default: 0 translatable_attribute :description, String attribute :total_budget, Integer, default: 0 attribute :decidim_scope_id, Integer validates :title, translatable_presence: true validates :weight, numericality: { greater_than_or_equal_to: 0 } validates :total_budget, numericality: { greater_than: 0 } validates :scope, presence: true, if: ->(form) { form.decidim_scope_id.present? } validates :decidim_scope_id, scope_belongs_to_component: true, if: ->(form) { form.decidim_scope_id.present? } # Finds the Scope from the given decidim_scope_id, uses the component scope if missing. # # Returns a Decidim::Scope def scope @scope ||= @attributes["decidim_scope_id"].value ? current_component.scopes.find_by(id: @attributes["decidim_scope_id"].value) : current_component.scope end # Scope identifier # # Returns the scope identifier related to the meeting def decidim_scope_id super || scope&.id end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems