OSDN Git Service

t#32025:comic rename
[pettanr/pettanr.git] / app / controllers / scrolls_controller.rb
1 class ScrollsController < 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]
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   before_filter :authenticate_admin!, :only => [:list, :browse]
12
13   def index
14     @page = Scroll.page params[:page]
15     @page_size = Scroll.page_size params[:page_size]
16     @scrolls = Scroll.list(@page, @page_size)
17     respond_to do |format|
18       format.html {
19         @paginate = Scroll.list_paginate(@page, @page_size)
20       }
21       format.json { render json: @scrolls.to_json(Scroll.list_json_opt) }
22       format.atom 
23       format.rss
24     end
25   end
26
27   def show
28     @scroll = Scroll.show(params[:id], [@user, @admin])
29
30     respond_to do |format|
31       format.html # show.html.erb
32       format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
33       format.atom 
34       format.rss 
35     end
36   end
37
38   def count
39     @scroll = {:count => Scroll.visible_count}
40     respond_to do |format|
41       format.json { render json: @scroll.to_json }
42     end
43   end
44   
45   def list
46     @scrolls = Scroll.all
47
48     respond_to do |format|
49       format.html { render layout: 'system' }# index.html.erb
50       format.json { render json: @scrolls }
51     end
52   end
53
54   def browse
55     @scroll = Scroll.find(params[:id])
56
57     respond_to do |format|
58       format.html { render layout: 'system' } # show.html.erb
59       format.json { render json: @scroll }
60     end
61   end
62   
63   def new
64     @scroll = Scroll.new
65     @scroll.supply_default
66     respond_to do |format|
67       format.html # new.html.erb
68       format.js
69       format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
70     end
71   end
72
73   def edit
74     @scroll = Scroll.edit(params[:id], @author)
75     respond_to do |format|
76       format.html 
77       format.js
78     end
79   end
80
81   def create
82     @scroll = Scroll.new
83     @scroll.supply_default 
84     @scroll.attributes = params[:scroll]
85     @scroll.overwrite @author
86
87     respond_to do |format|
88       if @scroll.save
89         flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
90         format.html { redirect_to @scroll }
91         format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll }
92       else
93         flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
94         format.html { render action: "new" }
95         format.json { render json: @scroll.errors, status: :unprocessable_entity }
96       end
97     end
98   end
99
100   def update
101     @scroll = Scroll.edit(params[:id], @author)
102     @scroll.attributes = params[:scroll]
103     @scroll.overwrite @author
104     respond_to do |format|
105       if @scroll.save
106         flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
107         format.html { redirect_to @scroll }
108         format.json { head :ok }
109       else
110         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
111         format.html { render action: "edit" }
112         format.json { render json: @scroll.errors, status: :unprocessable_entity }
113       end
114     end
115   end
116
117   def destroy
118     @scroll = Scroll.edit(params[:id], @author)
119     respond_to do |format|
120       if @scroll.destroy_with_scroll_panel
121         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
122         format.html { redirect_to '/home/scrolls' }
123         format.json { head :ok }
124       else
125         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human)
126         format.html { redirect_to @scroll }
127         format.json { render json: @scroll.errors, status: :unprocessable_entity }
128       end
129     end
130   end
131 end