Sha256: 16d5b67ae9b46889fb8567ef404b8ae74165b7cdb74ec8f587de619011148a00
Contents?: true
Size: 1.26 KB
Versions: 5
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true module Decidim module DecidimAwesome module Admin class CreateProposalCustomField < Command include NeedsConstraintHelpers # Public: Initializes the command. # def initialize(organization) @organization = organization @ident = rand(36**8).to_s(36) end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if we couldn't proceed. # # Returns nothing. def call fields = AwesomeConfig.find_or_initialize_by(var: :proposal_custom_fields, organization: @organization) fields.value = {} unless fields.value.is_a? Hash # TODO: prevent (unlikely) colisions with exisiting values fields.value[@ident] = default_definition fields.save! create_constraint_never(:proposal_custom_field) broadcast(:ok, @ident) rescue StandardError => e broadcast(:invalid, e.message) end private def default_definition # '[{"type":"textarea","required":true,"label":"Body","className":"form-control","name":"body","subtype":"textarea"}]' "[]" end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems