OSDN Git Service

classname rename to module_name
[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_html_format format
30     format.html {
31       @ground_picture = @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     @picture = Picture.show params[:picture_id], @operators
59     raise ActiveRecord::Forbidden unless @picture.enable?
60     @panel = Panel.edit(@operators.author.working_panel, @operators)
61     
62     @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
63     @ground_picture.supply_default
64
65     respond_to do |format|
66       format.html
67       format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) }
68     end
69   end
70
71   def edit
72     @ground_picture = GroundPicture.show(params[:id], @operators)
73     @panel = Panel.edit(@ground_picture.panel.id, @operators)
74     
75     respond_to do |format|
76       format.html
77     end
78   end
79
80   def create
81     raise Pettanr::NotWork unless @operators.author.working_panel
82     @panel = Panel.edit(@operators.author.working_panel, @operators)
83     
84     @ground_picture = GroundPicture.new
85     @ground_picture.attributes = params[:ground_picture]
86     @ground_picture.overwrite @panel.id
87     
88     @picture = Picture.show @ground_picture.picture_id, @operators
89     raise ActiveRecord::Forbidden unless @picture.enable?
90     
91     respond_to do |format|
92       if @ground_picture.valid?
93         if @ground_picture.store @operators
94           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
95           format.html { redirect_to @panel }
96           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
97         else
98           flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
99           format.html { render action: "new" }
100           format.json { render json: @panel.errors, status: :unprocessable_entity }
101         end
102       else
103         flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
104         format.html { render action: "new" }
105         format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
106       end
107     end
108   end
109
110   def update
111     @ground_picture = GroundPicture.show(params[:id], @operators)
112     @ground_picture.attributes = params[:ground_picture]
113     @panel = Panel.edit(@ground_picture.panel.id, @operators)
114     @ground_picture.overwrite @panel.id
115     
116     @picture = Picture.show @ground_picture.picture_id, @operators
117     raise ActiveRecord::Forbidden unless @picture.enable?
118     
119     respond_to do |format|
120       if @ground_picture.store @operators
121         flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human)
122         format.html { redirect_to @ground_picture }
123         format.json { head :ok }
124       else
125         flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human)
126         format.html { render action: "edit" }
127         format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
128       end
129     end
130   end
131
132   def destroy
133     @ground_picture = GroundPicture.show(params[:id], @operators)
134     @panel = Panel.edit(@ground_picture.panel.id, @operators)
135     
136     respond_to do |format|
137       if @ground_picture.remove @operators
138         flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human)
139         format.html { redirect_to @panel }
140         format.json { head :ok }
141       else
142         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human)
143         format.html { redirect_to @ground_picture }
144         format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
145       end
146     end
147   end
148   
149 end