OSDN Git Service

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