Class: Decidim::Initiatives::InitiativeForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Initiatives::InitiativeForm
- Includes:
- AttachmentAttributes, TranslatableAttributes
- Defined in:
- app/forms/decidim/initiatives/initiative_form.rb
Overview
A form object used to collect the data for a new initiative.
Instance Method Summary collapse
- #area ⇒ Object
- #area_updatable? ⇒ Boolean
- #available_scopes ⇒ Object
- #initiative_type ⇒ Object
- #map_model(model) ⇒ Object
- #scope ⇒ Object
- #scope_id ⇒ Object
- #scoped_type_id ⇒ Object
- #signature_type_updatable? ⇒ Boolean
- #state_updatable? ⇒ Boolean
Instance Method Details
#area ⇒ Object
65 66 67 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 65 def area @area ||= current_organization.areas.find_by(id: area_id) end |
#area_updatable? ⇒ Boolean
55 56 57 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 55 def area_updatable? @area_updatable ||= current_user.admin? || context.initiative.created? end |
#available_scopes ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 73 def available_scopes @available_scopes ||= if initiative_type.only_global_scope_enabled? initiative_type.scopes.where(scope: nil) else initiative_type.scopes end end |
#initiative_type ⇒ Object
69 70 71 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 69 def initiative_type @initiative_type ||= type_id ? InitiativesType.find(type_id) : context.initiative.type end |
#map_model(model) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 39 def map_model(model) self.type_id = model.type.id self.scope_id = model.scope&.id self.signature_type = model.signature_type self.title = translated_attribute(model.title) self.description = translated_attribute(model.description) end |
#scope ⇒ Object
81 82 83 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 81 def scope @scope ||= Scope.find(scope_id) if scope_id.present? end |
#scope_id ⇒ Object
59 60 61 62 63 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 59 def scope_id return nil if initiative_type.only_global_scope_enabled? super.presence end |
#scoped_type_id ⇒ Object
85 86 87 88 89 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 85 def scoped_type_id return unless type && scope_id type.scopes.find_by(decidim_scopes_id: scope_id.presence).id end |
#signature_type_updatable? ⇒ Boolean
47 48 49 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 47 def signature_type_updatable? state == "created" || state.nil? end |
#state_updatable? ⇒ Boolean
51 52 53 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 51 def state_updatable? false end |