app/models/chart.rb in artfully_ose-1.0.0.rc4 vs app/models/chart.rb in artfully_ose-1.1.0.rc1
- old
+ new
@@ -1,26 +1,32 @@
class Chart < ActiveRecord::Base
include Ticket::Foundry
foundry :using => :sections, :with => lambda { { :venue => event.venue.name } }
+ attr_accessor :skip_create_first_section
+ attr_accessible :name, :is_template, :event_id, :organization_id, :old_mongo_id, :sections_attributes, :organization, :event, :skip_create_first_section
- attr_accessible :name, :is_template, :event_id, :organization_id, :old_mongo_id, :sections_attributes, :organization, :event
-
belongs_to :event
belongs_to :organization
has_one :show
has_many :sections, :order => 'price DESC'
accepts_nested_attributes_for :sections, :reject_if => lambda { |a| a[:capacity].blank? }, :allow_destroy => true
- after_create :create_first_section
+
+ after_create :create_first_section, :unless => lambda { @skip_create_first_section == true }
validates :name, :presence => true, :length => { :maximum => 255 }
+ scope :template, where(:is_template => true)
def as_json(options = {})
- super({:methods => ['sections']}.merge(options))
+ h = super(options)
+ h[:sections] = sections.storefront
+ h
end
+
+ def widget_sections
+ self.sections.storefront.all
+ end
- scope :template, where(:is_template => true)
-
# copy! is when they're editing charts and want to create a copy of
# this chart to modify further (weekday and weekend charts)
# This method will copy chart.is_template
def copy!
duplicate(:without => "id", :with => { :name => "#{name} (Copy)" })
@@ -45,11 +51,13 @@
def update_attributes_from_params(params_hash)
#
# HACK: The move to bootstrap left us with currency submission in the form os "DD.CC" which
# Artfully interpreted as DD.00.
# This hack converts DD.CC to DDCC
- #
- params_hash[:sections_attributes].each do |index, section_hash|
+ #
+ params_hash ||= {}
+
+ params_hash.fetch(:sections_attributes, []).each do |index, section_hash|
new_price = Section.price_to_cents(section_hash['price'])
section_hash['price'] = new_price
end
update_attributes(params_hash)