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]
11 before_filter :authenticate_admin!, :only => [:list, :browse]
13 @@model = PanelPicture
17 respond_to do |format|
19 format.json { render :json => @items.to_json(@@model.list_json_opt) }
24 @item = PanelPicture.show(params[:id], @operators)
26 respond_to do |format|
28 @panel_picture = @item
31 format.json { render :json => @item.to_json(PanelPicture.show_json_opt) }
36 @panel_pictures = PanelPicture.all
38 respond_to do |format|
39 format.html { render layout: 'system' }
40 format.json { render json: @panel_pictures }
45 @panel_picture = PanelPicture.find(params[:id])
47 respond_to do |format|
48 format.html { render layout: 'system' }
49 format.json { render json: @panel_picture}
54 raise Pettanr::NotWork unless @author.working_panel
55 @picture = Picture.show params[:picture_id], @author
56 raise ActiveRecord::Forbidden unless @picture.enable?
57 @panel = Panel.edit(@author.working_panel, @author)
59 @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
60 @panel_picture.supply_default
62 respond_to do |format|
64 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
69 @panel_picture = PanelPicture.show(params[:id], @author)
70 @panel = Panel.edit(@panel_picture.panel.id, @author)
72 respond_to do |format|
78 raise Pettanr::NotWork unless @author.working_panel
79 @panel = Panel.edit(@author.working_panel, @author)
81 @panel_picture = PanelPicture.new
82 @panel_picture.attributes = params[:panel_picture]
83 @panel_picture.overwrite @panel.id
85 @picture = Picture.show @panel_picture.picture_id, @author
86 raise ActiveRecord::Forbidden unless @picture.enable?
88 respond_to do |format|
89 if @panel_picture.valid?
90 if @panel_picture.store @author
91 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
92 format.html { redirect_to @panel }
93 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
95 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
96 format.html { render action: "new" }
97 format.json { render json: @panel.errors, status: :unprocessable_entity }
100 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
101 format.html { render action: "new" }
102 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
108 @panel_picture = PanelPicture.show(params[:id], @author)
109 @panel_picture.attributes = params[:panel_picture]
110 @panel = Panel.edit(@panel_picture.panel.id, @author)
111 @panel_picture.overwrite @panel.id
113 @picture = Picture.show @panel_picture.picture_id, @author
114 raise ActiveRecord::Forbidden unless @picture.enable?
116 respond_to do |format|
117 if @panel_picture.store @author
118 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
119 format.html { redirect_to @panel_picture }
120 format.json { head :ok }
122 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
123 format.html { render action: "edit" }
124 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
130 @panel_picture = PanelPicture.show(params[:id], @author)
131 @panel = Panel.edit(@panel_picture.panel.id, @author)
133 respond_to do |format|
134 if @panel_picture.remove @author
135 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
136 format.html { redirect_to @panel }
137 format.json { head :ok }
139 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
140 format.html { redirect_to @panel_picture }
141 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }