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

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

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#areaObject


88
89
90
# File 'decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb', line 88

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

#area_updatable?Boolean

Returns:

  • (Boolean)

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

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

#map_model(model) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb', line 43

def map_model(model)
  self.type_id = model.type.id
  self.decidim_scope_id = model.scope&.id
  self.offline_votes = model.offline_votes

  if offline_votes.empty?
    self.offline_votes = model.votable_initiative_type_scopes.each_with_object({}) do |initiative_scope_type, all_votes|
      all_votes[initiative_scope_type.decidim_scopes_id || "global"] = [0, initiative_scope_type.scope_name]
    end
  else
    offline_votes.delete("total")
    self.offline_votes = offline_votes.each_with_object({}) do |(decidim_scope_id, votes), all_votes|
      scope_name = model.votable_initiative_type_scopes.find do |initiative_scope_type|
        initiative_scope_type.global_scope? && decidim_scope_id == "global" ||
          initiative_scope_type.decidim_scopes_id == decidim_scope_id.to_i
      end.scope_name

      all_votes[decidim_scope_id || "global"] = [votes, scope_name]
    end
  end
end

#scoped_type_idObject


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

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

rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity

Returns:

  • (Boolean)

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

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:

  • (Boolean)

74
75
76
# File 'decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb', line 74

def state_updatable?
  false
end