OSDN Git Service

fix filer
[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, :count, :count_by_panel, :count_by_scroll
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 show
30     @item = ScrollPanel.show(params[:id], @operators)
31
32     respond_to do |format|
33       format_prof format
34       format.json { render json: @item.scroll_panel_as_json(@operators.author) }
35     end
36   end
37   
38   def count
39     list_count
40   end
41   
42   def count_by_panel
43     list_count
44   end
45   
46   def count_by_scroll
47     list_count
48   end
49   
50   def new
51     @scroll_panel = ScrollPanel.new 
52     @scroll_panel.supply_default
53     respond_to do |format|
54       format.html
55       format.js
56       format.json { render json: @scroll_panel.scroll_panel_as_json(@operators.author) }
57     end
58   end
59
60   def edit
61     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
62     respond_to do |format|
63       format.html 
64       format.js
65     end
66   end
67
68   def create
69     @scroll_panel = ScrollPanel.new 
70     @scroll_panel.supply_default
71     @scroll_panel.attributes = params[:scroll_panel]
72     @scroll_panel.overwrite @operators
73     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
74     @panel = Panel.show(@scroll_panel.panel_id, @operators) if @scroll_panel.panel_id
75     
76     respond_to do |format|
77       if @scroll_panel.store @operators
78         flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human)
79         format.html { redirect_to play_scroll_path(@scroll) }
80         format.json { render json: @scroll_panel.scroll_panel_as_json(@operators.author) }
81       else
82         flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human)
83         format.html { render action: "new" }
84         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
85       end
86     end
87   end
88   
89   def update
90     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
91     ot = @scroll_panel.t
92     @scroll_panel.attributes = params[:scroll_panel]
93     @scroll_panel.overwrite @operators
94     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
95     respond_to do |format|
96       if @scroll_panel.store @operators, ot
97         flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human)
98         format.html { redirect_to play_scroll_path(@scroll) }
99         format.json { head :ok }
100       else
101         flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human)
102         format.html { render action: "edit" }
103         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
104       end
105     end
106   end
107
108   def destroy
109     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
110     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
111     respond_to do |format|
112       if @scroll_panel.destroy_and_shorten
113         flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
114         format.html { redirect_to play_scroll_path(@scroll) }
115         format.json { head :ok }
116       else
117         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
118         format.html { redirect_to scroll_panel_path(@scroll_panel) }
119         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
120       end
121     end
122   end
123 end