OSDN Git Service

t#32402:add file prof
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index 3eda75e..d60fd81 100644 (file)
@@ -1,38 +1,38 @@
 class ComicsController < ApplicationController
-  layout 'test' if Pettanr::Application.test_layout
-  if Const.run_mode == 0
-    before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_user!, :only => [:top, :index, :show, :play, :new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_reader, :only => [:top, :index, :show]
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
-  def top
-    respond_to do |format|
-      format.html # index.html.erb
-    end
-  end
-  
-  # GET /comics
-  # GET /comics.json
   def index
     @page = Comic.page params[:page]
     @page_size = Comic.page_size params[:page_size]
     @comics = Comic.list(@page, @page_size)
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Comic.list_paginate(@page, @page_size)
+      }
       format.json { render json: @comics.to_json(Comic.list_json_opt) }
+      format.atom 
+      format.rss
     end
   end
 
-  # GET /comics/1
-  # GET /comics/1.json
   def show
-    @comic = Comic.show(params[:id], @author)
+    @comic = Comic.show(params[:id], [@user, @admin])
 
     respond_to do |format|
-      format.html # show.html.erb
+      format.html 
+      format.prof  { render :template => 'top/prof', :layout => true }
       format.json { render json: @comic.to_json(Comic.show_json_opt) }
+      format.atom 
+      format.rss 
     end
   end
 
@@ -61,8 +61,6 @@ class ComicsController < ApplicationController
     end
   end
   
-  # GET /comics/new
-  # GET /comics/new.js
   def new
     @comic = Comic.new
     @comic.supply_default
@@ -73,8 +71,6 @@ class ComicsController < ApplicationController
     end
   end
 
-  # GET /comics/1/edit
-  # GET /comics/1.js/edit
   def edit
     @comic = Comic.edit(params[:id], @author)
     respond_to do |format|
@@ -83,8 +79,6 @@ class ComicsController < ApplicationController
     end
   end
 
-  # POST /comics
-  # POST /comics.json
   def create
     @comic = Comic.new
     @comic.supply_default 
@@ -93,40 +87,46 @@ class ComicsController < ApplicationController
 
     respond_to do |format|
       if @comic.save
-        format.html { redirect_to @comic, notice: 'Comic was successfully created.' }
+        flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
+        format.html { redirect_to @comic }
         format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
       else
+        flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
         format.html { render action: "new" }
         format.json { render json: @comic.errors, status: :unprocessable_entity }
       end
     end
   end
 
-  # PUT /comics/1
-  # PUT /comics/1.json
   def update
     @comic = Comic.edit(params[:id], @author)
     @comic.attributes = params[:comic]
     @comic.overwrite @author
     respond_to do |format|
       if @comic.save
-        format.html { redirect_to @comic, notice: 'Comic was successfully updated.' }
+        flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
+        format.html { redirect_to @comic }
         format.json { head :ok }
       else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
         format.html { render action: "edit" }
         format.json { render json: @comic.errors, status: :unprocessable_entity }
       end
     end
   end
 
-  # DELETE /comics/1
-  # DELETE /comics/1.json
   def destroy
     @comic = Comic.edit(params[:id], @author)
-    @comic.destroy
     respond_to do |format|
-      format.html { redirect_to comics_url }
-      format.json { head :ok }
+      if @comic.destroy_with_story
+        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 @comic }
+        format.json { render json: @comic.errors, status: :unprocessable_entity }
+      end
     end
   end
 end