Class: Decidim::Budgets::Admin::ProjectForm

Inherits:
Form show all
Includes:
ApplicationHelper, AttachmentAttributes, TranslatableAttributes, TranslationsHelper
Defined in:
decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb

Overview

This class holds a Form to create/update projects from Decidim's admin panel.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods included from ApplicationHelper

#cell, #edit_link, #extra_admin_link, #html_truncate, #present, #prevent_timeout_seconds, #resolve_presenter_class, #step_cta_url

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amend_button_for, #amenders_list_for, #amendments_enabled?, #amendments_for, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#budgetObject

Finds the Budget from the decidim_budgets_budget_id.

Returns a Decidim::Budgets:Budget


55
56
57
# File 'decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb', line 55

def budget
  @budget ||= context[:budget]
end

#categoryObject

Finds the Category from the decidim_category_id.

Returns a Decidim::Category


62
63
64
# File 'decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb', line 62

def category
  @category ||= categories.find_by(id: decidim_category_id)
end

#decidim_scope_idObject

Scope identifier

Returns the scope identifier related to the project


76
77
78
# File 'decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb', line 76

def decidim_scope_id
  super || scope&.id
end

#map_model(model) ⇒ Object


37
38
39
40
41
42
43
44
# File 'decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb', line 37

def map_model(model)
  self.proposal_ids = model.linked_resources(:proposals, "included_proposals").pluck(:id)
  self.selected = model.selected?

  return unless model.categorization

  self.decidim_category_id = model.categorization.decidim_category_id
end

#proposalsObject


46
47
48
49
50
# File 'decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb', line 46

def proposals
  @proposals ||= Decidim.find_resource_manifest(:proposals).try(:resource_scope, current_component)
                 &.where(id: proposal_ids)
                 &.order(title: :asc)
end

#scopeObject

Finds the Scope from the given decidim_scope_id, uses the component scope if missing.

Returns a Decidim::Scope


69
70
71
# File 'decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb', line 69

def scope
  @scope ||= @attributes["decidim_scope_id"].value ? current_component.scopes.find_by(id: @attributes["decidim_scope_id"].value) : current_component.scope
end