OSDN Git Service

t#31485:editate ground_colors
[pettanr/pettanr.git] / app / controllers / ground_colors_controller.rb
1 class GroundColorsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
5     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
6   else
7     before_filter :authenticate_reader, :only => [:index, :show]
8     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
9     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
10   end
11
12   def index
13     @page = GroundColor.page params[:page]
14     @page_size = GroundColor.page_size params[:page_size]
15     @ground_colors = GroundColor.list(@page, @page_size)
16
17     respond_to do |format|
18       format.html # index.html.erb
19       format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
20     end
21   end
22   
23   def show
24     @ground_color = GroundColor.show(params[:id], [@user, @admin])
25     respond_to do |format|
26       format.html # show.html.erb
27       format.json { render json: @ground_color.to_json(GroundColor.show_json_opt) }
28     end
29   end
30   
31   def new
32     @ground_color = GroundColor.new params[:ground_color]
33     @ground_color.supply_default
34     @panel = @author.working_panel
35
36     respond_to do |format|
37       format.html
38       format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
39     end
40   end
41
42   def edit
43     @ground_color = GroundColor.show(params[:id], @author)
44     @panel = Panel.edit(@ground_color.panel.id, @author)
45     
46     respond_to do |format|
47       format.html
48     end
49   end
50
51   def create
52     @ground_color = GroundColor.new params[:ground_color]
53     @ground_color.supply_default
54     @panel = Panel.edit(@author.working_panel, @author)
55     @ground_color.overwrite @panel.id
56     
57     respond_to do |format|
58       if @ground_color.valid?
59         if @ground_color.store @author
60           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
61           format.html { redirect_to @panel }
62           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
63         else
64           format.html { render action: "panels/new" }
65           format.json { render json: @panel.errors, status: :unprocessable_entity }
66         end
67       else
68         format.html { render action: "new" }
69         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
70       end
71     end
72   end
73
74   def update
75     @ground_color = GroundColor.show(params[:id], @author)
76     @ground_color.attributes = params[:ground_color]
77     @panel = Panel.edit(@ground_color.panel.id, @author)
78     @ground_color.overwrite @panel.id
79     
80     respond_to do |format|
81       if @ground_color.store @author
82         flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
83         format.html { redirect_to @ground_color }
84         format.json { head :ok }
85       else
86         format.html { render action: "edit" }
87         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
88       end
89     end
90   end
91
92   def destroy
93     @ground_color = GroundColor.show(params[:id], @author)
94     @panel = Panel.edit(@ground_color.panel.id, @author)
95     
96     respond_to do |format|
97       if @ground_color.remove @author
98         flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
99         format.html { redirect_to @panel }
100         format.json { head :ok }
101       else
102         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
103         format.html { redirect_to @ground_color }
104         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
105       end
106     end
107   end
108   
109 end