Class: Decidim::Initiatives::InitiativeForm

Inherits:
Form
  • Object
show all
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

Instance Method Details

#areaObject



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

Returns:

  • (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_scopesObject



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_typeObject



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

#scopeObject



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_idObject



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_idObject



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

Returns:

  • (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

Returns:

  • (Boolean)


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

def state_updatable?
  false
end

#typeObject



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