OSDN Git Service

fix
[pettanr/pettanr.git] / app / controllers / scroll_panels_controller.rb
1 class ScrollPanelsController < 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 => [
7       :index, :show, :by_panel, :by_scroll, :by_author, :count, :count_by_panel, :count_by_scroll, :count_by_author
8     ]
9     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
10     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
11   end
12
13   def self.model
14     ScrollPanel
15   end
16   
17   def index
18     filer_list
19   end
20   
21   def by_panel
22     filer_list
23   end
24   
25   def by_scroll
26     filer_list
27   end
28   
29   def by_author
30     filer_list
31   end
32   
33   def show
34     set_show
35     respond_to do |format|
36       show_prof_format format
37       format.json { render json: @item.scroll_panel_as_json(@operators.author) }
38     end
39   end
40   
41   def count
42     list_count
43   end
44   
45   def count_by_panel
46     list_count
47   end
48   
49   def count_by_scroll
50     list_count
51   end
52   
53   def count_by_author
54     list_count
55   end
56   
57   def new
58     form_new
59   end
60   
61   def edit
62     form_edit
63   end
64   
65   def create
66     @scroll_panel = ScrollPanel.new 
67     @scroll_panel.supply_default
68     @scroll_panel.attributes = params[:scroll_panel]
69     @scroll_panel.overwrite @operators
70     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
71     @panel = Panel.show(@scroll_panel.panel_id, @operators) if @scroll_panel.panel_id
72     
73     respond_to do |format|
74       if @scroll_panel.store @operators
75         flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human)
76         format.html { redirect_to play_scroll_path(@scroll) }
77         format.json { render json: @scroll_panel.scroll_panel_as_json(@operators.author) }
78       else
79         flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human)
80         format.html { render action: "new" }
81         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
82       end
83     end
84   end
85   
86   def update
87     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
88     ot = @scroll_panel.t
89     @scroll_panel.attributes = params[:scroll_panel]
90     @scroll_panel.overwrite @operators
91     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
92     respond_to do |format|
93       if @scroll_panel.store @operators, ot
94         flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human)
95         format.html { redirect_to play_scroll_path(@scroll) }
96         format.json { head :ok }
97       else
98         flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human)
99         format.html { render action: "edit" }
100         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
101       end
102     end
103   end
104
105   def destroy
106     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
107     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
108     respond_to do |format|
109       if @scroll_panel.destroy_and_shorten
110         flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
111         format.html { redirect_to play_scroll_path(@scroll) }
112         format.json { head :ok }
113       else
114         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
115         format.html { redirect_to scroll_panel_path(@scroll_panel) }
116         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
117       end
118     end
119   end
120 end