OSDN Git Service

fix form
[pettanr/pettanr.git] / app / controllers / ground_pictures_controller.rb
1 class GroundPicturesController < 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     GroundPicture
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
30     @item = GroundPicture.show(params[:id], @operators)
31     respond_to do |format|
32       format.html {
33         @ground_picture = @item
34       }
35       format_prof format
36       format.json { render json: @item.to_json(GroundPicture.show_json_opt) }
37     end
38   end
39   
40   def count
41     list_count
42   end
43   
44   def count_by_panel
45     list_count
46   end
47   
48   def count_by_author
49     list_count
50   end
51   
52   def new
53     raise Pettanr::NotWork unless @operators.author.working_panel
54     @picture = Picture.show params[:picture_id], @operators
55     raise ActiveRecord::Forbidden unless @picture.enable?
56     @panel = Panel.edit(@operators.author.working_panel, @operators)
57     
58     @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
59     @ground_picture.supply_default
60
61     respond_to do |format|
62       format.html
63       format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) }
64     end
65   end
66
67   def edit
68     @ground_picture = GroundPicture.show(params[:id], @operators)
69     @panel = Panel.edit(@ground_picture.panel.id, @operators)
70     
71     respond_to do |format|
72       format.html
73     end
74   end
75
76   def create
77     raise Pettanr::NotWork unless @operators.author.working_panel
78     @panel = Panel.edit(@operators.author.working_panel, @operators)
79     
80     @ground_picture = GroundPicture.new
81     @ground_picture.attributes = params[:ground_picture]
82     @ground_picture.overwrite @panel.id
83     
84     @picture = Picture.show @ground_picture.picture_id, @operators
85     raise ActiveRecord::Forbidden unless @picture.enable?
86     
87     respond_to do |format|
88       if @ground_picture.valid?
89         if @ground_picture.store @operators
90           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
91           format.html { redirect_to @panel }
92           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
93         else
94           flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
95           format.html { render action: "new" }
96           format.json { render json: @panel.errors, status: :unprocessable_entity }
97         end
98       else
99         flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
100         format.html { render action: "new" }
101         format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
102       end
103     end
104   end
105
106   def update
107     @ground_picture = GroundPicture.show(params[:id], @operators)
108     @ground_picture.attributes = params[:ground_picture]
109     @panel = Panel.edit(@ground_picture.panel.id, @operators)
110     @ground_picture.overwrite @panel.id
111     
112     @picture = Picture.show @ground_picture.picture_id, @operators
113     raise ActiveRecord::Forbidden unless @picture.enable?
114     
115     respond_to do |format|
116       if @ground_picture.store @operators
117         flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human)
118         format.html { redirect_to @ground_picture }
119         format.json { head :ok }
120       else
121         flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human)
122         format.html { render action: "edit" }
123         format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
124       end
125     end
126   end
127
128   def destroy
129     @ground_picture = GroundPicture.show(params[:id], @operators)
130     @panel = Panel.edit(@ground_picture.panel.id, @operators)
131     
132     respond_to do |format|
133       if @ground_picture.remove @operators
134         flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human)
135         format.html { redirect_to @panel }
136         format.json { head :ok }
137       else
138         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human)
139         format.html { redirect_to @ground_picture }
140         format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
141       end
142     end
143   end
144   
145 end