OSDN Git Service

fix test
[pettanr/pettanr.git] / app / controllers / scrolls_controller.rb
index 8faed6b..3b59b72 100644 (file)
@@ -3,7 +3,9 @@ class ScrollsController < ApplicationController
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [:top, :index, :show, :play, :by_author, :by_panel]
+    before_filter :authenticate_reader, :only => [
+      :top, :index, :show, :play, :by_panel, :by_author, :count, :count_by_panel, :count_by_author
+    ]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
@@ -26,11 +28,10 @@ class ScrollsController < ApplicationController
   
   def show_html_format format
     format.html {
-      @scroll = @item
-      if @operators.author
-        @new_panel_items = assist_items('panel', 'private')
-        #@new_panel_filer = assist_filer 'panel', @new_panel_items
-      end
+      play_list = Locmare::ListGroup.list 'scroll_panel', 'play'
+      @play_count = play_list.count(@operators, 
+        {:id => @item.id, :my_play => @item.own?(@operators)}
+      )
     }
   end
   
@@ -42,23 +43,19 @@ class ScrollsController < ApplicationController
       show_json_format format
     end
   end
-
+  
   def play
     @item = self.class.model.show(params[:id], @operators)
-    action_name = params[:action]
-    @action = self.class.controller.open(action_name, params, @operators)
-    @items = @action.list.items @item
+    set_play
+    play_list
     respond_to do |format|
       format.html {
-        @count = @action.list.count @item
-        @prev_offset = @action.list.prev_offset @item
-        @next_offset = @action.list.next_offset @item
-        if @operators.author
-          @new_panel_items = assist_items('panel', 'private_list')
-          @new_panel_filer = assist_filer 'panel', @new_panel_items
+        if @item.own? @operators
+          @fresh_panel_items = assist_items('panel', 'public')
+          @new_panel_items = assist_items('panel', 'private')
         end
       }
-      format.json { render json: @items.to_json(self.class.model.list_json_opt) }
+      format.json { render json: @items.to_json }
     end
   end
   
@@ -83,46 +80,26 @@ class ScrollsController < ApplicationController
   end
   
   def create
-    @item = Scroll.new
+    set_model
+    @item = @my_model_class.new
     @item.supply_default 
-    @item.attributes = params[:scroll]
+    @item.attributes = params[@my_model_class.item_name]
     @item.overwrite @operators
-
-    if @item.save
-      respond_to do |format|
-        flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.to_json(Scroll.show_json_opt), status: :created, location: @item }
-      end
-    else
-      flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
-      render_new
-        format.html { render action: "new" }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-    end
+    render_create
   end
-
+  
   def update
-    @item = Scroll.edit(params[:id], @operators)
-    @item.attributes = params[:scroll]
+    set_edit
+    @item.attributes = params[@my_model_class.item_name]
     @item.overwrite @operators
-    respond_to do |format|
-      if @item.save
-        flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
-        format.html { redirect_to @item }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
-        format.html { render action: "edit" }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-      end
-    end
+    render_update
   end
-
+  
   def destroy
-    @item = Scroll.edit(params[:id], @operators)
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
     respond_to do |format|
-      if @item.destroy_with_scroll_panel
+      if @item.destroy_with_leafs
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
         format.html { redirect_to '/home/scrolls' }
         format.json { head :ok }