OSDN Git Service

rails upgrade to 4
[pettanr/pettanr.git] / app / controllers / stories_controller.rb
index 6e473f1..6466664 100644 (file)
@@ -1,13 +1,13 @@
 class StoriesController < 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, :play, :by_comic, :by_sheet, :by_author, :count, :count_by_comic, :count_by_sheet, :count_by_author
+    before_action :authenticate_reader, :only => [
+      :index, :show, :play, :by_comic, :by_sheet, :by_author
     ]
-    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]
   end
   
   def index
@@ -28,11 +28,10 @@ class StoriesController < ApplicationController
   
   def show_html_format format
     format.html {
-      play_list = Locmare::ListGroup.list(
+      @play_list = Locmare::ListGroup.list(
         'story_sheets', 'by_story', @operators, 
-        {:id => @item.id, :my_play => @item.own?(@operators)}
+        {:id => @item.id, :page_size => -1}  # set no limit options
       )
-      @play_count = play_list.count(@operators)
     }
   end
   
@@ -46,44 +45,21 @@ class StoriesController < ApplicationController
   end
   
   def play
-    params[:offset] = nil
-    params[:count] = nil
-    params[:page] ||= 1
-    params[:page_size] = 1
     set_play
-    @list = Locmare::ListGroup.list(
-      @my_controller.name, 
-      @my_action.name, @operators, 
-      {:id => @item.id, :offset => 0, :limit => -1}# no limit
-    )
-    @items = @list.items(@operators)
-    @count = @list.count @operators
+    @list.options.merge!({'per_page' => 1})    # show one sheet
+    @list.reset
+    play_list
     respond_to do |format|
       format.html {
+        @pager = @list.page_status.pager
         if @item.own? @operators
           @new_sheet_items = assist_items('home', 'sheets')
         end
       }
-      format.json { render json: @items.to_json }
+      list_json_format @list, format
     end
   end
   
-  def count
-    list_count
-  end
-  
-  def count_by_comic
-    list_count
-  end
-  
-  def count_by_sheet
-    list_count
-  end
-  
-  def count_by_author
-    list_count
-  end
-  
   def new
     form_new
   end
@@ -97,7 +73,7 @@ class StoriesController < ApplicationController
     @story = @item
     @item = @my_model_class.new
     @item.supply_default 
-    @item.attributes = params[@my_model_class.item_name]
+    @item.attributes = @item.permit_params params
     @item.overwrite @operators
     render_create
   end
@@ -105,24 +81,15 @@ class StoriesController < ApplicationController
   def update
     set_edit
     @story = @item
-    @item.attributes = params[@my_model_class.item_name]
+    @item.attributes = @item.permit_params params
     @item.overwrite @operators
     render_update
   end
   
   def destroy
-    @item = Story.edit(params[:id], @operators)
-    respond_to do |format|
-      if @item.destroy_with_leafs
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
-        format.html { redirect_to '/home/stories' }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.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