class Ecoportal::API::V2::Page::Component::PeopleField
Public Instance Methods
add(*ids)
click to toggle source
Attaches people
# File lib/ecoportal/api/v2/page/component/people_field.rb, line 24 def add(*ids) people_ids << ids end
add_viewable(field_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
click to toggle source
Adds a field to the `viewable_fields`
# File lib/ecoportal/api/v2/page/component/people_field.rb, line 34 def add_viewable(field_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED) viewable_fields.upsert!({"id" => field_id}, pos: pos, before: before, after: after) end
configure(*conf)
click to toggle source
Quick config helper @param conf [Symbol, Array<Symbol>]
- `:snapshot` to set mode to `snapshot` - `:live` to set mode to `live` - `:me_button` to display `ME` button - `:permits` to define the permissions - `:all` for _entire page/all stages_ - `:stages` for _all stages containing this field_ - `:page` for _page only_ - `:stage` for _only the stage containing this field when attached_ - `:restructure` - `:configure` - `:can_permission` - `:create_actions` - `:admin_actions` - `:subscribed` - `:subscribed_to_tasks` - `requires: number` to fine the number of required people to be attached
Calls superclass method
Ecoportal::API::V2::Page::Component#configure
# File lib/ecoportal/api/v2/page/component/people_field.rb, line 61 def configure(*conf) conf.each_with_object([]) do |cnf, unused| case cnf when :snapshot self.attach_mode = "snapshot" when :live self.attach_mode = "live" when :me_button self.is_me_button = true when :singular self.singular = true when Hash supported = [:singular, :permits, :requires] unless (rest = hash_except(cnf.dup, *supported)).empty? unused.push(rest) end if cnf.key?(:singular) then self.singular = !!cnf[:singular] end if cnf.key?(:permits) if permits = cnf[:permits] self.attached_people_permissions_enabled = true configure_permits(*[permits].flatten.compact) else self.attached_people_permissions_enabled = false end end if cnf.key?(:requires) self.singular = false if requires = cnf[:requires] self.required = true self.requires_number = requires else self.required = false self.requires_number = nil end end else unused.push(cnf) end end.yield_self do |unused| super(*unused) end end
delete(*ids)
click to toggle source
Deletes people
# File lib/ecoportal/api/v2/page/component/people_field.rb, line 29 def delete(*ids) people_ids.reject! {|id| ids.include?(id)} end
delete_viewable(field_id)
click to toggle source
Deletes a field from the `viewable_fields`
# File lib/ecoportal/api/v2/page/component/people_field.rb, line 39 def delete_viewable(field_id) viewable_fields.delete!(field_id) end
Private Instance Methods
configure_permits(*conf)
click to toggle source
# File lib/ecoportal/api/v2/page/component/people_field.rb, line 107 def configure_permits(*conf) conf.each_with_object([]) do |cnf, flags| case cnf when :all self.apply_attached_people_permissions_to = "page" when :stages self.apply_attached_people_permissions_to = "all_stages" when :page self.apply_attached_people_permissions_to = "page_only" when :stage self.apply_attached_people_permissions_to = "current_stage" when :can_edit self.attached_people_permissions_editable = true else flags.push(cnf) end end.yield_self do |flags| self.attached_people_permissions_flags.configure *flags end end