OSDN Git Service

fix:err dialog
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index 669ac36..73851fc 100644 (file)
@@ -1,15 +1,13 @@
 class ComicsController < 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_author, :count, :count_by_story, :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
-    Comic
+    before_action :authenticate_reader, :only => [
+      :index, :show, :play, :by_story, :by_author
+    ]
+    before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
   
   def index
@@ -17,26 +15,19 @@ class ComicsController < ApplicationController
   end
   
   def by_story
-    filer_list
+    filer_list param: params[:id]
   end
   
   def by_author
-    filer_list
+    filer_list param: params[:id]
   end
   
   def show_html_format format
     format.html {
-      @comic = @item
-      action = Manifest.manifest.controllers['comics'].actions['play']
-      list = Locmare::ListGroup.list action.item_name, action.list_name
-      list_result = list.open(@operators, 
-        {:id => params[:id], :page => params[:page], :page_size => params[:page_size]}
+      @play_list = Locmare::ListGroup.list(
+        'comic_stories', 'by_comic', @operators, 
+        {:id => @item.id, :page_size => -1}  # set no limit options
       )
-      @comic_stories = list_result.items 
-      if @operators.author
-        @new_story_items = assist_items('story', 'private')
-        #@new_story_filer = assist_filer 'story', @new_story_items
-      end
     }
   end
   
@@ -51,16 +42,18 @@ class ComicsController < ApplicationController
     end
   end
   
-  def count
-    list_count
-  end
-  
-  def count_by_story
-    list_count
-  end
-  
-  def count_by_author
-    list_count
+  def play
+    set_play
+    @finder.per(-1)    # no limit no pager
+    play_list
+    respond_to do |format|
+      format.html {
+        if @item.own? @operators
+          @new_story_items = assist_items('home', 'stories', finder: :find_private, param: @operators)
+        end
+      }
+      list_json_format @finder, format
+    end
   end
   
   def new
@@ -73,34 +66,26 @@ class ComicsController < ApplicationController
   
   def create
     set_model
-    @comic = @item
     @item = @my_model_class.new
     @item.supply_default 
-    @item.attributes = params[@my_model_class.item_name]
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = @item.permit_params params
     @item.overwrite @operators
     render_create
   end
   
   def update
     set_edit
-    @comic = @item
-    @item.attributes = params[@my_model_class.item_name]
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = @item.permit_params params
     @item.overwrite @operators
     render_update
   end
   
   def destroy
-    @item = Comic.edit(params[:id], @operators)
-    respond_to do |format|
-      if @item.destroy_with_leafs
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
-        format.html { redirect_to '/home/comics' }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/' + @item.path_name
   end
+  
 end