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