OSDN Git Service

fix
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
1 class ComicsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
5     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
6   else
7     before_filter :authenticate_reader, :only => [:top, :index, :show, :stories, :by_author]
8     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
9     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
10   end
11
12   def self.model
13     Comic
14   end
15   
16   def index
17     public_list
18   end
19
20   def stories
21     has_many_list
22   end
23
24   def by_author
25     filter_list
26   end
27
28   def show
29     @item = Comic.show(params[:id], @operators)
30     respond_to do |format|
31       format.html {
32       }
33       format_prof format
34       format.json { render json: @item.to_json(Comic.show_json_opt) }
35       format.atom 
36       format.rss 
37     end
38   end
39
40   def count
41     @comic = {:count => Comic.visible_count}
42     respond_to do |format|
43       format.json { render json: @comic.to_json }
44     end
45   end
46   
47   def new
48     @comic = Comic.new
49     @comic.supply_default
50     respond_to do |format|
51       format.html
52       format.js
53       format.json { render json: @comic.to_json(Comic.show_json_opt) }
54     end
55   end
56
57   def edit
58     @comic = Comic.edit(params[:id], @operators)
59     respond_to do |format|
60       format.html 
61       format.js
62     end
63   end
64
65   def create
66     @comic = Comic.new
67     @comic.supply_default 
68     @comic.attributes = params[:comic]
69     @comic.overwrite @operators
70
71     respond_to do |format|
72       if @comic.save
73         flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
74         format.html { redirect_to @comic }
75         format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
76       else
77         flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
78         format.html { render action: "new" }
79         format.json { render json: @comic.errors, status: :unprocessable_entity }
80       end
81     end
82   end
83
84   def update
85     @comic = Comic.edit(params[:id], @operators)
86     @comic.attributes = params[:comic]
87     @comic.overwrite @operators
88     respond_to do |format|
89       if @comic.save
90         flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
91         format.html { redirect_to @comic }
92         format.json { head :ok }
93       else
94         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
95         format.html { render action: "edit" }
96         format.json { render json: @comic.errors, status: :unprocessable_entity }
97       end
98     end
99   end
100
101   def destroy
102     @comic = Comic.edit(params[:id], @operators)
103     respond_to do |format|
104       if @comic.destroy_with_story
105         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
106         format.html { redirect_to '/home/comics' }
107         format.json { head :ok }
108       else
109         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
110         format.html { redirect_to @comic }
111         format.json { render json: @comic.errors, status: :unprocessable_entity }
112       end
113     end
114   end
115 end