2 class Panel < Peta::Root
5 has_many :scroll_panels
7 has_many :panel_pictures, :dependent => :destroy
8 has_many :speech_balloons, :dependent => :destroy
9 has_many :ground_pictures, :dependent => :destroy
10 has_many :ground_colors, :dependent => :destroy
11 accepts_nested_attributes_for :panel_pictures, :allow_destroy => true
12 accepts_nested_attributes_for :speech_balloons, :allow_destroy => true
13 accepts_nested_attributes_for :ground_pictures, :allow_destroy => true
14 accepts_nested_attributes_for :ground_colors, :allow_destroy => true
16 validates :width, :presence => true, :numericality => true, :natural_number => true
17 validates :height, :presence => true, :numericality => true, :natural_number => true
18 validates :border, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
19 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
20 validates :publish, :presence => true, :numericality => true
27 def overwrite operators
28 return false unless operators.author
29 self.author_id = operators.author.id
32 def visible? operators
34 when nil # super return
39 return true if self.new_record?
45 self.visible? operators
54 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px',
55 'border-style' => 'solid', 'border-width' => self.border.to_s + 'px',
56 'border-color' => 'black', 'background-color' => 'white'
60 # ground_picture element template
63 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px'
67 def self.public_list_where list
75 self.child_models.each do |child_model|
76 r.merge!(child_model.show_opt_for_panel)
82 scenario_elements.map { |e|
88 scenario_elements.map { |e|
93 def self.licensed_pictures panels
95 panels.each do |panel|
96 r.merge!(panel.licensed_pictures)
101 def licensed_pictures
103 self.scenario_elements.each do |elm|
104 next unless elm.class.has_picture?
105 r[elm.picture_id] = elm.picture unless r[elm.picture_id]