Method: Osm::Event#add_column

Defined in:
lib/osm/event.rb

#add_column(api, name, label = '', required = false) ⇒ Boolean

Add a column to the event in OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

  • label (String) (defaults to: '')

    The label for the field in OSM

  • name (String)

    The label for the field in My.SCOUT (if this is blank then parents can’t edit it)

  • required (Boolean) (defaults to: false)

    Whether the parent is required to enter something

Returns:

  • (Boolean)

    whether the update succedded

Raises:



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/osm/event.rb', line 450

def add_column(api, name, label='', required=false)
  require_ability_to(api, :write, :events, section_id)
  raise Osm::ArgumentIsInvalid, 'name is invalid' if name.blank?

  data = api.perform_query("events.php?action=addColumn&sectionid=#{section_id}&eventid=#{id}", {
    'columnName' => name,
    'parentLabel' => label,
    'parentRequire' => (required ? 1 : 0),
  })

  # The cached events for the section will be out of date - remove them
  cache_delete(api, ['events', section_id])
  cache_delete(api, ['event', id])
  cache_delete(api, ['event_attendance', id])

  self.columns = self.class.new_event_from_data(data).columns

  return data.is_a?(Hash) && (data['eventid'].to_i == id)
end