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 def self.list_opt_for_panel
21 def self.show_opt_for_panel
28 def self.json_opt_for_panel
40 self.t = self.panel.new_t
41 self.z = self.panel.new_z
49 def visible? operators
50 return false unless super
51 self.owner_model.visible? operators
59 wh ? wh : 100 - self.div_offset
63 if self.orientation == 0
71 if self.orientation == 0
79 if self.orientation == 0
87 if self.orientation == 0
94 def style spot = nil, opacity = 20
96 'position' => 'absolute', 'z-index' => self.z,
97 'top' => self.div_y.to_s + '%', 'left' => self.div_x.to_s + '%',
98 'width' => self.div_width.to_s + '%', 'height' => self.div_height.to_s + '%',
99 'background-color' => '#' + format("%06x", self.code)
101 self.merge_opacity(r, opacity) if spot and spot != self
110 'ground_colors.updated_at desc'
114 {:panel => {:author => {}} }
117 def self.list_json_opt
118 {:include => {:panel => {:include => {:author => {}}} }}
122 {:include => {:panel => {:author => {}} }}
125 def self.show_json_opt
126 {:include => {:panel => {:include => {:author => {}}} }}
131 self.panel.ground_colors.build(self.attributes)
133 self.panel.ground_colors.each do |ground_color|
134 next unless ground_color == self
135 attr = self.attributes
137 ground_color.attributes = attr
141 self.panel.store({}, operators)
145 self.panel.remove_element(self, operators)
152 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'