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]
14 @page = PanelPicture.page params[:page]
15 @page_size = PanelPicture.page_size params[:page_size]
16 @panel_pictures = PanelPicture.list(@page, @page_size)
18 respond_to do |format|
20 @paginate = PanelPicture.list_paginate(@page, @page_size)
22 format.json { render :json => @panel_pictures.to_json(PanelPicture.list_json_opt) }
27 @panel_picture = PanelPicture.show(params[:id], [@user, @admin])
29 respond_to do |format|
31 format.json { render :json => @panel_picture.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 @picture = Picture.show params[:picture_id], @author
55 raise ActiveRecord::Forbidden unless @picture.enable?
56 @panel = Panel.edit(@author.working_panel, @author)
58 @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
59 @panel_picture.supply_default
61 respond_to do |format|
63 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
68 @panel_picture = PanelPicture.show(params[:id], @author)
69 @panel = Panel.edit(@panel_picture.panel.id, @author)
71 respond_to do |format|
77 @panel = Panel.edit(@author.working_panel, @author)
79 @panel_picture = PanelPicture.new
80 @panel_picture.attributes = params[:panel_picture]
81 @panel_picture.overwrite @panel.id
83 @picture = Picture.show @panel_picture.picture_id, @author
84 raise ActiveRecord::Forbidden unless @picture.enable?
86 respond_to do |format|
87 if @panel_picture.valid?
88 if @panel_picture.store @author
89 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
90 format.html { redirect_to @panel }
91 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
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.errors, status: :unprocessable_entity }
98 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
99 format.html { render action: "new" }
100 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
106 @panel_picture = PanelPicture.show(params[:id], @author)
107 @panel_picture.attributes = params[:panel_picture]
108 @panel = Panel.edit(@panel_picture.panel.id, @author)
109 @panel_picture.overwrite @panel.id
111 @picture = Picture.show @panel_picture.picture_id, @author
112 raise ActiveRecord::Forbidden unless @picture.enable?
114 respond_to do |format|
115 if @panel_picture.store @author
116 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
117 format.html { redirect_to @panel_picture }
118 format.json { head :ok }
120 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
121 format.html { render action: "edit" }
122 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
128 @panel_picture = PanelPicture.show(params[:id], @author)
129 @panel = Panel.edit(@panel_picture.panel.id, @author)
131 respond_to do |format|
132 if @panel_picture.remove @author
133 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
134 format.html { redirect_to @panel }
135 format.json { head :ok }
137 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
138 format.html { redirect_to @panel_picture }
139 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }