OSDN Git Service

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