OSDN Git Service

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