Class: Decidim::Initiatives::InitiativeForm

Inherits:
Form
  • Object
show all
Includes:
AttachmentAttributes, TranslatableAttributes
Defined in:
decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb

Overview

A form object used to collect the data for a new initiative.

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#areaObject


62
63
64
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 62

def area
  @area ||= current_organization.areas.find_by(id: area_id)
end

#area_updatable?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 52

def area_updatable?
  @area_updatable ||= current_user.admin? || context.initiative.created?
end

#available_scopesObject


70
71
72
73
74
75
76
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 70

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_typeObject


66
67
68
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 66

def initiative_type
  @initiative_type ||= type_id ? InitiativesType.find(type_id) : context.initiative.type
end

#map_model(model) ⇒ Object


39
40
41
42
# File 'decidim-initiatives/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
end

#scopeObject


78
79
80
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 78

def scope
  @scope ||= Scope.find(scope_id) if scope_id.present?
end

#scope_idObject


56
57
58
59
60
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 56

def scope_id
  return nil if initiative_type.only_global_scope_enabled?

  super.presence
end

#scoped_type_idObject


82
83
84
85
86
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 82

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

Returns:

  • (Boolean)

44
45
46
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 44

def signature_type_updatable?
  state == "created" || state.nil?
end

#state_updatable?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'decidim-initiatives/app/forms/decidim/initiatives/initiative_form.rb', line 48

def state_updatable?
  false
end