OSDN Git Service

rename model name
[pettanr/pettanr.git] / app / controllers / story_sheets_controller.rb
index 496943f..c1b74e0 100644 (file)
@@ -4,15 +4,11 @@ class StorySheetsController < ApplicationController
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
     before_filter :authenticate_reader, :only => [
-      :index, :show, :by_story, :by_sheet, :count, :count_by_story, :count_by_sheet
+      :index, :show, :by_story, :by_sheet, :by_author, :count, :count_by_story, :count_by_sheet, :count_by_author
     ]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
-
-  def self.model
-    StorySheet
-  end
   
   def index
     filer_list
@@ -26,12 +22,15 @@ class StorySheetsController < ApplicationController
     filer_list
   end
   
+  def by_author
+    filer_list
+  end
+  
   def show
-    @item = StorySheet.show(params[:id], @operators)
-
+    set_show
     respond_to do |format|
-      format_prof format
-      format.json { render json: @item.to_json(StorySheet.show_json_opt) }
+      show_prof_format format
+      show_json_format format
     end
   end
   
@@ -47,6 +46,10 @@ class StorySheetsController < ApplicationController
     list_count
   end
   
+  def count_by_author
+    list_count
+  end
+  
   def new
     form_new
   end
@@ -56,45 +59,31 @@ class StorySheetsController < ApplicationController
   end
   
   def create
-    @story_sheet = StorySheet.new 
-    @story_sheet.supply_default
-    @story_sheet.attributes = params[:story_sheet]
-    @story_sheet.overwrite @operators
-    @story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id
-    @sheet = Sheet.show(@story_sheet.sheet_id, @operators) if @story_sheet.sheet_id
+    @my_model_class = self.class.model
+    @item = @my_model_class.new
+    @item.supply_default
+    @item.attributes = params[@item.item_name]
+    @item.overwrite @operators
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    @panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
     
-    respond_to do |format|
-      if @story_sheet.store @operators
-        flash[:notice] = I18n.t('flash.notice.created', :model => StorySheet.model_name.human)
-        format.html { redirect_to play_story_path(@story) }
-        format.json { render json: @story_sheet.to_json(StorySheet.show_json_opt) }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_created', :model => StorySheet.model_name.human)
-        format.html { render action: "new" }
-        format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
-      end
-    end
+    leaf_render_create play_scroll_path(@binder)
   end
   
   def update
-    @story_sheet = StorySheet.edit(params[:id], @operators)
-    ot = @story_sheet.t
-    @story_sheet.attributes = params[:story_sheet]
-    @story_sheet.overwrite @operators
-    @story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id
-    respond_to do |format|
-      if @story_sheet.store @operators, ot
-        flash[:notice] = I18n.t('flash.notice.updated', :model => StorySheet.model_name.human)
-        format.html { redirect_to play_story_path(@story) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_updated', :model => StorySheet.model_name.human)
-        format.html { render action: "edit" }
-        format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
-      end
-    end
+    @my_model_class = self.class.model
+    @item = @my_model_class.edit(params[:id], @operators)
+    ot = @item.t
+    @item.attributes = params[@item.item_name]
+    @item.overwrite @operators
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    # no check permission for destination
+    # swapable hidden panel
+    #@panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
+    
+    leaf_render_update ot, play_scroll_path(@binder)
   end
-
+  
   def destroy
     @story_sheet = StorySheet.edit(params[:id], @operators)
     @story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id