From 49980c47694407ce0be539e35379835f910d7895 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Sun, 9 Jun 2013 07:08:34 +0900 Subject: [PATCH] t#31533:add default t,z --- app/controllers/ground_colors_controller.rb | 8 +++++--- app/models/ground_color.rb | 5 +++++ app/models/ground_picture.rb | 6 +++++- app/models/panel.rb | 10 +++++++++- app/models/panel_picture.rb | 24 ++++++++++-------------- app/models/speech_balloon.rb | 10 ++++++++++ app/views/ground_pictures/_form.html.erb | 1 - 7 files changed, 44 insertions(+), 20 deletions(-) diff --git a/app/controllers/ground_colors_controller.rb b/app/controllers/ground_colors_controller.rb index c74e9309..5b94a644 100644 --- a/app/controllers/ground_colors_controller.rb +++ b/app/controllers/ground_colors_controller.rb @@ -31,9 +31,10 @@ class GroundColorsController < ApplicationController end def new - @ground_color = GroundColor.new params[:ground_color] - @ground_color.supply_default + @ground_color = GroundColor.new @panel = @author.working_panel + @ground_color.panel_id = @panel.id + @ground_color.supply_default respond_to do |format| format.html @@ -52,8 +53,9 @@ class GroundColorsController < ApplicationController def create @ground_color = GroundColor.new params[:ground_color] - @ground_color.supply_default @panel = Panel.edit(@author.working_panel, @author) + @ground_color.panel_id = @panel.id + @ground_color.supply_default @ground_color.overwrite @panel.id respond_to do |format| diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index d17af253..95a80ffa 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -17,6 +17,11 @@ class GroundColor < ActiveRecord::Base end def supply_default + self.code = 0 + if self.panel + self.t = self.panel.new_t + self.z = self.panel.new_z + end end def overwrite pid diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index d4ff1ba0..67cc2c42 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -22,9 +22,13 @@ class GroundPicture < ActiveRecord::Base end def supply_default - self.repeat = 0 self.x = 0 self.y = 0 + self.repeat = 0 + if self.panel + self.t = self.panel.new_t + self.z = self.panel.new_z + end end def overwrite diff --git a/app/models/panel.rb b/app/models/panel.rb index a0481581..89589780 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -214,6 +214,14 @@ class Panel < ActiveRecord::Base '[' + ary.map {|i| i.panel_elements_as_json }.join(',') + ']' end + def new_t + self.parts.size + end + + def new_z + self.parts.size + 1 + end + def scenario panel_elements.map { |e| e.scenario @@ -301,7 +309,7 @@ class Panel < ActiveRecord::Base def destroy_with_elements res = false Panel.transaction do - self.panel_elements.each do |element| + self.parts_element.each do |element| raise ActiveRecord::Rollback unless element.destroy end raise ActiveRecord::Rollback unless self.destroy diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index b459e6f3..ba599206 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -32,12 +32,16 @@ class PanelPicture < ActiveRecord::Base end def supply_default - self.x = 0 if self.x.blank? - self.y = 0 if self.y.blank? - self.width = self.picture.width if self.width.blank? and self.picture - self.height = self.picture.height if self.height.blank? and self.picture - self.t = self.new_t if self.t.blank? - self.z = self.new_z if self.z.blank? + self.x = 0 + self.y = 0 + if self.picture + self.width = self.picture.width + self.height = self.picture.height + end + if self.panel + self.t = self.panel.new_t + self.z = self.panel.new_z + end end def overwrite @@ -67,14 +71,6 @@ class PanelPicture < ActiveRecord::Base {:src => self.url, :width => tw, :height => th, :alt => self.caption} end - def new_t - self.panel.parts.size - end - - def new_z - self.panel.panel_elements.size + 1 - end - def self.default_page_size 25 end diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index b6c6cc09..92d7f9e8 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -23,6 +23,16 @@ class SpeechBalloon < ActiveRecord::Base end end + def supply_default + self.x = self.x || 0 + self.y = self.y || 0 + self.t = self.t || self.panel.new_t if self.panel + self.z = self.z || self.panel.new_z if self.panel + end + + def overwrite + end + def visible? roles if MagicNumber['run_mode'] == 0 return false unless guest_role_check(roles) diff --git a/app/views/ground_pictures/_form.html.erb b/app/views/ground_pictures/_form.html.erb index 46f2884e..47af5038 100644 --- a/app/views/ground_pictures/_form.html.erb +++ b/app/views/ground_pictures/_form.html.erb @@ -1,7 +1,6 @@ <%= form_for(@ground_picture) do |f| %> <%= render 'system/error_explanation', :obj => @ground_picture %> - repeat:
<%= f.label :caption %>
<%= f.text_field :caption %> -- 2.11.0