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]
29 def show_html_format format
31 @panel_picture = @item
37 respond_to do |format|
38 show_html_format format
39 show_prof_format format
40 show_json_format format
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)
62 @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
64 respond_to do |format|
67 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
68 @form = form_manager.open @item, @operators, mounted
70 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
75 @item = PanelPicture.show(params[:id], @operators)
76 @panel = Panel.edit(@item.panel.id, @operators)
78 respond_to do |format|
81 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
82 @form = form_manager.open @item, @operators, mounted
88 raise Pettanr::NotWork unless @operators.author.working_panel
89 @panel = Panel.edit(@operators.author.working_panel, @operators)
91 @panel_picture = PanelPicture.new
92 @panel_picture.attributes = params[:panel_picture]
93 @panel_picture.overwrite @panel.id
95 @picture = Picture.show @panel_picture.picture_id, @operators
96 raise ActiveRecord::Forbidden unless @picture.enable?
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 }
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 }
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 }
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
123 @picture = Picture.show @panel_picture.picture_id, @operators
124 raise ActiveRecord::Forbidden unless @picture.enable?
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 }
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 }
140 @panel_picture = PanelPicture.show(params[:id], @operators)
141 @panel = Panel.edit(@panel_picture.panel.id, @operators)
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 }
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 }