OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / controllers / comic_stories_controller.rb
index bcc8df1..449dd21 100644 (file)
@@ -1,17 +1,13 @@
 class ComicStoriesController < ApplicationController
   if Manifest.manifest.magic_numbers['run_mode'] == 0
-    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
-    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+    before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [
-      :index, :show, :by_story, :by_comic, :by_author, :count, :count_by_story, :count_by_comic, :count_by_author
+    before_action :authenticate_reader, :only => [
+      :index, :show, :by_story, :by_comic, :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
-    ComicStory
+    before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
   
   def index
@@ -19,37 +15,25 @@ class ComicStoriesController < ApplicationController
   end
   
   def by_story
-    filer_list
+    filer_list param: params[:id]
   end
   
   def by_comic
-    filer_list
+    filer_list param: params[:id]
   end
   
   def by_author
-    filer_list
+    filer_list param: params[:id]
   end
   
   def show
     set_show
     respond_to do |format|
       show_prof_format format
-      format.json { render json: @item.comic_story_as_json(@operators.author) }
+      format.json { render json: @item.to_json }
     end
   end
   
-  def count
-    list_count
-  end
-  
-  def count_by_story
-    list_count
-  end
-  
-  def count_by_comic
-    list_count
-  end
-  
   def count_by_author
     list_count
   end
@@ -63,58 +47,36 @@ class ComicStoriesController < ApplicationController
   end
   
   def create
-    @comic_story = ComicStory.new 
-    @comic_story.supply_default
-    @comic_story.attributes = params[:comic_story]
-    @comic_story.overwrite @operators
-    @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
-    @story = Story.show(@comic_story.story_id, @operators) if @comic_story.story_id
+    set_model
+    @item = @my_model_class.new
+    @item.supply_default
+    @item.attributes = @item.permit_params params
+    @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 @comic_story.store @operators
-        flash[:notice] = I18n.t('flash.notice.created', :model => ComicStory.model_name.human)
-        format.html { redirect_to play_comic_path(@comic) }
-        format.json { render json: @comic_story.comic_story_as_json(@operators.author) }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_created', :model => ComicStory.model_name.human)
-        format.html { render action: "new" }
-        format.json { render json: @comic_story.errors, status: :unprocessable_entity }
-      end
-    end
+    leaf_render_create play_comic_path(@binder)
   end
   
   def update
-    @comic_story = ComicStory.edit(params[:id], @operators)
-    ot = @comic_story.t
-    @comic_story.attributes = params[:comic_story]
-    @comic_story.overwrite @operators
-    @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
-    respond_to do |format|
-      if @comic_story.store @operators, ot
-        flash[:notice] = I18n.t('flash.notice.updated', :model => ComicStory.model_name.human)
-        format.html { redirect_to play_comic_path(@comic) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_updated', :model => ComicStory.model_name.human)
-        format.html { render action: "edit" }
-        format.json { render json: @comic_story.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    ot = @item.t
+    @item.attributes = @item.permit_params params
+    @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_comic_path(@binder)
   end
-
+  
   def destroy
-    @comic_story = ComicStory.edit(params[:id], @operators)
-    @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
-    respond_to do |format|
-      if @comic_story.destroy_and_shorten
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => ComicStory.model_name.human)
-        format.html { redirect_to play_comic_path(@comic) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ComicStory.model_name.human)
-        format.html { redirect_to comic_story_path(@comic_story) }
-        format.json { render json: @comic_story.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    render_destroy play_comic_path(@binder)
   end
+  
 end