OSDN Git Service

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