OSDN Git Service

t#32472:add select on profiles
[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 {
19         @paginate = GroundColor.list_paginate(@page, @page_size)
20         render :template => 'system/filer', :locals => {
21           :items => @ground_colors, :model => GroundColor, 
22           :roles => [@user, @admin], :pager => @paginate
23         }
24       }
25       format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
26     end
27   end
28   
29   def show
30     @item = GroundColor.show(params[:id], [@user, @admin])
31     respond_to do |format|
32       format.html {
33         @ground_color = @item
34       }
35       format_prof format
36       format.json { render json: @item.to_json(GroundColor.show_json_opt) }
37     end
38   end
39   
40   def new
41     raise Pettanr::NotWork unless @author.working_panel
42     @panel = Panel.edit(@author.working_panel, @author)
43     @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i
44     @ground_color.supply_default
45
46     respond_to do |format|
47       format.html
48       format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
49     end
50   end
51
52   def edit
53     @ground_color = GroundColor.show(params[:id], @author)
54     @panel = Panel.edit(@ground_color.panel.id, @author)
55     
56     respond_to do |format|
57       format.html
58     end
59   end
60
61   def create
62     raise Pettanr::NotWork unless @author.working_panel
63     @panel = Panel.edit(@author.working_panel, @author)
64     
65     @ground_color = GroundColor.new 
66     @ground_color.attributes = params[:ground_color]
67     @ground_color.overwrite @panel.id
68     
69     respond_to do |format|
70       if @ground_color.valid?
71         if @ground_color.store @author
72           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
73           format.html { redirect_to @panel }
74           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
75         else
76           flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
77           format.html { render action: "new" }
78           format.json { render json: @ground_color.errors, status: :unprocessable_entity }
79         end
80       else
81         flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
82         format.html { render action: "new" }
83         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
84       end
85     end
86   end
87
88   def update
89     @ground_color = GroundColor.show(params[:id], @author)
90     @ground_color.attributes = params[:ground_color]
91     @panel = Panel.edit(@ground_color.panel.id, @author)
92     @ground_color.overwrite @panel.id
93     
94     respond_to do |format|
95       if @ground_color.store @author
96         flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
97         format.html { redirect_to @ground_color }
98         format.json { head :ok }
99       else
100         flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundColor.model_name.human)
101         format.html { render action: "edit" }
102         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
103       end
104     end
105   end
106
107   def destroy
108     @ground_color = GroundColor.show(params[:id], @author)
109     @panel = Panel.edit(@ground_color.panel.id, @author)
110     
111     respond_to do |format|
112       if @ground_color.remove @author
113         flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
114         format.html { redirect_to @panel }
115         format.json { head :ok }
116       else
117         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
118         format.html { redirect_to @ground_color }
119         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
120       end
121     end
122   end
123   
124 end