1 class GroundColor < Peta::Element
6 validates :panel_id, :numericality => {:allow_blank => true}
7 validates :code, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
8 validates :orientation, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
9 validates :xy, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
10 validates :wh, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
11 validates :z, :presence => true, :numericality => {:greater_than => 0}
12 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
14 scope :with_panel, -> do
18 scope :find_index, -> do
19 with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
22 scope :find_private, -> (operators) do
23 with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
26 scope :find_by_panel, -> (panel_id) do
27 find_index.where(panel_id: panel_id).references(:panel)
30 scope :find_by_author, -> (author_id) do
31 find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
34 def self.by_author_list_includes
49 self.t = self.panel.new_t
50 self.z = self.panel.new_z
63 wh ? wh : 100 - self.div_offset
67 if self.orientation == 0
75 if self.orientation == 0
83 if self.orientation == 0
91 if self.orientation == 0
98 def style spot = nil, opacity = 20
100 'position' => 'absolute', 'z-index' => self.z,
101 'top' => self.div_y.to_s + '%', 'left' => self.div_x.to_s + '%',
102 'width' => self.div_width.to_s + '%', 'height' => self.div_height.to_s + '%',
103 'background-color' => '#' + format("%06x", self.code)
105 self.merge_opacity(r, opacity) if spot and spot != self
109 def self.public_list_where list
114 {:include => {:panel => {:author => {}} }}
121 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'