OSDN Git Service

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