OSDN Git Service

33bb1f62713e6acecf89c730ca40038a04d9ab83
[pettanr/pettanr.git] / app / controllers / scrolls_controller.rb
1 class ScrollsController < 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, :play, :by_author, :by_panel]
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     Scroll
13   end
14   
15   def index
16     filer_list
17   end
18   
19   def by_author
20     filer_list
21   end
22   
23   def by_panel
24     filer_list
25   end
26   
27   def show
28     @item = Scroll.show(params[:id], @operators)
29
30     respond_to do |format|
31       format.html {
32         if @operators.author
33           @new_panel_items = assist_items('panel', 'private_list')
34           @new_panel_filer = assist_filer 'panel', @new_panel_items
35         end
36       }
37       format.json { render json: @item.to_json(Scroll.show_json_opt) }
38       format_prof format
39       format.atom 
40       format.rss 
41     end
42   end
43
44   def play
45     @item = self.class.model.show(params[:id], @operators)
46     action_name = params[:action]
47     @action = self.class.controller.open(action_name, params, @operators)
48     @items = @action.list.items @item
49     respond_to do |format|
50       format.html {
51         @count = @action.list.count @item
52         @prev_offset = @action.list.prev_offset @item
53         @next_offset = @action.list.next_offset @item
54         if @operators.author
55           @new_panel_items = assist_items('panel', 'private_list')
56           @new_panel_filer = assist_filer 'panel', @new_panel_items
57         end
58       }
59       format.json { render json: @items.to_json(self.class.model.list_json_opt) }
60     end
61   end
62   
63   def count
64     list_count
65   end
66   
67   def count_by_author
68     list_count
69   end
70   
71   def count_by_panel
72     list_count
73   end
74   
75   def new
76     form_new
77   end
78
79   def edit
80     @scroll = Scroll.edit(params[:id], @operators)
81     respond_to do |format|
82       format.html 
83       format.js
84     end
85   end
86
87   def create
88     @scroll = Scroll.new
89     @scroll.supply_default 
90     @scroll.attributes = params[:scroll]
91     @scroll.overwrite @operators
92
93     respond_to do |format|
94       if @scroll.save
95         flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
96         format.html { redirect_to @scroll }
97         format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll }
98       else
99         flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
100         format.html { render action: "new" }
101         format.json { render json: @scroll.errors, status: :unprocessable_entity }
102       end
103     end
104   end
105
106   def update
107     @scroll = Scroll.edit(params[:id], @operators)
108     @scroll.attributes = params[:scroll]
109     @scroll.overwrite @operators
110     respond_to do |format|
111       if @scroll.save
112         flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
113         format.html { redirect_to @scroll }
114         format.json { head :ok }
115       else
116         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
117         format.html { render action: "edit" }
118         format.json { render json: @scroll.errors, status: :unprocessable_entity }
119       end
120     end
121   end
122
123   def destroy
124     @scroll = Scroll.edit(params[:id], @operators)
125     respond_to do |format|
126       if @scroll.destroy_with_scroll_panel
127         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
128         format.html { redirect_to '/home/scrolls' }
129         format.json { head :ok }
130       else
131         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human)
132         format.html { redirect_to @scroll }
133         format.json { render json: @scroll.errors, status: :unprocessable_entity }
134       end
135     end
136   end
137 end