OSDN Git Service

fix form
[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     form_new
45   end
46   
47   def edit
48     form_edit
49   end
50   
51   def create
52     @comic = Comic.new
53     @comic.supply_default 
54     @comic.attributes = params[:comic]
55     @comic.overwrite @operators
56
57     respond_to do |format|
58       if @comic.save
59         flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
60         format.html { redirect_to @comic }
61         format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
62       else
63         flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
64         format.html { render action: "new" }
65         format.json { render json: @comic.errors, status: :unprocessable_entity }
66       end
67     end
68   end
69
70   def update
71     @comic = Comic.edit(params[:id], @operators)
72     @comic.attributes = params[:comic]
73     @comic.overwrite @operators
74     respond_to do |format|
75       if @comic.save
76         flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
77         format.html { redirect_to @comic }
78         format.json { head :ok }
79       else
80         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
81         format.html { render action: "edit" }
82         format.json { render json: @comic.errors, status: :unprocessable_entity }
83       end
84     end
85   end
86
87   def destroy
88     @comic = Comic.edit(params[:id], @operators)
89     respond_to do |format|
90       if @comic.destroy_with_story
91         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
92         format.html { redirect_to '/home/comics' }
93         format.json { head :ok }
94       else
95         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
96         format.html { redirect_to @comic }
97         format.json { render json: @comic.errors, status: :unprocessable_entity }
98       end
99     end
100   end
101 end