1 class PanelPicturesController < ApplicationController
2 layout 'test' if MagicNumber['test_layout']
3 if MagicNumber['run_mode'] == 0
4 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
5 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
7 before_filter :authenticate_reader, :only => [:index, :show, :by_panel, :by_author]
8 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
29 @item = PanelPicture.show(params[:id], @operators)
31 respond_to do |format|
33 @panel_picture = @item
36 format.json { render :json => @item.to_json(PanelPicture.show_json_opt) }
41 raise Pettanr::NotWork unless @operators.author.working_panel
42 @picture = Picture.show params[:picture_id], @operators
43 raise ActiveRecord::Forbidden unless @picture.enable?
44 @panel = Panel.edit(@operators.author.working_panel, @operators)
46 @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
48 respond_to do |format|
51 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
52 @form = form_manager.open @item, @operators, mounted
54 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
59 @item = PanelPicture.show(params[:id], @operators)
60 @panel = Panel.edit(@item.panel.id, @operators)
62 respond_to do |format|
65 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
66 @form = form_manager.open @item, @operators, mounted
72 raise Pettanr::NotWork unless @operators.author.working_panel
73 @panel = Panel.edit(@operators.author.working_panel, @operators)
75 @panel_picture = PanelPicture.new
76 @panel_picture.attributes = params[:panel_picture]
77 @panel_picture.overwrite @panel.id
79 @picture = Picture.show @panel_picture.picture_id, @operators
80 raise ActiveRecord::Forbidden unless @picture.enable?
82 respond_to do |format|
83 if @panel_picture.valid?
84 if @panel_picture.store @operators
85 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
86 format.html { redirect_to @panel }
87 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
89 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
90 format.html { render action: "new" }
91 format.json { render json: @panel.errors, status: :unprocessable_entity }
94 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
95 format.html { render action: "new" }
96 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
102 @panel_picture = PanelPicture.show(params[:id], @operators)
103 @panel_picture.attributes = params[:panel_picture]
104 @panel = Panel.edit(@panel_picture.panel.id, @operators)
105 @panel_picture.overwrite @panel.id
107 @picture = Picture.show @panel_picture.picture_id, @operators
108 raise ActiveRecord::Forbidden unless @picture.enable?
110 respond_to do |format|
111 if @panel_picture.store @operators
112 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
113 format.html { redirect_to @panel_picture }
114 format.json { head :ok }
116 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
117 format.html { render action: "edit" }
118 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
124 @panel_picture = PanelPicture.show(params[:id], @operators)
125 @panel = Panel.edit(@panel_picture.panel.id, @operators)
127 respond_to do |format|
128 if @panel_picture.remove @operators
129 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
130 format.html { redirect_to @panel }
131 format.json { head :ok }
133 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
134 format.html { redirect_to @panel_picture }
135 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }