Class: Decidim::Initiatives::Admin::InitiativeForm

Inherits:
Form show all
Includes:
TranslatableAttributes
Defined in:
decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb

Overview

A form object used to show the initiative data in the administration panel.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#areaObject


68
69
70
# File 'decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb', line 68

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

#area_updatable?Boolean

Returns:


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

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

#map_model(model) ⇒ Object


41
42
43
44
45
# File 'decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb', line 41

def map_model(model)
  self.type_id = model.type.id
  self.decidim_scope_id = model.scope&.id
  self.offline_votes = offline_votes.empty? ? zero_offine_votes_with_scopes_names(model) : offline_votes_with_scopes_names(model)
end

#scoped_type_idObject


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

def scoped_type_id
  return unless type && decidim_scope_id

  type.scopes.find_by(decidim_scopes_id: decidim_scope_id.presence).id
end

#signature_type_updatable?Boolean

Returns:


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

def signature_type_updatable?
  @signature_type_updatable ||= begin
    state ||= context.initiative.state
    (state == "validating" && context.current_user.admin?) || state == "created"
  end
end

#state_updatable?Boolean

Returns:


54
55
56
# File 'decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb', line 54

def state_updatable?
  false
end