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 => [:index, :show, :by_panel, :by_author]
7 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
8 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
28 @item = PanelPicture.show(params[:id], @operators)
30 respond_to do |format|
32 @panel_picture = @item
35 format.json { render :json => @item.to_json(PanelPicture.show_json_opt) }
40 raise Pettanr::NotWork unless @operators.author.working_panel
41 @picture = Picture.show params[:picture_id], @operators
42 raise ActiveRecord::Forbidden unless @picture.enable?
43 @panel = Panel.edit(@operators.author.working_panel, @operators)
45 @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
47 respond_to do |format|
50 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
51 @form = form_manager.open @item, @operators, mounted
53 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
58 @item = PanelPicture.show(params[:id], @operators)
59 @panel = Panel.edit(@item.panel.id, @operators)
61 respond_to do |format|
64 form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
65 @form = form_manager.open @item, @operators, mounted
71 raise Pettanr::NotWork unless @operators.author.working_panel
72 @panel = Panel.edit(@operators.author.working_panel, @operators)
74 @panel_picture = PanelPicture.new
75 @panel_picture.attributes = params[:panel_picture]
76 @panel_picture.overwrite @panel.id
78 @picture = Picture.show @panel_picture.picture_id, @operators
79 raise ActiveRecord::Forbidden unless @picture.enable?
81 respond_to do |format|
82 if @panel_picture.valid?
83 if @panel_picture.store @operators
84 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
85 format.html { redirect_to @panel }
86 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
88 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
89 format.html { render action: "new" }
90 format.json { render json: @panel.errors, status: :unprocessable_entity }
93 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
94 format.html { render action: "new" }
95 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
101 @panel_picture = PanelPicture.show(params[:id], @operators)
102 @panel_picture.attributes = params[:panel_picture]
103 @panel = Panel.edit(@panel_picture.panel.id, @operators)
104 @panel_picture.overwrite @panel.id
106 @picture = Picture.show @panel_picture.picture_id, @operators
107 raise ActiveRecord::Forbidden unless @picture.enable?
109 respond_to do |format|
110 if @panel_picture.store @operators
111 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
112 format.html { redirect_to @panel_picture }
113 format.json { head :ok }
115 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
116 format.html { render action: "edit" }
117 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
123 @panel_picture = PanelPicture.show(params[:id], @operators)
124 @panel = Panel.edit(@panel_picture.panel.id, @operators)
126 respond_to do |format|
127 if @panel_picture.remove @operators
128 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
129 format.html { redirect_to @panel }
130 format.json { head :ok }
132 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
133 format.html { redirect_to @panel_picture }
134 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }