OSDN Git Service

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