OSDN Git Service

fix panel test
[pettanr/pettanr.git] / app / controllers / panels_controller.rb
index 24359c3..2236299 100644 (file)
@@ -1,6 +1,6 @@
 class PanelsController < ApplicationController
   layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:index, :show, :create, :update, :destroy]
+  before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
   private
@@ -14,39 +14,37 @@ class PanelsController < ApplicationController
   # GET /panels
   # GET /panels.json
   def index
-    @panels = Panel.find(:all, :include => [:comic, :author], :order => 'updated_at', :limit => 20)
+    @page = Panel.page params[:page]
+    @page_size = Panel.page_size params[:page_size]
+    @panels = Panel.list({}, @page, @page_size)
 
     respond_to do |format|
       format.html # index.html.erb
-      format.json { render :json => @panels.to_json(
-        :include => [:comic, :author]
-      ) }
+      format.json { render json: @panels.to_json(Panel.list_json_opt) }
     end
   end
 
   # GET /panels/1
   # GET /panels/1.json
   def show
-    @panel = Panel.find(params[:id], include: [:comic, :panel_pictures => :resource_picture, :balloons => :speeches])# only: [:width, :height])
+    @panel = Panel.show(params[:id], @author)
 
     respond_to do |format|
       format.html # show.html.erb
-       format.json {
-        render :json => @panel.to_json(include: {
-          :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
-        })
-      }
+      format.json { render json: @panel.to_json(Panel.show_json_include_opt) }
       format.jsonp {
-        render :json => "callback(" + @panel.to_json(include: {
-          :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
-        }) + ");"
+        render :json => "callback(" + @panel.to_json(Panel.show_json_include_opt) + ");"
       }
-#      format.json { render :json => @frame.to_json(include: {
-#        :comic => {:only => :title}, :panel_pictures => {:include => {:image => {:only => [:width]}},:only => [:width, :height, :z, :image_id]}
-#      }, only: [:border]) }
     end
   end
 
+  def count
+    @panel = {:count => Panel.visible_count}
+    respond_to do |format|
+      format.json { render json: @panel.to_json }
+    end
+  end
+  
   def list
     @panels = Panel.all :order => 'updated_at'
 
@@ -64,6 +62,25 @@ class PanelsController < ApplicationController
     end
   end
 
+  def new
+    @panel = Panel.new
+    @panel.supply_default @author
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.js
+      format.json { render json: @panel }
+    end
+  end
+
+  def edit
+    @panel = Panel.show(params[:id], @author)
+    respond_to do |format|
+      format.html
+      format.js
+    end
+  end
+
   # POST /panels
   # POST /panels.json
   def create
@@ -77,7 +94,7 @@ class PanelsController < ApplicationController
 
     respond_to do |format|
       Panel.transaction do
-        if @panel.vdt_save
+        if @panel.store
           format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
           format.json { render json: @panel, status: :created, location: @panel }
         else