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
- #type ⇒ Object
Instance Method Details
#area ⇒ Object
64 65 66 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 64 def area @area ||= current_organization.areas.find_by(id: area_id) end |
#area_updatable? ⇒ Boolean
60 61 62 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 60 def area_updatable? @area_updatable ||= current_user.admin? || context.initiative.created? end |
#available_scopes ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 88 def available_scopes @available_scopes ||= if type.only_global_scope_enabled? type.scopes.where(scope: nil) else type.scopes end end |
#initiative_type ⇒ Object
68 69 70 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 68 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 46 |
# 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.decidim_user_group_id = model.decidim_user_group_id self.signature_type = model.signature_type || initiative_type.signature_type self.title = translated_attribute(model.title) self.description = translated_attribute(model.description) end |
#scope ⇒ Object
78 79 80 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 78 def scope @scope ||= Scope.find(scope_id) if scope_id.present? end |
#scope_id ⇒ Object
82 83 84 85 86 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 82 def scope_id return nil if type.only_global_scope_enabled? super.presence end |
#scoped_type_id ⇒ Object
72 73 74 75 76 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 72 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
52 53 54 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 52 def signature_type_updatable? state == "created" || state.nil? end |
#state_updatable? ⇒ Boolean
56 57 58 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 56 def state_updatable? false end |
#type ⇒ Object
48 49 50 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 48 def type @type ||= type_id ? Decidim::InitiativesType.find(type_id) : context.initiative.type end |