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 655
|
Instance Attribute Details
#id ⇒ String
Returns OSM id for the column.
641 |
# File 'lib/osm/event.rb', line 641 attribute :id, :type => String |
#label ⇒ String
Returns label to display in My.SCOUT (“” prevents display in My.SCOUT).
641 |
# File 'lib/osm/event.rb', line 641 attribute :id, :type => String |
#name ⇒ String
Returns name for the column (displayed in OSM).
641 |
# File 'lib/osm/event.rb', line 641 attribute :id, :type => String |
#parent_required ⇒ Boolean
Returns whether the parent is required to enter something.
641 |
# File 'lib/osm/event.rb', line 641 attribute :id, :type => String |
Instance Method Details
#<=>(another) ⇒ Object
Compare Column based on event then id
713 714 715 716 717 |
# File 'lib/osm/event.rb', line 713 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
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/osm/event.rb', line 691 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
719 720 721 |
# File 'lib/osm/event.rb', line 719 def inspect Osm.inspect_instance(self, ={:replace_with => {'event' => :id}}) end |
#update(api) ⇒ Boolean
Update event column in OSM
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
# File 'lib/osm/event.rb', line 663 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 |