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]
6 before_filter :authenticate_reader, :only => [
7 :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author
9 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
10 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
30 @item = PanelPicture.show(params[:id], @operators)
32 respond_to do |format|
34 @panel_picture = @item
37 format.json { render :json => @item.to_json(PanelPicture.show_json_opt) }
54 raise Pettanr::NotWork unless @operators.author.working_panel
55 @picture = Picture.show params[:picture_id], @operators
56 raise ActiveRecord::Forbidden unless @picture.enable?
57 @panel = Panel.edit(@operators.author.working_panel, @operators)
59 @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
61 respond_to do |format|
64 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
65 @form = form_manager.open @item, @operators, mounted
67 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
72 @item = PanelPicture.show(params[:id], @operators)
73 @panel = Panel.edit(@item.panel.id, @operators)
75 respond_to do |format|
78 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
79 @form = form_manager.open @item, @operators, mounted
85 raise Pettanr::NotWork unless @operators.author.working_panel
86 @panel = Panel.edit(@operators.author.working_panel, @operators)
88 @panel_picture = PanelPicture.new
89 @panel_picture.attributes = params[:panel_picture]
90 @panel_picture.overwrite @panel.id
92 @picture = Picture.show @panel_picture.picture_id, @operators
93 raise ActiveRecord::Forbidden unless @picture.enable?
95 respond_to do |format|
96 if @panel_picture.valid?
97 if @panel_picture.store @operators
98 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
99 format.html { redirect_to @panel }
100 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
102 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
103 format.html { render action: "new" }
104 format.json { render json: @panel.errors, status: :unprocessable_entity }
107 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
108 format.html { render action: "new" }
109 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
115 @panel_picture = PanelPicture.show(params[:id], @operators)
116 @panel_picture.attributes = params[:panel_picture]
117 @panel = Panel.edit(@panel_picture.panel.id, @operators)
118 @panel_picture.overwrite @panel.id
120 @picture = Picture.show @panel_picture.picture_id, @operators
121 raise ActiveRecord::Forbidden unless @picture.enable?
123 respond_to do |format|
124 if @panel_picture.store @operators
125 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
126 format.html { redirect_to @panel_picture }
127 format.json { head :ok }
129 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
130 format.html { render action: "edit" }
131 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
137 @panel_picture = PanelPicture.show(params[:id], @operators)
138 @panel = Panel.edit(@panel_picture.panel.id, @operators)
140 respond_to do |format|
141 if @panel_picture.remove @operators
142 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
143 format.html { redirect_to @panel }
144 format.json { head :ok }
146 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
147 format.html { redirect_to @panel_picture }
148 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }