Class: Osm::Event::Column

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/event.rb,
lib/osm/event.rb

Overview

Ensure the constant exists for the validators

Constant Summary collapse

SORT_BY =
[:event, :id]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Constructor Details

#initializeObject

Initialize a new Column

Parameters:

  • attributes (Hash)

    The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)



# File 'lib/osm/event.rb', line 659

Instance Attribute Details

#idString

Returns OSM id for the column.

Returns:

  • (String)

    OSM id for the column



645
# File 'lib/osm/event.rb', line 645

attribute :id, :type => String

#labelString

Returns label to display in My.SCOUT (“” prevents display in My.SCOUT).

Returns:

  • (String)

    label to display in My.SCOUT (“” prevents display in My.SCOUT)



645
# File 'lib/osm/event.rb', line 645

attribute :id, :type => String

#nameString

Returns name for the column (displayed in OSM).

Returns:

  • (String)

    name for the column (displayed in OSM)



645
# File 'lib/osm/event.rb', line 645

attribute :id, :type => String

#parent_requiredBoolean

Returns whether the parent is required to enter something.

Returns:

  • (Boolean)

    whether the parent is required to enter something



645
# File 'lib/osm/event.rb', line 645

attribute :id, :type => String

Instance Method Details

#delete(api) ⇒ Boolean

Delete event column from OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Boolean)

    whether the delete succedded



695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/osm/event.rb', line 695

def delete(api)
  require_ability_to(api, :write, :events, event.section_id)

  data = api.perform_query("events.php?action=deleteColumn&sectionid=#{event.section_id}&eventid=#{event.id}", {
    'columnId' => id
  })

  (ActiveSupport::JSON.decode(data['config']) || []).each do |i|
    return false if i['id'] == id
  end

  new_columns = []
  event.columns.each do |column|
    new_columns.push(column) unless column == self
  end
  event.columns = new_columns

  cache_write(api, ['event', event.id], event)
  return true
end

#inspectObject



716
717
718
# File 'lib/osm/event.rb', line 716

def inspect
  Osm.inspect_instance(self, options={:replace_with => {'event' => :id}})
end

#update(api) ⇒ Boolean

Update event column in OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Boolean)

    if the operation suceeded or not



667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/osm/event.rb', line 667

def update(api)
  require_ability_to(api, :write, :events, event.section_id)

  data = api.perform_query("events.php?action=renameColumn&sectionid=#{event.section_id}&eventid=#{event.id}", {
    'columnId' => id,
    'columnName' => name,
    'pL' => label,
    'pR' => (parent_required ? 1 : 0),
  })

  (ActiveSupport::JSON.decode(data['config']) || []).each do |i|
    if i['id'] == id
      if i['name'].eql?(name) && (i['pL'].nil? || i['pL'].eql?(label)) && (i['pR'].eql?('1') == parent_required)
        reset_changed_attributes
          # The cached event will be out of date - remove it
          cache_delete(api, ['event', event.id])
          # The cached event attedance will be out of date
          cache_delete(api, ['event_attendance', event.id])
        return true
      end
    end
  end
  return false
end