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

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 663

Instance Attribute Details

#idString

Returns OSM id for the column.

Returns:

  • (String)

    OSM id for the column


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

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)


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

attribute :id, :type => String

#nameString

Returns name for the column (displayed in OSM).

Returns:

  • (String)

    name for the column (displayed in OSM)


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

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


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

attribute :id, :type => String

Instance Method Details

#<=>(another) ⇒ Object

Compare Column based on event then id


721
722
723
724
725
# File 'lib/osm/event.rb', line 721

def <=>(another)
  result = self.event <=> another.try(:event)
  result = self.id <=> another.try(:id) if result == 0
  return result
end

#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


699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/osm/event.rb', line 699

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


727
728
729
# File 'lib/osm/event.rb', line 727

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


671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/osm/event.rb', line 671

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