OSDN Git Service

t#31538:fix default value
authoryasushiito <yas@pen-chan.jp>
Wed, 12 Jun 2013 01:40:34 +0000 (10:40 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 12 Jun 2013 01:40:34 +0000 (10:40 +0900)
15 files changed:
app/controllers/ground_colors_controller.rb
app/controllers/ground_pictures_controller.rb
app/controllers/panel_pictures_controller.rb
app/models/ground_color.rb
app/models/ground_picture.rb
app/models/panel_picture.rb
app/views/ground_colors/_form.html.erb
app/views/ground_colors/new.html.erb
app/views/ground_colors/show.html.erb
app/views/ground_pictures/new.html.erb
app/views/panel_pictures/new.html.erb
app/views/panels/edit.html.erb
app/views/resource_pictures/show.html.erb
config/locales/pettanr.ja.yml
spec/models/ground_picture_spec.rb

index 0652ea7..139699c 100644 (file)
@@ -31,9 +31,8 @@ class GroundColorsController < ApplicationController
   end
   
   def new
-    @ground_color = GroundColor.new
-    @panel = @author.working_panel
-    @ground_color.panel_id = @panel.id
+    @panel = Panel.edit(@author.working_panel, @author)
+    @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i
     @ground_color.supply_default
 
     respond_to do |format|
@@ -52,10 +51,10 @@ class GroundColorsController < ApplicationController
   end
 
   def create
-    @ground_color = GroundColor.new params[:ground_color]
     @panel = Panel.edit(@author.working_panel, @author)
-    @ground_color.panel_id = @panel.id
-    @ground_color.supply_default
+    
+    @ground_color = GroundColor.new 
+    @ground_color.attributes = params[:ground_color]
     @ground_color.overwrite @panel.id
     
     respond_to do |format|
@@ -65,9 +64,9 @@ class GroundColorsController < ApplicationController
           format.html { redirect_to @panel }
           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
         else
-          flash[:notice] = I18n.t('flash.notice.not_created', :model => Panel.model_name.human)
-          format.html { render action: "panels/new" }
-          format.json { render json: @panel.errors, status: :unprocessable_entity }
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
+          format.html { render action: "new" }
+          format.json { render json: @ground_color.errors, status: :unprocessable_entity }
         end
       else
         flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
index dd8ebb6..26c14b7 100644 (file)
@@ -31,9 +31,12 @@ class GroundPicturesController < ApplicationController
   end
   
   def new
-    @ground_picture = GroundPicture.new params[:ground_picture]
+    @picture = Picture.show params[:picture_id], @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
+    @panel = Panel.edit(@author.working_panel, @author)
+    
+    @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
     @ground_picture.supply_default
-    @panel = @ground_picture.panel
 
     respond_to do |format|
       format.html
@@ -51,10 +54,14 @@ class GroundPicturesController < ApplicationController
   end
 
   def create
-    @ground_picture = GroundPicture.new params[:ground_picture]
-    @ground_picture.supply_default
-    @ground_picture.overwrite 
-    @panel = Panel.edit(@ground_picture.panel.id, @author)
+    @panel = Panel.edit(@author.working_panel, @author)
+    
+    @ground_picture = GroundPicture.new
+    @ground_picture.attributes = params[:ground_picture]
+    @ground_picture.overwrite @panel.id
+    
+    @picture = Picture.show @ground_picture.picture_id, @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @ground_picture.valid?
@@ -63,8 +70,8 @@ class GroundPicturesController < ApplicationController
           format.html { redirect_to @panel }
           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
         else
-          flash[:notice] = I18n.t('flash.notice.not_created', :model => Panel.model_name.human)
-          format.html { render action: "panels/new" }
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
+          format.html { render action: "new" }
           format.json { render json: @panel.errors, status: :unprocessable_entity }
         end
       else
@@ -78,8 +85,11 @@ class GroundPicturesController < ApplicationController
   def update
     @ground_picture = GroundPicture.show(params[:id], @author)
     @ground_picture.attributes = params[:ground_picture]
-    @ground_picture.overwrite 
     @panel = Panel.edit(@ground_picture.panel.id, @author)
+    @ground_picture.overwrite @panel.id
+    
+    @picture = Picture.show @ground_picture.picture_id, @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @ground_picture.store @author
index be237f5..f093949 100644 (file)
@@ -51,9 +51,12 @@ class PanelPicturesController < ApplicationController
   end
 
   def new
-    @panel_picture = PanelPicture.new params[:panel_picture]
+    @picture = Picture.show params[:picture_id], @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
+    @panel = Panel.edit(@author.working_panel, @author)
+    
+    @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
     @panel_picture.supply_default
-    @panel = @panel_picture.panel
 
     respond_to do |format|
       format.html
@@ -71,10 +74,14 @@ class PanelPicturesController < ApplicationController
   end
 
   def create
-    @panel_picture = PanelPicture.new params[:panel_picture]
-    @panel_picture.supply_default
-    @panel_picture.overwrite 
-    @panel = Panel.edit(@panel_picture.panel.id, @author)
+    @panel = Panel.edit(@author.working_panel, @author)
+    
+    @panel_picture = PanelPicture.new 
+    @panel_picture.attributes = params[:panel_picture]
+    @panel_picture.overwrite @panel.id
+    
+    @picture = Picture.show @panel_picture.picture_id, @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @panel_picture.valid?
@@ -83,8 +90,8 @@ class PanelPicturesController < ApplicationController
           format.html { redirect_to @panel }
           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
         else
-          flash[:notice] = I18n.t('flash.notice.not_created', :model => Panel.model_name.human)
-          format.html { render action: "panels/new" }
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
+          format.html { render action: "new" }
           format.json { render json: @panel.errors, status: :unprocessable_entity }
         end
       else
@@ -98,8 +105,11 @@ class PanelPicturesController < ApplicationController
   def update
     @panel_picture = PanelPicture.show(params[:id], @author)
     @panel_picture.attributes = params[:panel_picture]
-    @panel_picture.overwrite 
     @panel = Panel.edit(@panel_picture.panel.id, @author)
+    @panel_picture.overwrite @panel.id
+    
+    @picture = Picture.show @panel_picture.picture_id, @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @panel_picture.store @author
index 95a80ff..8ed6a30 100644 (file)
@@ -17,7 +17,7 @@ class GroundColor < ActiveRecord::Base
   end
   
   def supply_default
-    self.code = 0
+    self.code ||= 0
     if self.panel
       self.t = self.panel.new_t 
       self.z = self.panel.new_z 
index 67cc2c4..d8ac557 100644 (file)
@@ -31,7 +31,8 @@ class GroundPicture < ActiveRecord::Base
     end
   end
   
-  def overwrite
+  def overwrite pid
+    self.panel_id = pid
   end
   
   def visible? roles
index ba59920..f56adc8 100644 (file)
@@ -44,7 +44,8 @@ class PanelPicture < ActiveRecord::Base
     end
   end
   
-  def overwrite 
+  def overwrite  pid
+    self.panel_id = pid
   end
   
   def flip
index 8a1d82b..2569eaf 100644 (file)
@@ -9,6 +9,10 @@
     <%= f.label :z %><br />
     <%= f.number_field :z %>
   </div>
+  <div class="field">
+    <%= f.label :t %><br />
+    <%= f.number_field :t %>
+  </div>
   <%= f.hidden_field :panel_id %>
 
   <div class="actions">
index da2a5cb..029a5cd 100644 (file)
@@ -1,4 +1,5 @@
 <h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
 
 <h2><%= t('home.index.catch') -%></h2>
 <%= render 'panels/standard', :panel => @panel, :author => @author %>
index 782cf41..cf40b05 100644 (file)
 
 <%= link_to t('link.edit'), edit_ground_color_path(@ground_color) %>
 <%= link_to t('link.destroy'), ground_color_path(@ground_color), :method => :delete %>
+
+<% if @author and @author.working? -%>
+  <h3><%= t('home.index.catch') -%></h3>
+  <%= link_to panel_icon(:object => @author.working_panel, :size => 25), panel_path(@author.working_panel) %>
+  <%= link_to @author.working_panel.caption, main_app.panel_path(@author.working_panel) %>
+
+  <p>
+    <%= link_to t('resource_pictures.add_to_panel_for_ground_color'), main_app.new_ground_color_path(:code => @ground_color.code) %>
+  </p>
+<% end -%>
index efd7dcb..3beafec 100644 (file)
@@ -1,4 +1,6 @@
 <h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
 <h2><%= t('home.index.catch') -%></h2>
 <%= render 'panels/standard', :panel => @panel, :author => @author %>
 <h2><%= t('ground_pictures.create_ground_picture') -%></h2>
index d938287..1903d92 100644 (file)
@@ -1,4 +1,6 @@
 <h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
 <h2><%= t('home.index.catch') -%></h2>
 <%= render 'panels/standard', :panel => @panel, :author => @author %>
 <h2><%= t('panel_pictures.resource_picture') -%></h2>
index bc01cd6..93d2383 100644 (file)
@@ -1,6 +1,6 @@
 <h1><%= t '.title' -%></h1>
 <p id="notice"><%= notice %></p>
 
-<%= render 'standard', :panel => @panel, :author => @author %>
+<%= render 'panels/standard', :panel => @panel, :author => @author %>
 <%= render 'form' %>
 <%= link_to t('link.destroy'), panel_path(@panel), :method => :delete %>
index 6e6332a..9dc4303 100644 (file)
@@ -48,9 +48,9 @@
   <%= link_to @author.working_panel.caption, main_app.panel_path(@author.working_panel) %>
 
   <p>
-    <%= link_to t('resource_pictures.add_to_panel'), main_app.new_panel_picture_path(:panel_picture => {:panel_id => @author.working_panel.id, :picture_id => @resource_picture.picture_id}) %>
+    <%= link_to t('resource_pictures.add_to_panel_for_panel_picture'), main_app.new_panel_picture_path(:picture_id => @resource_picture.picture_id) %>
   </p>
   <p>
-    <%= link_to t('resource_pictures.add_to_panel'), main_app.new_ground_picture_path(:ground_picture => {:panel_id => @author.working_panel.id, :picture_id => @resource_picture.picture_id}) %>
+    <%= link_to t('resource_pictures.add_to_panel_for_ground_picture'), main_app.new_ground_picture_path(:picture_id => @resource_picture.picture_id) %>
   </p>
 <% end -%>
index beec6f3..cc406b1 100644 (file)
@@ -656,7 +656,8 @@ ja:
       title: 素材 生一覧
     browse:
       title: 素材 生単票
-    add_to_panel: この素材をつかんだコマに追加する
+    add_to_panel_for_panel_picture: この素材をつかんだコマにコマ絵として追加する
+    add_to_panel_for_ground_picture: この素材をつかんだコマに絵地として追加する
   original_picture_license_groups:
     new:
       title: 画像の公開(ライセンスグループの選択)
index 92228a7..8230ce0 100644 (file)
@@ -171,9 +171,10 @@ describe GroundPicture do
   end
   
   describe '上書き補充に於いて' do
-    it 'defined' do
+    it 'panel_idが設定されている' do
       @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
-      @gp.overwrite
+      @gp.overwrite  @panel.id
+      @gp.panel_id.should eq @panel.id
     end
   end