OSDN Git Service

t#32046:add sheet
[pettanr/pettanr.git] / app / controllers / stories_controller.rb
index 3a4a41c..366c4a8 100644 (file)
@@ -28,12 +28,11 @@ class StoriesController < ApplicationController
 
     respond_to do |format|
       format.html { 
-        @sheet = StorySheet.play_sheet(@story, @author)
         if @author
           @new_sheets = Sheet.mylist(@author, 1, 5)
         end
       }
-      format.json { render json: @story.story_as_json(@author) }
+      format.json { render json: @story.to_json(Story.show_json_opt) }
     end
   end
   
@@ -48,7 +47,14 @@ class StoriesController < ApplicationController
           @new_sheets = Sheet.mylist(@author, 1, 5)
         end
       }
-      format.json {render text: StorySheet.list_as_json_text(@story_sheets, @author)}
+      format.json {
+        if @sheet
+          @story_sheets = SheetPanel.play_list @sheet, @author
+          render text: SheetPanel.list_as_json_text(@story_sheets, @author)
+        else
+          render text: ''
+        end
+      }
       format.jsonp {
         render :json => "callback(" + @story_sheets.to_json_list + ");"
       }
@@ -79,7 +85,7 @@ class StoriesController < ApplicationController
     respond_to do |format|
       format.html # new.html.erb
       format.js
-      format.json { render json: @story.story_as_json(@author) }
+      format.json { render json: @story.to_json(Story.show_json_opt) }
     end
   end
 
@@ -95,14 +101,14 @@ class StoriesController < ApplicationController
     @story = Story.new 
     @story.supply_default
     @story.attributes = params[:story]
-    @story.overwrite @author
+    @story.overwrite
     @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
     
     respond_to do |format|
-      if @story.store
+      if @story.store @author
         flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
-        format.html { redirect_to story_path(@story) }
-        format.json { render json: @story.story_as_json(@author) }
+        format.html { redirect_to play_story_path(@story, :page => @story.t.to_i + 1) }
+        format.json { render json: @story.to_json(Story.show_json_opt) }
       else
         flash[:notice] = I18n.t('flash.notice.not_created', :model => Story.model_name.human)
         format.html { render action: "new" }
@@ -115,11 +121,11 @@ class StoriesController < ApplicationController
     @story = Story.edit(params[:id], @author)
     ot = @story.t
     @story.attributes = params[:story]
-    @story.overwrite @author
+    @story.overwrite
     respond_to do |format|
-      if @story.store ot
+      if @story.store  @author, ot
         flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
-        format.html { redirect_to story_path(@story) }
+        format.html { redirect_to play_story_path(@story, :page => @story.t.to_i + 1) }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Story.model_name.human)