OSDN Git Service

t#31223:add them contents list for author and artist
[pettanr/pettanr.git] / app / controllers / authors_controller.rb
index 50adf08..531f46d 100644 (file)
@@ -1,7 +1,13 @@
 class AuthorsController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :edit, :update]
-  before_filter :authenticate_author, :only => [:index, :show, :edit, :update]
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
+    before_filter :authenticate_author, :only => [:edit, :update]
+  else
+    before_filter :authenticate_reader, :only => [:index, :show, :comics, :panels]
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
+    before_filter :authenticate_author, :only => [:edit, :update]
+  end
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
   def index
@@ -16,7 +22,7 @@ class AuthorsController < ApplicationController
   end
 
   def show
-    @au = Author.show(params[:id], @author)
+    @au = Author.show(params[:id], [@user, @admin])
 
     respond_to do |format|
       format.html
@@ -24,6 +30,32 @@ class AuthorsController < ApplicationController
     end
   end
 
+  def comics
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.comic_page_size params[:page_size]
+    @comics = Comic.mylist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @comics.to_json(Comic.list_json_opt) }
+    end
+  end
+  
+  def panels
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.panel_page_size params[:page_size]
+    @panels = Panel.mylist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render text: Panel.list_as_json_text(@panels) }
+    end
+  end
+  
   def count
     @au = {:count => Author.visible_count}
     respond_to do |format|
@@ -69,7 +101,8 @@ class AuthorsController < ApplicationController
     @au.overwrite @user.id
     respond_to do |format|
       if @au.save
-        format.html { redirect_to root_path, notice: 'Author was successfully created.' }
+        flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
+        format.html { redirect_to root_path }
         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
       else
         format.html { render action: "new" }
@@ -85,7 +118,8 @@ class AuthorsController < ApplicationController
 
     respond_to do |format|
       if @au.save
-        format.html { redirect_to '/home/configure', notice: 'Author was successfully updated.' }
+        flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
+        format.html { redirect_to '/home/configure' }
         format.json { head :ok }
       else
         format.html { render action: "edit" }