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]
8 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
21 @item = PanelPicture.show(params[:id], @operators)
23 respond_to do |format|
25 @panel_picture = @item
28 format.json { render :json => @item.to_json(PanelPicture.show_json_opt) }
33 raise Pettanr::NotWork unless @operators.author.working_panel
34 @picture = Picture.show params[:picture_id], @operators
35 raise ActiveRecord::Forbidden unless @picture.enable?
36 @panel = Panel.edit(@operators.author.working_panel, @operators)
38 @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
39 @panel_picture.supply_default
41 respond_to do |format|
43 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
48 @panel_picture = PanelPicture.show(params[:id], @operators)
49 @panel = Panel.edit(@panel_picture.panel.id, @operators)
51 respond_to do |format|
57 raise Pettanr::NotWork unless @operators.author.working_panel
58 @panel = Panel.edit(@operators.author.working_panel, @operators)
60 @panel_picture = PanelPicture.new
61 @panel_picture.attributes = params[:panel_picture]
62 @panel_picture.overwrite @panel.id
64 @picture = Picture.show @panel_picture.picture_id, @operators
65 raise ActiveRecord::Forbidden unless @picture.enable?
67 respond_to do |format|
68 if @panel_picture.valid?
69 if @panel_picture.store @operators
70 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
71 format.html { redirect_to @panel }
72 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
74 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
75 format.html { render action: "new" }
76 format.json { render json: @panel.errors, status: :unprocessable_entity }
79 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
80 format.html { render action: "new" }
81 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
87 @panel_picture = PanelPicture.show(params[:id], @operators)
88 @panel_picture.attributes = params[:panel_picture]
89 @panel = Panel.edit(@panel_picture.panel.id, @operators)
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.store @operators
97 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
98 format.html { redirect_to @panel_picture }
99 format.json { head :ok }
101 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
102 format.html { render action: "edit" }
103 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
109 @panel_picture = PanelPicture.show(params[:id], @operators)
110 @panel = Panel.edit(@panel_picture.panel.id, @operators)
112 respond_to do |format|
113 if @panel_picture.remove @operators
114 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
115 format.html { redirect_to @panel }
116 format.json { head :ok }
118 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
119 format.html { redirect_to @panel_picture }
120 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }