1 class GroundColor < Peta::Element
7 validates :panel_id, :numericality => {:allow_blank => true}
8 validates :code, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
9 validates :orientation, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
10 validates :xy, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
11 validates :wh, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
12 validates :z, :presence => true, :numericality => {:greater_than => 0}
13 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
15 def self.list_opt_for_panel
22 def self.show_opt_for_panel
29 def self.json_opt_for_panel
41 self.t = self.panel.new_t
42 self.z = self.panel.new_z
50 def visible? operators
51 return false unless super
52 self.owner_model.visible? operators
60 wh ? wh : 100 - self.div_offset
64 if self.orientation == 0
72 if self.orientation == 0
80 if self.orientation == 0
88 if self.orientation == 0
95 def style spot = nil, opacity = 20
97 'position' => 'absolute', 'z-index' => self.z,
98 'top' => self.div_y.to_s + '%', 'left' => self.div_x.to_s + '%',
99 'width' => self.div_width.to_s + '%', 'height' => self.div_height.to_s + '%',
100 'background-color' => '#' + format("%06x", self.code)
102 self.merge_opacity(r, opacity) if spot and spot != self
111 'ground_colors.updated_at desc'
115 {:panel => {:author => {}} }
118 def self.list_json_opt
119 {:include => {:panel => {:include => {:author => {}}} }}
123 {:include => {:panel => {:author => {}} }}
126 def self.show_json_opt
127 {:include => {:panel => {:include => {:author => {}}} }}
132 self.panel.ground_colors.build(self.attributes)
134 self.panel.ground_colors.each do |ground_color|
135 next unless ground_color == self
136 attr = self.attributes
138 ground_color.attributes = attr
142 self.panel.store({}, operators)
146 self.panel.remove_element(self, operators)
153 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'