OSDN Git Service

fom
[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     form_new
52   end
53   
54   def edit
55     form_edit
56   end
57   
58   def create
59     @scroll_panel = ScrollPanel.new 
60     @scroll_panel.supply_default
61     @scroll_panel.attributes = params[:scroll_panel]
62     @scroll_panel.overwrite @operators
63     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
64     @panel = Panel.show(@scroll_panel.panel_id, @operators) if @scroll_panel.panel_id
65     
66     respond_to do |format|
67       if @scroll_panel.store @operators
68         flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human)
69         format.html { redirect_to play_scroll_path(@scroll) }
70         format.json { render json: @scroll_panel.scroll_panel_as_json(@operators.author) }
71       else
72         flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human)
73         format.html { render action: "new" }
74         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
75       end
76     end
77   end
78   
79   def update
80     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
81     ot = @scroll_panel.t
82     @scroll_panel.attributes = params[:scroll_panel]
83     @scroll_panel.overwrite @operators
84     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
85     respond_to do |format|
86       if @scroll_panel.store @operators, ot
87         flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human)
88         format.html { redirect_to play_scroll_path(@scroll) }
89         format.json { head :ok }
90       else
91         flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human)
92         format.html { render action: "edit" }
93         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
94       end
95     end
96   end
97
98   def destroy
99     @scroll_panel = ScrollPanel.edit(params[:id], @operators)
100     @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
101     respond_to do |format|
102       if @scroll_panel.destroy_and_shorten
103         flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
104         format.html { redirect_to play_scroll_path(@scroll) }
105         format.json { head :ok }
106       else
107         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
108         format.html { redirect_to scroll_panel_path(@scroll_panel) }
109         format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
110       end
111     end
112   end
113 end