OSDN Git Service

manifest view profiler
[pettanr/pettanr.git] / app / controllers / panel_pictures_controller.rb
1 class PanelPicturesController < 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     PanelPicture
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       @panel_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     @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
63     @item.supply_default
64     respond_to do |format|
65       format.html {
66         mounted = 1
67         form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
68         @form = form_manager.open @item, @operators, mounted
69       }
70       format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
71     end
72   end
73
74   def edit
75     @item = PanelPicture.show(params[:id], @operators)
76     @panel = Panel.edit(@item.panel.id, @operators)
77     
78     respond_to do |format|
79       format.html {
80         mounted = 1
81         form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
82         @form = form_manager.open @item, @operators, mounted
83       }
84     end
85   end
86
87   def create
88     raise Pettanr::NotWork unless @operators.author.working_panel
89     @panel = Panel.edit(@operators.author.working_panel, @operators)
90     
91     @panel_picture = PanelPicture.new 
92     @panel_picture.attributes = params[:panel_picture]
93     @panel_picture.overwrite @panel.id
94     
95     @picture = Picture.show @panel_picture.picture_id, @operators
96     raise ActiveRecord::Forbidden unless @picture.enable?
97     
98     respond_to do |format|
99       if @panel_picture.valid?
100         if @panel_picture.store @operators
101           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
102           format.html { redirect_to @panel }
103           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
104         else
105           flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
106           format.html { render action: "new" }
107           format.json { render json: @panel.errors, status: :unprocessable_entity }
108         end
109       else
110         flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
111         format.html { render action: "new" }
112         format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
113       end
114     end
115   end
116
117   def update
118     @panel_picture = PanelPicture.show(params[:id], @operators)
119     @panel_picture.attributes = params[:panel_picture]
120     @panel = Panel.edit(@panel_picture.panel.id, @operators)
121     @panel_picture.overwrite @panel.id
122     
123     @picture = Picture.show @panel_picture.picture_id, @operators
124     raise ActiveRecord::Forbidden unless @picture.enable?
125     
126     respond_to do |format|
127       if @panel_picture.store @operators
128         flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
129         format.html { redirect_to @panel_picture }
130         format.json { head :ok }
131       else
132         flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
133         format.html { render action: "edit" }
134         format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
135       end
136     end
137   end
138
139   def destroy
140     @panel_picture = PanelPicture.show(params[:id], @operators)
141     @panel = Panel.edit(@panel_picture.panel.id, @operators)
142     
143     respond_to do |format|
144       if @panel_picture.remove @operators
145         flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
146         format.html { redirect_to @panel }
147         format.json { head :ok }
148       else
149         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
150         format.html { redirect_to @panel_picture }
151         format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
152       end
153     end
154   end
155   
156 end