OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / controllers / ground_colors_controller.rb
1 class GroundColorsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
5   else
6     before_filter :authenticate_reader, :only => [
7       :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author
8     ]
9     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
10     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
11   end
12
13   def self.model
14     GroundColor
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_author
26     filer_list
27   end
28   
29   def show_html_format format
30     format.html {
31       @ground_color = @item
32     }
33   end
34   
35   def show
36     set_show
37     respond_to do |format|
38       show_html_format format
39       show_prof_format format
40       show_json_format format
41     end
42   end
43   
44   def count
45     list_count
46   end
47   
48   def count_by_panel
49     list_count
50   end
51   
52   def count_by_author
53     list_count
54   end
55   
56   def new
57     raise Pettanr::NotWork unless @operators.author.working_panel
58     @panel = Panel.edit(@operators.author.working_panel, @operators)
59     @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i
60     @ground_color.supply_default
61
62     respond_to do |format|
63       format.html
64       format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
65     end
66   end
67
68   def edit
69     @ground_color = GroundColor.show(params[:id], @operators)
70     @panel = Panel.edit(@ground_color.panel.id, @operators)
71     
72     respond_to do |format|
73       format.html
74     end
75   end
76
77   def create
78     raise Pettanr::NotWork unless @operators.author.working_panel
79     @panel = Panel.edit(@operators.author.working_panel, @operators)
80     
81     @ground_color = GroundColor.new 
82     @ground_color.attributes = params[:ground_color]
83     @ground_color.overwrite @panel.id
84     
85     respond_to do |format|
86       if @ground_color.valid?
87         if @ground_color.store @operators
88           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
89           format.html { redirect_to @panel }
90           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
91         else
92           flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
93           format.html { render action: "new" }
94           format.json { render json: @ground_color.errors, status: :unprocessable_entity }
95         end
96       else
97         flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
98         format.html { render action: "new" }
99         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
100       end
101     end
102   end
103
104   def update
105     @ground_color = GroundColor.show(params[:id], @operators)
106     @ground_color.attributes = params[:ground_color]
107     @panel = Panel.edit(@ground_color.panel.id, @operators)
108     @ground_color.overwrite @panel.id
109     
110     respond_to do |format|
111       if @ground_color.store @operators
112         flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
113         format.html { redirect_to @ground_color }
114         format.json { head :ok }
115       else
116         flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundColor.model_name.human)
117         format.html { render action: "edit" }
118         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
119       end
120     end
121   end
122
123   def destroy
124     @ground_color = GroundColor.show(params[:id], @operators)
125     @panel = Panel.edit(@ground_color.panel.id, @operators)
126     
127     respond_to do |format|
128       if @ground_color.remove @operators
129         flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
130         format.html { redirect_to @panel }
131         format.json { head :ok }
132       else
133         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
134         format.html { redirect_to @ground_color }
135         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
136       end
137     end
138   end
139   
140 end