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