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
61 62 63 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 61 def area @area ||= current_organization.areas.find_by(id: area_id) end |
#area_updatable? ⇒ Boolean
57 58 59 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 57 def area_updatable? @area_updatable ||= current_user.admin? || context.initiative.created? end |
#available_scopes ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 85 def available_scopes @available_scopes ||= if type.only_global_scope_enabled? type.scopes.where(scope: nil) else type.scopes end end |
#initiative_type ⇒ Object
65 66 67 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 65 def initiative_type @initiative_type ||= type_id ? InitiativesType.find(type_id) : context.initiative.type end |
#map_model(model) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 37 def map_model(model) self.type_id = model.type.id self.scope_id = model.scope&.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
75 76 77 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 75 def scope @scope ||= Scope.find(scope_id) if scope_id.present? end |
#scope_id ⇒ Object
79 80 81 82 83 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 79 def scope_id return nil if type.only_global_scope_enabled? super.presence end |
#scoped_type_id ⇒ Object
69 70 71 72 73 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 69 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
49 50 51 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 49 def signature_type_updatable? state == "created" || state.nil? end |
#state_updatable? ⇒ Boolean
53 54 55 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 53 def state_updatable? false end |
#type ⇒ Object
45 46 47 |
# File 'app/forms/decidim/initiatives/initiative_form.rb', line 45 def type @type ||= type_id ? Decidim::InitiativesType.find(type_id) : context.initiative.type end |