OSDN Git Service

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