From: yasushiito Date: Thu, 1 Aug 2013 09:50:15 +0000 (+0900) Subject: t#31772:element lib X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4a6e0f4d50891db192d5f477f61b7448c1d90a02;p=pettanr%2Fpettanr.git t#31772:element lib --- diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index 057d1d04..0e27aba9 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -65,7 +65,19 @@ class GroundColor < ActiveRecord::Base def opt_div_style spot = nil, opacity = 20 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : '' - "position: absolute; width:#{self.panel.width}px; height:#{self.panel.height}px; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}" + "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}" + end + + def new_panel + @new_panel + end + + def new_panel= v + @new_panel = v + end + + def get_panel + self.panel || @new_panel end def tag_id c = nil @@ -77,7 +89,7 @@ class GroundColor < ActiveRecord::Base end def tag_panel_id - self.panel.new_record? ? '0' : self.panel.id.to_s + self.get_panel.new_record? ? '0' : self.get_panel.id.to_s end def tag_element_id diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index 50428685..3562d32d 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -75,7 +75,7 @@ class GroundPicture < ActiveRecord::Base def opt_div_style full_url, spot = nil, opacity = 20 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : '' - "position: absolute; width:#{self.panel.width}px; height:#{self.panel.height}px; top: 0px; left: 0px; z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px #{self.y}px; #{o}" + "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; top: 0px; left: 0px; z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px #{self.y}px; #{o}" end def tmb_opt_img_tag @@ -83,6 +83,18 @@ class GroundPicture < ActiveRecord::Base {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption} end + def new_panel + @new_panel + end + + def new_panel= v + @new_panel = v + end + + def get_panel + self.panel || @new_panel + end + def tag_id c = nil 'panel' + tag_panel_id + 'ground_picture' + tag_element_id + c.to_s end @@ -92,7 +104,7 @@ class GroundPicture < ActiveRecord::Base end def tag_panel_id - self.panel.new_record? ? '0' : self.panel.id.to_s + self.get_panel.new_record? ? '0' : self.get_panel.id.to_s end def tag_element_id diff --git a/app/models/panel.rb b/app/models/panel.rb index c64dfdd2..919443bc 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -321,6 +321,9 @@ class Panel < ActiveRecord::Base self.overwrite au res = false Panel.transaction do + self.panel_elements.each do |elm| + elm.new_panel = self + end #self.publish = nil res = self.save unless validate_child @@ -367,11 +370,9 @@ class Panel < ActiveRecord::Base def copy attr = self.copy_attributes - attr.merge! PanelPicture.panelize(self.panel_pictures.map {|elm| elm.copy_attributes}) - attr.merge! SpeechBalloon.panelize(self.speech_balloons.map {|elm| elm.copy_attributes}) - attr.merge! GroundPicture.panelize(self.ground_pictures.map {|elm| elm.copy_attributes}) - attr.merge! GroundColor.panelize(self.ground_colors.map {|elm| elm.copy_attributes}) - p attr + Panel.each_element_class_names do |n| + attr.merge! Panel.class_name_to_class(n).panelize(self.elements_by_class_name(n).map {|elm| elm.copy_attributes}) + end attr end diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 64f990ca..69171d15 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -107,6 +107,18 @@ class PanelPicture < ActiveRecord::Base {:src => self.url, :width => tw, :height => th, :alt => self.caption} end + def new_panel + @new_panel + end + + def new_panel= v + @new_panel = v + end + + def get_panel + self.panel || @new_panel + end + def tag_id c = nil 'panel' + tag_panel_id + 'panel_picture' + tag_element_id + c.to_s end @@ -116,7 +128,7 @@ class PanelPicture < ActiveRecord::Base end def tag_panel_id - self.panel.new_record? ? '0' : self.panel.id.to_s + self.get_panel.new_record? ? '0' : self.get_panel.id.to_s end def tag_element_id diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index 421127b3..decaf8fe 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -68,6 +68,18 @@ class SpeechBalloon < ActiveRecord::Base self.panel.visible? roles end + def new_panel + @new_panel + end + + def new_panel= v + @new_panel = v + end + + def get_panel + self.panel || @new_panel + end + def tag_id c = nil 'panel' + tag_panel_id + 'speech_balloon' + tag_element_id + c.to_s end @@ -77,7 +89,7 @@ class SpeechBalloon < ActiveRecord::Base end def tag_panel_id - self.panel.new_record? ? '0' : self.panel.id.to_s + self.get_panel.new_record? ? '0' : self.get_panel.id.to_s end def tag_element_id diff --git a/app/views/panels/_body.html.erb b/app/views/panels/_body.html.erb index ad023e55..a25be020 100644 --- a/app/views/panels/_body.html.erb +++ b/app/views/panels/_body.html.erb @@ -17,9 +17,7 @@ <% end %> <% end %>
- <% unless panel.new_record? %> <% panel.panel_elements.each do |elm| %> <%= render elm.class.to_s.tableize + '/element', :elm => elm, :spot => spot %> <% end %> - <% end %>
diff --git a/app/views/panels/_form.html.erb b/app/views/panels/_form.html.erb index 5b552f34..6f0fb222 100644 --- a/app/views/panels/_form.html.erb +++ b/app/views/panels/_form.html.erb @@ -36,7 +36,6 @@ <% end %> -<% unless panel.new_record? %>
    @@ -124,7 +123,6 @@
-<% end %>