Class: Osm::Event::Column
- Defined in:
- lib/osm/event.rb,
lib/osm/event.rb
Overview
Ensure the constant exists for the validators
Instance Attribute Summary collapse
-
#id ⇒ String
OSM id for the column.
-
#label ⇒ String
Label to display in My.SCOUT (“” prevents display in My.SCOUT).
-
#name ⇒ String
Name for the column (displayed in OSM).
-
#parent_required ⇒ Boolean
Whether the parent is required to enter something.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Column based on event then id.
-
#delete(api) ⇒ Boolean
Delete event column from OSM.
-
#initialize ⇒ Object
constructor
Initialize a new Column.
- #inspect ⇒ Object
-
#update(api) ⇒ Boolean
Update event column in OSM.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Column
|
# File 'lib/osm/event.rb', line 441
|
Instance Attribute Details
#id ⇒ String
Returns OSM id for the column.
429 |
# File 'lib/osm/event.rb', line 429 attribute :id, :type => String |
#label ⇒ String
Returns label to display in My.SCOUT (“” prevents display in My.SCOUT).
429 |
# File 'lib/osm/event.rb', line 429 attribute :id, :type => String |
#name ⇒ String
Returns name for the column (displayed in OSM).
429 |
# File 'lib/osm/event.rb', line 429 attribute :id, :type => String |
#parent_required ⇒ Boolean
Returns whether the parent is required to enter something.
429 |
# File 'lib/osm/event.rb', line 429 attribute :id, :type => String |
Instance Method Details
#<=>(another) ⇒ Object
Compare Column based on event then id
499 500 501 502 503 |
# File 'lib/osm/event.rb', line 499 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
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/osm/event.rb', line 477 def delete(api) require_ability_to(api, :write, :events, event.section_id) data = api.perform_query("events.php?action=deleteColumn§ionid=#{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 |
#inspect ⇒ Object
505 506 507 |
# File 'lib/osm/event.rb', line 505 def inspect Osm.inspect_instance(self, ={:replace_with => {'event' => :id}}) end |
#update(api) ⇒ Boolean
Update event column in OSM
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/osm/event.rb', line 449 def update(api) require_ability_to(api, :write, :events, event.section_id) data = api.perform_query("events.php?action=renameColumn§ionid=#{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 |